#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 */

/* Variables and functions */
double log(int);
int pow(int, int);
int rand();
int t5_1_2(int low, int high) {
  int i = 0;
  int count = 0;
  double j = log(high - low + 1) / log(2);
  if (j - (int)j > 0) {
    j++;
  }
  while (1) {
    count = 0;
    for (i = 0; i < j; i++) {
      count += (rand() % 2) * pow(2, i);
    }
    if (low + count <= high) {
      break;
    }
  }
  return low + count;
}


x86 assembly (clang, -O0):
<t5_1_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    -0x4(%rbp),%edi
add    $0x1,%edi
call   1030 <log@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x2,%edi
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
cvttsd2si -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ab <t5_1_2+0x7b>
movsd  0xe5f(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11b0 <t5_1_2+0x80>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120d <t5_1_2+0xdd>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11be <t5_1_2+0x8e>
mov    -0x4(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1221 <t5_1_2+0xf1>
jmp    1226 <t5_1_2+0xf6>
jmp    11b0 <t5_1_2+0x80>
mov    -0x4(%rbp),%eax
add    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t5_1_2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %esi,%edi
sub    %r15d,%edi
add    $0x1,%edi
call   1030 <log@plt>
movapd %xmm0,(%rsp)
mov    $0x2,%edi
call   1030 <log@plt>
movapd (%rsp),%xmm2
divsd  %xmm0,%xmm2
cvttpd2dq %xmm2,%xmm0
cvtdq2pd %xmm0,%xmm0
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movsd  0xe81(%rip),%xmm0
addsd  %xmm2,%xmm0
movapd %xmm2,%xmm3
xorpd  %xmm2,%xmm2
cmpltsd %xmm1,%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm3,%xmm2
orpd   %xmm0,%xmm2
movapd %xmm2,(%rsp)
jmp    11b8 <t5_1_2+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %r15d,%r12d
cmp    %r14d,%r12d
jle    120c <t5_1_2+0xdc>
ucomisd 0xe48(%rip),%xmm2
mov    $0x0,%r12d
jbe    11b0 <t5_1_2+0x80>
xor    %r12d,%r12d
xor    %ebp,%ebp
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ebx
shr    $0x1f,%eax
add    %ebx,%eax
and    $0xfffffffe,%eax
sub    %eax,%ebx
mov    $0x2,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movapd (%rsp),%xmm2
imul   %ebx,%eax
add    %eax,%r12d
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
ucomisd %xmm0,%xmm2
ja     11d0 <t5_1_2+0xa0>
jmp    11b0 <t5_1_2+0x80>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @t5_1_2(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = sub nsw i32 %8, %9
%11 = add nsw i32 %10, 1
%12 = call double @log(i32 %11)
%13 = call double @log(i32 2)
%14 = fdiv double %12, %13
store double %14, double* %7
%15 = load double, double* %7
%16 = load double, double* %7
%17 = fptosi double %16 to i32
%18 = sitofp i32 %17 to double
%19 = fsub double %15, %18
%20 = fcmp ogt double %19, 0.000000e+00
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load double, double* %7
%23 = fadd double %22, 1.000000e+00
store double %23, double* %7
br label %24
24: ; preds = %21, %2
br label %25
25: ; preds = %24, %49
store i32 0, i32* %6
store i32 0, i32* %5
br label %26
26: ; preds = %39, %25
%27 = load i32, i32* %5
%28 = sitofp i32 %27 to double
%29 = load double, double* %7
%30 = fcmp olt double %28, %29
br i1 %30, label %31, label %42
31: ; preds = %26
%32 = call i32 (...) @rand()
%33 = srem i32 %32, 2
%34 = load i32, i32* %5
%35 = call i32 @pow(i32 2, i32 %34)
%36 = mul nsw i32 %33, %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, %36
store i32 %38, i32* %6
br label %39
39: ; preds = %31
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %26
42: ; preds = %26
%43 = load i32, i32* %3
%44 = load i32, i32* %6
%45 = add nsw i32 %43, %44
%46 = load i32, i32* %4
%47 = icmp sle i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %50
49: ; preds = %42
br label %25
50: ; preds = %48
%51 = load i32, i32* %3
%52 = load i32, i32* %6
%53 = add nsw i32 %51, %52
ret i32 %53
}

LLVM IR (-O2):
define i32 @t5_1_2(i32 %0, i32 %1) {
%3 = sub i32 1, %0
%4 = add i32 %3, %1
%5 = tail call double @log(i32 %4)
%6 = tail call double @log(i32 2)
%7 = fdiv double %5, %6
%8 = fptosi double %7 to i32
%9 = sitofp i32 %8 to double
%10 = fsub double %7, %9
%11 = fcmp ogt double %10, 0.000000e+00
%12 = fadd double %7, 1.000000e+00
%13 = select i1 %11, double %12, double %7
%14 = fcmp ogt double %13, 0.000000e+00
br label %15
15: ; preds = %27, %2
br i1 %14, label %16, label %27
16: ; preds = %15, %16
%17 = phi i32 [ %23, %16 ], [ 0, %15 ]
%18 = phi i32 [ %24, %16 ], [ 0, %15 ]
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, 2
%21 = tail call i32 @pow(i32 2, i32 %18)
%22 = mul nsw i32 %20, %21
%23 = add nsw i32 %22, %17
%24 = add nuw nsw i32 %18, 1
%25 = sitofp i32 %24 to double
%26 = fcmp ogt double %13, %25
br i1 %26, label %16, label %27
27: ; preds = %16, %15
%28 = phi i32 [ 0, %15 ], [ %23, %16 ]
%29 = add nsw i32 %28, %0
%30 = icmp sgt i32 %29, %1
br i1 %30, label %15, label %31
31: ; preds = %27
ret i32 %29
}