#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_SUCCESS;
long long binary_num(int);
int check_low_bit(void *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long long);
int /*<<< orphan*/ free(void *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, long long);
int main() {
  int times = 100;
  int i;
  const int MAX = 10001;
  int min_bits = 60;
  long long min_value = 9999999999999;
  ;
  int temp;
  void *p[MAX];
  while (times--) {
    int i = 1;
    for (i = 1; i < MAX; i++) {
      printf("Processing ---- current malloc size is: %d\n", i);
      p[i] = (void *)malloc(i);
      temp = check_low_bit(p[i]);
      if (temp < min_bits) {
        min_bits = temp;
      }
      if (((uintptr_t)p[i]) < min_value) {
        min_value = ((uintptr_t)p[i]);
      }
    }
    for (i = 2; i < MAX; i += 2) {
      free(p[i]);
    }
  }
  printf("The minimal available low bits is %d\n", min_bits);
  printf("The acceptable min_value is %lld\n", min_value);
  FILE *fp;
  fp = fopen("LOW_BITS.h", "w");
  fprintf(fp, "#define LOW_BIT_USED %lld\n", binary_num(min_bits));
  fprintf(fp, "#define MIN_ADDRESS %lld\n", min_value);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x138e0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
movl   $0x2711,-0x10(%rbp)
movl   $0x3c,-0x14(%rbp)
movabs $0x9184e729fff,%rax
mov    %rax,-0x20(%rbp)
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1299 <main+0x129>
movl   $0x1,-0x34(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0x2711,-0x34(%rbp)
jge    1261 <main+0xf1>
movslq -0x34(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
mov    %rcx,-0x138d0(%rbp,%rax,8)
ff
movslq -0x34(%rbp),%rax
mov    -0x138d0(%rbp,%rax,8),%rdi
ff
call   1090 <check_low_bit@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1228 <main+0xb8>
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x138d0(%rbp,%rax,8),%rax
ff
cmp    -0x20(%rbp),%rax
jae    124e <main+0xde>
movslq -0x34(%rbp),%rax
mov    -0x138d0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x20(%rbp)
jmp    1253 <main+0xe3>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ce <main+0x5e>
movl   $0x2,-0x34(%rbp)
cmpl   $0x2711,-0x34(%rbp)
jge    1294 <main+0x124>
movslq -0x34(%rbp),%rax
mov    -0x138d0(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    1268 <main+0xf8>
jmp    11ac <main+0x3c>
movslq -0x14(%rbp),%rsi
lea    0xd88(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xd9e(%rip),%rdi
call   1040 <printf@plt>
lea    0xdb4(%rip),%rdi
lea    0xdb8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x138d8(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <binary_num@plt>
mov    -0x138d8(%rbp),%rdi
mov    %rax,%rdx
lea    0xd8d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd94(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x138e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x13888,%rsp
movabs $0x9184e729fff,%r15
mov    $0x3c,%ebp
mov    $0x63,%r13d
lea    0xe63(%rip),%r14
nopl   (%rax)
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,(%rsp,%rbx,8)
mov    %rax,%rdi
call   1090 <check_low_bit@plt>
cmp    %ebp,%eax
cmovl  %eax,%ebp
cmp    %r12,%r15
cmova  %r12,%r15
add    $0x1,%rbx
cmp    $0x2711,%rbx
jne    11b0 <main+0x40>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x10(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x2,%rbx
cmp    $0x270f,%rbx
jb     11f0 <main+0x80>
sub    $0x1,%r13d
jae    11a0 <main+0x30>
movslq %ebp,%r14
lea    0xe15(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe2c(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
lea    0xe3f(%rip),%rdi
lea    0xe43(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1070 <binary_num@plt>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1050 <fprintf@plt>
lea    0xe37(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
add    $0x13888,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Processing ---- current malloc size is: %d\0A\00"
@.str.1 = [38 x i8] c"The minimal available low bits is %d\0A\00"
@.str.2 = [34 x i8] c"The acceptable min_value is %lld\0A\00"
@.str.3 = [11 x i8] c"LOW_BITS.h\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [27 x i8] c"#define LOW_BIT_USED %lld\0A\00"
@.str.6 = [26 x i8] c"#define MIN_ADDRESS %lld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %1
store i32 100, i32* %2
store i32 10001, i32* %4
store i32 60, i32* %5
store i64 9999999999999, i64* %6
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %8
%12 = alloca i8*, i64 10001
br label %13
13: ; preds = %72, %0
%14 = load i32, i32* %2
%15 = add nsw i32 %14, -1
store i32 %15, i32* %2
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %73
17: ; preds = %13
store i32 1, i32* %9
store i32 1, i32* %9
br label %18
18: ; preds = %56, %17
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 10001
br i1 %20, label %21, label %59
21: ; preds = %18
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = load i32, i32* %9
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %12, i64 %29
store i8* %27, i8** %30
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %12, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @check_low_bit(i8* %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = load i32, i32* %5
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %21
%40 = load i32, i32* %7
store i32 %40, i32* %5
br label %41
41: ; preds = %39, %21
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %12, i64 %43
%45 = load i8*, i8** %44
%46 = ptrtoint i8* %45 to i64
%47 = load i64, i64* %6
%48 = icmp ult i64 %46, %47
br i1 %48, label %49, label %55
49: ; preds = %41
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %12, i64 %51
%53 = load i8*, i8** %52
%54 = ptrtoint i8* %53 to i64
store i64 %54, i64* %6
br label %55
55: ; preds = %49, %41
br label %56
56: ; preds = %55
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %18
59: ; preds = %18
store i32 2, i32* %9
br label %60
60: ; preds = %69, %59
%61 = load i32, i32* %9
%62 = icmp slt i32 %61, 10001
br i1 %62, label %63, label %72
63: ; preds = %60
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %12, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @free(i8* %67)
br label %69
69: ; preds = %63
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 2
store i32 %71, i32* %9
br label %60
72: ; preds = %60
br label %13
73: ; preds = %13
%74 = load i32, i32* %5
%75 = sext i32 %74 to i64
%76 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %75)
%77 = load i64, i64* %6
%78 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %77)
%79 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %79, i32** %10
%80 = load i32*, i32** %10
%81 = load i32, i32* %5
%82 = call i64 @binary_num(i32 %81)
%83 = call i32 @fprintf(i32* %80, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i64 %82)
%84 = load i32*, i32** %10
%85 = load i64, i64* %6
%86 = call i32 @fprintf(i32* %84, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i64 %85)
%87 = load i32, i32* @EXIT_SUCCESS
store i32 %87, i32* %1
%88 = load i8*, i8** %8
%89 = load i32, i32* %1
ret i32 %89
}

LLVM IR (-O2):
@.str = [44 x i8] c"Processing ---- current malloc size is: %d\0A\00"
@.str.1 = [38 x i8] c"The minimal available low bits is %d\0A\00"
@.str.2 = [34 x i8] c"The acceptable min_value is %lld\0A\00"
@.str.3 = [11 x i8] c"LOW_BITS.h\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [27 x i8] c"#define LOW_BIT_USED %lld\0A\00"
@.str.6 = [26 x i8] c"#define MIN_ADDRESS %lld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [10001 x i8*]
br label %5
2: ; preds = %25
%3 = add nsw i32 %6, -1
%4 = icmp eq i32 %6, 0
br i1 %4, label %32, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 99, %0 ], [ %3, %2 ]
%7 = phi i32 [ 60, %0 ], [ %20, %2 ]
%8 = phi i64 [ 9999999999999, %0 ], [ %22, %2 ]
br label %9
9: ; preds = %5, %9
%10 = phi i64 [ 1, %5 ], [ %23, %9 ]
%11 = phi i32 [ %7, %5 ], [ %20, %9 ]
%12 = phi i64 [ %8, %5 ], [ %22, %9 ]
%13 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %10)
%14 = trunc i64 %10 to i32
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds [10001 x i8*], [10001 x i8*]* %1, i64 0, i64 %10
store i8* %16, i8** %17
%18 = tail call i32 @check_low_bit(i8* %16)
%19 = icmp slt i32 %18, %11
%20 = select i1 %19, i32 %18, i32 %11
%21 = icmp ugt i64 %12, %15
%22 = select i1 %21, i64 %15, i64 %12
%23 = add nuw nsw i64 %10, 1
%24 = icmp eq i64 %23, 10001
br i1 %24, label %25, label %9
25: ; preds = %9, %25
%26 = phi i64 [ %30, %25 ], [ 2, %9 ]
%27 = getelementptr inbounds [10001 x i8*], [10001 x i8*]* %1, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 @free(i8* %28)
%30 = add nuw nsw i64 %26, 2
%31 = icmp ult i64 %26, 9999
br i1 %31, label %25, label %2
32: ; preds = %2
%33 = sext i32 %20 to i64
%34 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %33)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %22)
%36 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call i64 @binary_num(i32 %20)
%38 = tail call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i64 %37)
%39 = tail call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i64 %22)
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}