#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, num, result = 1;
  bool powerOfTwo;
  printf("Enter a number: ");
  scanf("%d", &num);
  for (i = 1; i < num / 2; i++) {
    result = result * 2;
    powerOfTwo = true;
    if (result == num) {
      printf("%dth power of 2\n", i);
      break;
    }
    powerOfTwo = false;
  }
  if (powerOfTwo == false) {
    printf("Not a power of 2\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11c0 <main+0xa0>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11ab <main+0x8b>
mov    -0x8(%rbp),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c0 <main+0xa0>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x3b>
cmpl   $0x0,-0x14(%rbp)
jne    11d8 <main+0xb8>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x4,%eax
jl     117d <main+0x4d>
mov    %eax,%ecx
shr    %ecx
mov    $0x1,%edx
mov    $0x1,%esi
nopw   0x0(%rax,%rax,1)
add    %edx,%edx
cmp    %eax,%edx
je     118b <main+0x5b>
add    $0x1,%esi
cmp    %esi,%ecx
jne    1170 <main+0x40>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
jmp    1199 <main+0x69>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"%dth power of 2\0A\00"
@.str.3 = [18 x i8] c"Not a power of 2\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 1, i32* %2
br label %8
8: ; preds = %23, %0
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 2
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %26
13: ; preds = %8
%14 = load i32, i32* %4
%15 = mul nsw i32 %14, 2
store i32 %15, i32* %4
store i32 1, i32* %5
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %26
22: ; preds = %13
store i32 0, i32* %5
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %8
26: ; preds = %19, %8
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"%dth power of 2\0A\00"
@str = [17 x i8] c"Not a power of 2\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 3
br i1 %6, label %7, label %19
7: ; preds = %0
%8 = lshr i32 %5, 1
br label %9
9: ; preds = %7, %16
%10 = phi i32 [ %12, %16 ], [ 1, %7 ]
%11 = phi i32 [ %17, %16 ], [ 1, %7 ]
%12 = shl nsw i32 %10, 1
%13 = icmp eq i32 %12, %5
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %21
16: ; preds = %9
%17 = add nuw nsw i32 %11, 1
%18 = icmp eq i32 %17, %8
br i1 %18, label %19, label %9
19: ; preds = %16, %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %14, %19
ret i32 0
}