Skip to content

Instantly share code, notes, and snippets.

@moreaki
Created January 2, 2017 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moreaki/8b446ca85aecb93e2059c16d3c7cf9d6 to your computer and use it in GitHub Desktop.
Save moreaki/8b446ca85aecb93e2059c16d3c7cf9d6 to your computer and use it in GitHub Desktop.
Test code to compare different diassembly and decompiling strategies on MacOSX
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define d32 32-__builtin_clz
#define d64 64-__builtin_clzl
#define F_U32 "%24u: f1_u32:%2d f2_u32:%2d f1_u64:%2d f2_u64:%2d type:%18s\n"
#define F_U64 "%24llu: f1_u32:%2d f2_u32:%2d f1_u64:%2d f2_u64:%2d type:%18s\n"
/* kk.c: Testcode for debugging decompiling functionality
*
* Compile and run as:
*
* gcc -g -O0 -pedantic -Wall -Wextra -Wshadow -fno-inline -o kk kk.c && ./kk
* gcc -g -O0 -pedantic -Wall -Wextra -Wshadow -fno-inline -fPIC -o kk kk.c && ./kk
*
*/
static uint8_t f1_u32(uint32_t n) {
return n ? 1 + f1_u32(n/2) : 0;
}
static uint8_t f1_u64(uint64_t n) {
return n ? 1 + f1_u64(n/2) : 0;
}
static uint8_t f2_u32(uint32_t n) {
return d32(n);
}
static uint8_t f2_u64(uint64_t n) {
return d64(n);
}
int main(void) {
uint32_t u32 = UINT32_MAX;
uint64_t u64 = UINT64_MAX;
long long sll = LLONG_MAX;
unsigned long long ull = ULLONG_MAX;
for (uint8_t i = 0; i < 2<<3; ++i) {
if (i % 3 == 0) {
printf(F_U32, i, f1_u32(i), f2_u32(i), f1_u64(i), f2_u64(i), "uint8_t");
}
}
printf(F_U32, u32, f1_u32(u32), f2_u32(u32), f1_u64(u32), f2_u64(u32), "uint32_t");
printf(F_U64, u64, f1_u32(u64), f2_u32(u64), f1_u64(u64), f2_u64(u64), "uint64_t");
printf(F_U64, sll, f1_u32(sll), f2_u32(sll), f1_u64(sll), f2_u64(sll), "long long");
printf(F_U64, ull, f1_u32(ull), f2_u32(ull), f1_u64(ull), f2_u64(ull), "unsigned long long");
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment