#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ floor(int /*<<< orphan*/);
int /*<<< orphan*/ log2(double);
scalar_t__ log2_32(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void t_min_level() {
  printf("Testing level inside the heap and custom log2 function...  ");
  assert(((log2_32(1) & 1) == 0) == true);
  assert(((log2_32(2) & 1) == 0) == false);
  assert(((log2_32(3) & 1) == 0) == false);
  assert(((log2_32(4) & 1) == 0) == true);
  assert(((log2_32(7) & 1) == 0) == true);
  assert(((log2_32(8) & 1) == 0) == false);
  assert(((log2_32(15) & 1) == 0) == false);
  assert(((log2_32(16) & 1) == 0) == true);
  assert(log2_32(4) == floor(log2(4.0)));
  assert(log2_32(3) == floor(log2(3.0)));
  assert(log2_32(310409) == floor(log2(310409.0)));
  assert(log2_32(997563) == floor(log2(997563.0)));
  srand(time(NULL));
  for (int i = 0; i < 500; i++) {
    uint32_t tmp = (uint32_t)rand();
    assert(log2_32(tmp) == floor(log2((double)tmp)));
  }
  printf("[OK]\n");
}


x86 assembly (clang, -O0):
<t_min_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x2,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x3,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x4,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x7,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x8,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0xf,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x10,%edi
call   1040 <log2_32@plt>
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x4,%edi
call   1040 <log2_32@plt>
mov    %rax,-0x28(%rbp)
movsd  0xd1e(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   1090 <floor@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x3,%edi
call   1040 <log2_32@plt>
mov    %rax,-0x20(%rbp)
movsd  0xcdd(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   1090 <floor@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x4bc89,%edi
call   1040 <log2_32@plt>
mov    %rax,-0x18(%rbp)
movsd  0xc9c(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   1090 <floor@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0xf38bb,%edi
call   1040 <log2_32@plt>
mov    %rax,-0x10(%rbp)
movsd  0xc5b(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   1090 <floor@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x1f4,-0x4(%rbp)
jge    1438 <t_min_level+0x2b8>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <log2_32@plt>
mov    %rax,-0x30(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   1090 <floor@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    13df <t_min_level+0x25f>
lea    0xc1d(%rip),%rdi
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t_min_level>:
push   %rbp
push   %r14
push   %rbx
lea    0xe85(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1050 <log2_32@plt>
not    %eax
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0x2,%edi
call   1050 <log2_32@plt>
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0x3,%edi
call   1050 <log2_32@plt>
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0x4,%edi
call   1050 <log2_32@plt>
not    %eax
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0x7,%edi
call   1050 <log2_32@plt>
not    %eax
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0x8,%edi
call   1050 <log2_32@plt>
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0xf,%edi
call   1050 <log2_32@plt>
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0x10,%edi
call   1050 <log2_32@plt>
not    %eax
and    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    $0x4,%edi
call   1050 <log2_32@plt>
mov    %rax,%rbx
movsd  0xda3(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1080 <assert@plt>
mov    $0x3,%edi
call   1050 <log2_32@plt>
mov    %rax,%rbx
movsd  0xd7c(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1080 <assert@plt>
mov    $0x4bc89,%edi
call   1050 <log2_32@plt>
mov    %rax,%rbx
movsd  0xd55(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1080 <assert@plt>
mov    $0xf38bb,%edi
call   1050 <log2_32@plt>
mov    %rax,%rbx
movsd  0xd2e(%rip),%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    $0x1f4,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <log2_32@plt>
mov    %rax,%r14
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
call   1030 <log2@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
xor    %edi,%edi
cmp    %rax,%r14
sete   %dil
call   1080 <assert@plt>
add    $0xffffffff,%ebp
jne    1320 <t_min_level+0x190>
lea    0xcfc(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"Testing level inside the heap and custom log2 function... \00"
@.str.1 = [6 x i8] c"[OK]\0A\00"
define void @t_min_level() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @log2_32(i32 1)
%5 = and i64 %4, 1
%6 = icmp eq i64 %5, 0
%7 = zext i1 %6 to i32
%8 = icmp eq i32 %7, 1
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i64 @log2_32(i32 2)
%12 = and i64 %11, 1
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i64 @log2_32(i32 3)
%19 = and i64 %18, 1
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i64 @log2_32(i32 4)
%26 = and i64 %25, 1
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = icmp eq i32 %28, 1
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i64 @log2_32(i32 7)
%33 = and i64 %32, 1
%34 = icmp eq i64 %33, 0
%35 = zext i1 %34 to i32
%36 = icmp eq i32 %35, 1
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = call i64 @log2_32(i32 8)
%40 = and i64 %39, 1
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
%43 = icmp eq i32 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = call i64 @log2_32(i32 15)
%47 = and i64 %46, 1
%48 = icmp eq i64 %47, 0
%49 = zext i1 %48 to i32
%50 = icmp eq i32 %49, 0
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = call i64 @log2_32(i32 16)
%54 = and i64 %53, 1
%55 = icmp eq i64 %54, 0
%56 = zext i1 %55 to i32
%57 = icmp eq i32 %56, 1
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = call i64 @log2_32(i32 4)
%61 = call i32 @log2(double 4.000000e+00)
%62 = call i64 @floor(i32 %61)
%63 = icmp eq i64 %60, %62
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = call i64 @log2_32(i32 3)
%67 = call i32 @log2(double 3.000000e+00)
%68 = call i64 @floor(i32 %67)
%69 = icmp eq i64 %66, %68
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = call i64 @log2_32(i32 310409)
%73 = call i32 @log2(double 3.104090e+05)
%74 = call i64 @floor(i32 %73)
%75 = icmp eq i64 %72, %74
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
%78 = call i64 @log2_32(i32 997563)
%79 = call i32 @log2(double 9.975630e+05)
%80 = call i64 @floor(i32 %79)
%81 = icmp eq i64 %78, %80
%82 = zext i1 %81 to i32
%83 = call i32 @assert(i32 %82)
%84 = call i32 @time(i32* null)
%85 = call i32 @srand(i32 %84)
store i32 0, i32* %1
br label %86
86: ; preds = %100, %0
%87 = load i32, i32* %1
%88 = icmp slt i32 %87, 500
br i1 %88, label %89, label %103
89: ; preds = %86
%90 = call i32 (...) @rand()
store i32 %90, i32* %2
%91 = load i32, i32* %2
%92 = call i64 @log2_32(i32 %91)
%93 = load i32, i32* %2
%94 = sitofp i32 %93 to double
%95 = call i32 @log2(double %94)
%96 = call i64 @floor(i32 %95)
%97 = icmp eq i64 %92, %96
%98 = zext i1 %97 to i32
%99 = call i32 @assert(i32 %98)
br label %100
100: ; preds = %89
%101 = load i32, i32* %1
%102 = add nsw i32 %101, 1
store i32 %102, i32* %1
br label %86
103: ; preds = %86
%104 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"Testing level inside the heap and custom log2 function... \00"
@str = [5 x i8] c"[OK]\00"
define void @t_min_level() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @log2_32(i32 1)
%3 = trunc i64 %2 to i32
%4 = and i32 %3, 1
%5 = xor i32 %4, 1
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i64 @log2_32(i32 2)
%8 = trunc i64 %7 to i32
%9 = and i32 %8, 1
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i64 @log2_32(i32 3)
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 1
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i64 @log2_32(i32 4)
%16 = trunc i64 %15 to i32
%17 = and i32 %16, 1
%18 = xor i32 %17, 1
%19 = tail call i32 @assert(i32 %18)
%20 = tail call i64 @log2_32(i32 7)
%21 = trunc i64 %20 to i32
%22 = and i32 %21, 1
%23 = xor i32 %22, 1
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i64 @log2_32(i32 8)
%26 = trunc i64 %25 to i32
%27 = and i32 %26, 1
%28 = tail call i32 @assert(i32 %27)
%29 = tail call i64 @log2_32(i32 15)
%30 = trunc i64 %29 to i32
%31 = and i32 %30, 1
%32 = tail call i32 @assert(i32 %31)
%33 = tail call i64 @log2_32(i32 16)
%34 = trunc i64 %33 to i32
%35 = and i32 %34, 1
%36 = xor i32 %35, 1
%37 = tail call i32 @assert(i32 %36)
%38 = tail call i64 @log2_32(i32 4)
%39 = tail call i32 @log2(double 4.000000e+00)
%40 = tail call i64 @floor(i32 %39)
%41 = icmp eq i64 %38, %40
%42 = zext i1 %41 to i32
%43 = tail call i32 @assert(i32 %42)
%44 = tail call i64 @log2_32(i32 3)
%45 = tail call i32 @log2(double 3.000000e+00)
%46 = tail call i64 @floor(i32 %45)
%47 = icmp eq i64 %44, %46
%48 = zext i1 %47 to i32
%49 = tail call i32 @assert(i32 %48)
%50 = tail call i64 @log2_32(i32 310409)
%51 = tail call i32 @log2(double 3.104090e+05)
%52 = tail call i64 @floor(i32 %51)
%53 = icmp eq i64 %50, %52
%54 = zext i1 %53 to i32
%55 = tail call i32 @assert(i32 %54)
%56 = tail call i64 @log2_32(i32 997563)
%57 = tail call i32 @log2(double 9.975630e+05)
%58 = tail call i64 @floor(i32 %57)
%59 = icmp eq i64 %56, %58
%60 = zext i1 %59 to i32
%61 = tail call i32 @assert(i32 %60)
%62 = tail call i32 @time(i32* null)
%63 = tail call i32 @srand(i32 %62)
br label %66
64: ; preds = %66
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret void
66: ; preds = %0, %66
%67 = phi i32 [ 0, %0 ], [ %76, %66 ]
%68 = tail call i32 (...) @rand()
%69 = tail call i64 @log2_32(i32 %68)
%70 = sitofp i32 %68 to double
%71 = tail call i32 @log2(double %70)
%72 = tail call i64 @floor(i32 %71)
%73 = icmp eq i64 %69, %72
%74 = zext i1 %73 to i32
%75 = tail call i32 @assert(i32 %74)
%76 = add nuw nsw i32 %67, 1
%77 = icmp eq i32 %76, 500
br i1 %77, label %64, label %66
}