#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 ceil(int);
double floor(double);
double log10(unsigned int);
int getPowTwo(unsigned int num) {
  double logTwoTen = log10(2.0);
  int x = 1;
  double lower, upper;
  int numDigit;
  while (1) {
    lower = ceil(x * 1.0 / logTwoTen + log10(num * 1.0) / logTwoTen);
    upper = floor(x * 1.0 / logTwoTen + log10((num + 1) * 1.0) / logTwoTen);
    if (lower <= upper) {
      numDigit = (int)floor(lower * logTwoTen) + 1;
      if (x * 2 > numDigit)
        return (int)lower;
    }
    x++;
  }
}


x86 assembly (clang, -O0):
<getPowTwo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x2,%edi
call   1040 <log10@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1040 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1214 <getPowTwo+0xe4>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1050 <floor@plt>
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cmp    -0x2c(%rbp),%eax
jle    120f <getPowTwo+0xdf>
cvttsd2si -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret
jmp    1214 <getPowTwo+0xe4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <getPowTwo+0x21>

x86 assembly (clang, -O2):
<getPowTwo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edi,%r14d
mov    $0x2,%ebx
mov    $0x2,%edi
call   1040 <log10@plt>
lea    0x1(%r14),%r15d
movapd %xmm0,0x20(%rsp)
unpcklpd %xmm0,%xmm0
movapd %xmm0,0x30(%rsp)
mov    $0x1,%ebp
jmp    1176 <getPowTwo+0x46>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0x2,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movapd %xmm0,0x10(%rsp)
mov    %r14d,%edi
call   1040 <log10@plt>
movapd 0x10(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
divpd  0x30(%rsp),%xmm1
movapd %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
call   1040 <log10@plt>
divsd  0x20(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
call   1050 <floor@plt>
ucomisd 0x8(%rsp),%xmm0
jb     1170 <getPowTwo+0x40>
movapd 0x20(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1050 <floor@plt>
cvttsd2si %xmm0,%eax
add    $0x1,%eax
cmp    %eax,%ebx
jle    1170 <getPowTwo+0x40>
cvttsd2si 0x8(%rsp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getPowTwo(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 %0, i32* %2
%8 = call double @log10(i32 2)
store double %8, double* %3
store i32 1, i32* %4
br label %9
9: ; preds = %1, %58
%10 = load i32, i32* %4
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 1.000000e+00
%13 = load double, double* %3
%14 = fdiv double %12, %13
%15 = load i32, i32* %2
%16 = uitofp i32 %15 to double
%17 = fmul double %16, 1.000000e+00
%18 = fptoui double %17 to i32
%19 = call double @log10(i32 %18)
%20 = load double, double* %3
%21 = fdiv double %19, %20
%22 = fadd double %14, %21
%23 = fptosi double %22 to i32
%24 = call double @ceil(i32 %23)
store double %24, double* %5
%25 = load i32, i32* %4
%26 = sitofp i32 %25 to double
%27 = fmul double %26, 1.000000e+00
%28 = load double, double* %3
%29 = fdiv double %27, %28
%30 = load i32, i32* %2
%31 = add i32 %30, 1
%32 = uitofp i32 %31 to double
%33 = fmul double %32, 1.000000e+00
%34 = fptoui double %33 to i32
%35 = call double @log10(i32 %34)
%36 = load double, double* %3
%37 = fdiv double %35, %36
%38 = fadd double %29, %37
%39 = call double @llvm.floor.f64(double %38)
store double %39, double* %6
%40 = load double, double* %5
%41 = load double, double* %6
%42 = fcmp ole double %40, %41
br i1 %42, label %43, label %58
43: ; preds = %9
%44 = load double, double* %5
%45 = load double, double* %3
%46 = fmul double %44, %45
%47 = call double @llvm.floor.f64(double %46)
%48 = fptosi double %47 to i32
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
%50 = load i32, i32* %4
%51 = mul nsw i32 %50, 2
%52 = load i32, i32* %7
%53 = icmp sgt i32 %51, %52
br i1 %53, label %54, label %57
54: ; preds = %43
%55 = load double, double* %5
%56 = fptosi double %55 to i32
ret i32 %56
57: ; preds = %43
br label %58
58: ; preds = %57, %9
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %9
}

LLVM IR (-O2):
define i32 @getPowTwo(i32 %0) {
%2 = tail call double @log10(i32 2)
%3 = add i32 %0, 1
%4 = insertelement <2 x double> poison, double %2, i64 0
%5 = shufflevector <2 x double> %4, <2 x double> poison, <2 x i32> zeroinitializer
br label %6
6: ; preds = %33, %1
%7 = phi i32 [ 1, %1 ], [ %34, %33 ]
%8 = sitofp i32 %7 to double
%9 = tail call double @log10(i32 %0)
%10 = insertelement <2 x double> poison, double %8, i64 0
%11 = insertelement <2 x double> %10, double %9, i64 1
%12 = fdiv <2 x double> %11, %5
%13 = extractelement <2 x double> %12, i64 0
%14 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%15 = fadd <2 x double> %12, %14
%16 = extractelement <2 x double> %15, i64 0
%17 = fptosi double %16 to i32
%18 = tail call double @ceil(i32 %17)
%19 = tail call double @log10(i32 %3)
%20 = fdiv double %19, %2
%21 = fadd double %13, %20
%22 = tail call double @llvm.floor.f64(double %21)
%23 = fcmp ugt double %18, %22
br i1 %23, label %33, label %24
24: ; preds = %6
%25 = fmul double %2, %18
%26 = tail call double @llvm.floor.f64(double %25)
%27 = fptosi double %26 to i32
%28 = add nsw i32 %27, 1
%29 = shl nuw nsw i32 %7, 1
%30 = icmp sgt i32 %29, %28
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = fptosi double %18 to i32
ret i32 %32
33: ; preds = %24, %6
%34 = add nuw nsw i32 %7, 1
br label %6
}