#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 log(double);
int npfa(int);
int pow(double, double);
int optncc(int n) {
  int n2, n3;
  n2 = pow(2.0, 1.0 * (int)(log((float)n) / log(2.0) + 0.9999));
  if (n2 != n) {
    n3 = npfa(n);
    if ((n3 - n) < (n2 - n))
      return npfa(n);
    else
      return n2;
  } else
    return n;
}


x86 assembly (clang, -O0):
<optncc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xeaa(%rip),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xea1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe85(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe71(%rip),%xmm0
call   1040 <pow@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11dd <optncc+0xad>
mov    -0x8(%rbp),%edi
call   1050 <npfa@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    11d2 <optncc+0xa2>
mov    -0x8(%rbp),%edi
call   1050 <npfa@plt>
mov    %eax,-0x4(%rbp)
jmp    11e3 <optncc+0xb3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e3 <optncc+0xb3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optncc>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cvtsi2ss %edi,%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <log@plt>
divsd  0xeb6(%rip),%xmm0
addsd  0xeb6(%rip),%xmm0
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm1
movsd  0xeae(%rip),%xmm0
call   1040 <pow@plt>
cmp    %ebx,%eax
jne    116f <optncc+0x3f>
mov    %ebx,%ebp
jmp    1189 <optncc+0x59>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <npfa@plt>
cmp    %ebp,%eax
jge    1189 <optncc+0x59>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <npfa@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @optncc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = sitofp i32 %6 to float
%8 = fpext float %7 to double
%9 = call double @log(double %8)
%10 = call double @log(double 2.000000e+00)
%11 = fdiv double %9, %10
%12 = fadd double %11, 9.999000e-01
%13 = fptosi double %12 to i32
%14 = sitofp i32 %13 to double
%15 = fmul double 1.000000e+00, %14
%16 = call i32 @pow(double 2.000000e+00, double %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %1
%21 = load i32, i32* %3
%22 = call i32 @npfa(i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = load i32, i32* %3
%25 = sub nsw i32 %23, %24
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = sub nsw i32 %26, %27
%29 = icmp slt i32 %25, %28
br i1 %29, label %30, label %33
30: ; preds = %20
%31 = load i32, i32* %3
%32 = call i32 @npfa(i32 %31)
store i32 %32, i32* %2
br label %37
33: ; preds = %20
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %37
35: ; preds = %1
%36 = load i32, i32* %3
store i32 %36, i32* %2
br label %37
37: ; preds = %35, %33, %30
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @optncc(i32 %0) {
%2 = sitofp i32 %0 to float
%3 = fpext float %2 to double
%4 = tail call double @log(double %3)
%5 = fdiv double %4, 0x3FE62E42FEFA39EF
%6 = fadd double %5, 9.999000e-01
%7 = fptosi double %6 to i32
%8 = sitofp i32 %7 to double
%9 = tail call i32 @pow(double 2.000000e+00, double %8)
%10 = icmp eq i32 %9, %0
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = tail call i32 @npfa(i32 %0)
%13 = icmp slt i32 %12, %9
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @npfa(i32 %0)
br label %16
16: ; preds = %1, %11, %14
%17 = phi i32 [ %15, %14 ], [ %9, %11 ], [ %0, %1 ]
ret i32 %17
}