#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 */
int numOfDigits(int);
long long pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    int match = -1;
    int lengthN = numOfDigits(n);
    for (int i = 7; i < 5766432; i++) {
      long long candidate = pow((double)2, (double)i);
      int candidateLength = numOfDigits((int)candidate);
      int moreThanHalf = lengthN;
      if (candidateLength % 2 == 0)
        moreThanHalf++;
      if (candidateLength / 2 >= moreThanHalf) {
        if ((candidate / (int)pow(10, candidateLength - lengthN)) == n) {
          match = i;
          break;
        }
      }
    }
    if (match == -1) {
      printf("no power of 2\n");
    } else {
      printf("%d\n", match);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1274 <main+0x134>
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <numOfDigits@plt>
mov    %eax,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
cmpl   $0x57fd20,-0x14(%rbp)
jge    1241 <main+0x101>
cvtsi2sdl -0x14(%rbp),%xmm0
cvttsd2si %xmm0,%esi
mov    $0x2,%edi
call   1060 <pow@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1040 <numOfDigits@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d6 <main+0x96>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    -0x28(%rbp),%eax
jl     122e <main+0xee>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%esi
sub    -0x10(%rbp),%esi
mov    $0xa,%edi
call   1060 <pow@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
cqto
idiv   %rcx
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jne    1229 <main+0xe9>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1241 <main+0x101>
jmp    122e <main+0xee>
jmp    1233 <main+0xf3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <main+0x41>
cmpl   $0xffffffff,-0xc(%rbp)
jne    125e <main+0x11e>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126f <main+0x12f>
mov    -0xc(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1255 <main+0x105>
lea    0xe8b(%rip),%r14
lea    0xe7d(%rip),%r15
lea    0x4(%rsp),%r13
jmp    11ac <main+0x5c>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1255 <main+0x105>
mov    0x4(%rsp),%edi
call   1050 <numOfDigits@plt>
mov    %eax,%ebx
mov    $0x7,%ebp
jmp    11dd <main+0x8d>
xchg   %ax,%ax
mov    %r12,%rax
cqto
idiv   %rsi
movslq 0x4(%rsp),%rcx
cmp    %rcx,%rax
je     1240 <main+0xf0>
add    $0x1,%ebp
cmp    $0x57fd20,%ebp
je     1190 <main+0x40>
mov    $0x2,%edi
mov    %ebp,%esi
call   1070 <pow@plt>
mov    %rax,%r12
mov    %r12d,%edi
call   1050 <numOfDigits@plt>
mov    %eax,%ecx
not    %ecx
and    $0x1,%ecx
add    %ebx,%ecx
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
cmp    %ecx,%edx
jl     11d2 <main+0x82>
sub    %ebx,%eax
mov    $0xa,%edi
mov    %eax,%esi
call   1070 <pow@plt>
mov    %rax,%rcx
movslq %ecx,%rsi
mov    %r12,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    11c0 <main+0x70>
mov    %r12d,%eax
xor    %edx,%edx
div    %ecx
jmp    11c8 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xdbc(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1198 <main+0x48>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [15 x i8] c"no power of 2\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
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 i32
store i32 0, i32* %1
br label %9
9: ; preds = %65, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %66
12: ; preds = %9
store i32 -1, i32* %3
%13 = load i32, i32* %2
%14 = call i32 @numOfDigits(i32 %13)
store i32 %14, i32* %4
store i32 7, i32* %5
br label %15
15: ; preds = %54, %12
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 5766432
br i1 %17, label %18, label %57
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sitofp i32 %19 to double
%21 = fptosi double %20 to i32
%22 = call i64 @pow(i32 2, i32 %21)
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = trunc i64 %23 to i32
%25 = call i32 @numOfDigits(i32 %24)
store i32 %25, i32* %7
%26 = load i32, i32* %4
store i32 %26, i32* %8
%27 = load i32, i32* %7
%28 = srem i32 %27, 2
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %18
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %33
33: ; preds = %30, %18
%34 = load i32, i32* %7
%35 = sdiv i32 %34, 2
%36 = load i32, i32* %8
%37 = icmp sge i32 %35, %36
br i1 %37, label %38, label %53
38: ; preds = %33
%39 = load i64, i64* %6
%40 = load i32, i32* %7
%41 = load i32, i32* %4
%42 = sub nsw i32 %40, %41
%43 = call i64 @pow(i32 10, i32 %42)
%44 = trunc i64 %43 to i32
%45 = sext i32 %44 to i64
%46 = sdiv i64 %39, %45
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = icmp eq i64 %46, %48
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = load i32, i32* %5
store i32 %51, i32* %3
br label %57
52: ; preds = %38
br label %53
53: ; preds = %52, %33
br label %54
54: ; preds = %53
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %15
57: ; preds = %50, %15
%58 = load i32, i32* %3
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %65
62: ; preds = %57
%63 = load i32, i32* %3
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %60
br label %9
66: ; preds = %9
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@str = [14 x i8] c"no power of 2\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %37
5: ; preds = %0, %34
%6 = load i32, i32* %1
%7 = call i32 @numOfDigits(i32 %6)
br label %8
8: ; preds = %5, %27
%9 = phi i32 [ 7, %5 ], [ %28, %27 ]
%10 = call i64 @pow(i32 2, i32 %9)
%11 = trunc i64 %10 to i32
%12 = call i32 @numOfDigits(i32 %11)
%13 = and i32 %12, 1
%14 = xor i32 %13, 1
%15 = add nsw i32 %14, %7
%16 = sdiv i32 %12, 2
%17 = icmp slt i32 %16, %15
br i1 %17, label %27, label %18
18: ; preds = %8
%19 = sub nsw i32 %12, %7
%20 = call i64 @pow(i32 10, i32 %19)
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
%23 = sdiv i64 %10, %22
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = icmp eq i64 %23, %25
br i1 %26, label %32, label %27
27: ; preds = %8, %18
%28 = add nuw nsw i32 %9, 1
%29 = icmp eq i32 %28, 5766432
br i1 %29, label %30, label %8
30: ; preds = %27
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %34
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %34
34: ; preds = %32, %30
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%36 = icmp eq i32 %35, 1
br i1 %36, label %5, label %37
37: ; preds = %34, %0
ret i32 0
}