#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*/ exit(int);
int /*<<< orphan*/ printf(char *, int);
int int_log2(int n) {
  int k = 1;
  int log = 0;
  for (; k < n; k *= 2, log++)
    ;
  if (n != (1 << log)) {
    printf("FFT: Data length is not a power of 2!: %d.\n", n);
    exit(1);
  }
  return log;
}


x86 assembly (clang, -O0):
<int_log2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1161 <int_log2+0x41>
jmp    114a <int_log2+0x2a>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <int_log2+0x19>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
je     1191 <int_log2+0x71>
mov    -0x4(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_log2>:
mov    %edi,%esi
xor    %ecx,%ecx
cmp    $0x2,%edi
jl     1139 <int_log2+0x19>
mov    $0x1,%eax
xor    %ecx,%ecx
add    %eax,%eax
add    $0x1,%ecx
cmp    %esi,%eax
jl     1130 <int_log2+0x10>
mov    $0x1,%eax
shl    %cl,%eax
cmp    %esi,%eax
jne    1147 <int_log2+0x27>
mov    %ecx,%eax
ret
push   %rax
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"FFT: Data length is not a power of 2!: %d.\0A\00"
define i32 @int_log2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %10, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %5
br label %10
10: ; preds = %9
%11 = load i32, i32* %3
%12 = mul nsw i32 %11, 2
store i32 %12, i32* %3
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
br label %5
15: ; preds = %5
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = shl i32 1, %17
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* %2
%22 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [44 x i8] c"FFT: Data length is not a power of 2!: %d.\0A\00"
define i32 @int_log2(i32 %0) {
%2 = icmp sgt i32 %0, 1
br i1 %2, label %3, label %9
3: ; preds = %1, %3
%4 = phi i32 [ %7, %3 ], [ 0, %1 ]
%5 = phi i32 [ %6, %3 ], [ 1, %1 ]
%6 = shl nsw i32 %5, 1
%7 = add nuw nsw i32 %4, 1
%8 = icmp slt i32 %6, %0
br i1 %8, label %3, label %9
9: ; preds = %3, %1
%10 = phi i32 [ 0, %1 ], [ %7, %3 ]
%11 = shl nuw i32 1, %10
%12 = icmp eq i32 %11, %0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
ret i32 %10
}