#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 checkIfNumIsPowerOf2(int givenNumber) {
  int num = givenNumber;
  if (num == 0) {
    return -1;
  }
  int divisor = 0;
  if (num < 0)
    divisor = -2;
  else
    divisor = 2;
  while (num != 1) {
    num = num / divisor;
    if (num == 1) {
      return 0;
    }
    if ((num % divisor) != 0) {
      return -1;
    }
  }
  printf("%d is power of 2\n");
  return 0;
}


x86 assembly (clang, -O0):
<checkIfNumIsPowerOf2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1137 <checkIfNumIsPowerOf2+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <checkIfNumIsPowerOf2+0xae>
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1154 <checkIfNumIsPowerOf2+0x44>
movl   $0xfffffffe,-0x10(%rbp)
jmp    115b <checkIfNumIsPowerOf2+0x4b>
movl   $0x2,-0x10(%rbp)
jmp    1160 <checkIfNumIsPowerOf2+0x50>
cmpl   $0x1,-0xc(%rbp)
je     11ab <checkIfNumIsPowerOf2+0x9b>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    118a <checkIfNumIsPowerOf2+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11be <checkIfNumIsPowerOf2+0xae>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
je     11a6 <checkIfNumIsPowerOf2+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <checkIfNumIsPowerOf2+0xae>
jmp    1160 <checkIfNumIsPowerOf2+0x50>
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkIfNumIsPowerOf2>:
mov    $0xffffffff,%ecx
test   %edi,%edi
je     1148 <checkIfNumIsPowerOf2+0x38>
mov    %edi,%eax
not    %eax
shr    $0x1f,%eax
lea    -0x2(,%rax,4),%esi
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%edi
je     114b <checkIfNumIsPowerOf2+0x3b>
mov    %edi,%eax
cltd
idiv   %esi
cmp    $0x1,%eax
je     1161 <checkIfNumIsPowerOf2+0x51>
mov    %eax,%edi
cltd
idiv   %esi
test   %edx,%edx
je     1130 <checkIfNumIsPowerOf2+0x20>
mov    %ecx,%eax
ret
push   %rax
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
xor    %ecx,%ecx
add    $0x8,%rsp
mov    %ecx,%eax
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"%d is power of 2\0A\00"
define i32 @checkIfNumIsPowerOf2(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = icmp slt i32 %0, 0
%5 = select i1 %4, i32 -2, i32 2
br label %6
6: ; preds = %12, %3
%7 = phi i32 [ %0, %3 ], [ %10, %12 ]
%8 = icmp eq i32 %7, 1
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = sdiv i32 %7, %5
%11 = icmp eq i32 %10, 1
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = srem i32 %10, %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %6, label %17
15: ; preds = %6
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %9, %12, %15, %1
%18 = phi i32 [ -1, %1 ], [ 0, %15 ], [ -1, %12 ], [ 0, %9 ]
ret i32 %18
}