#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*/ HError(int, char *, int);
int NumTreeNodes(int nc) {
  int n = nc;
  while (n > 2) {
    if ((n % 2) == 1)
      HError(7172, "NumTreeNodes: nc %d not a power of 2", nc);
    n /= 2;
  }
  return 2 * nc - 1;
}


x86 assembly (clang, -O0):
<NumTreeNodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1166 <NumTreeNodes+0x56>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1153 <NumTreeNodes+0x43>
mov    -0x4(%rbp),%edx
mov    $0x1c04,%edi
lea    0xeb2(%rip),%rsi
call   1030 <HError@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1121 <NumTreeNodes+0x11>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NumTreeNodes>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
cmp    $0x3,%edi
jl     1152 <NumTreeNodes+0x42>
lea    0xede(%rip),%r14
mov    %ebx,%ebp
jmp    113b <NumTreeNodes+0x2b>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%eax
shr    %eax
cmp    $0x5,%ebp
mov    %eax,%ebp
jbe    1152 <NumTreeNodes+0x42>
test   $0x1,%bpl
je     1130 <NumTreeNodes+0x20>
mov    $0x1c04,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <HError@plt>
jmp    1130 <NumTreeNodes+0x20>
lea    (%rbx,%rbx,1),%eax
add    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"NumTreeNodes: nc %d not a power of 2\00"
define i32 @NumTreeNodes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
store i32 %4, i32* %3
br label %5
5: ; preds = %15, %1
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 2
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load i32, i32* %3
%10 = srem i32 %9, 2
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %2
%14 = call i32 @HError(i32 7172, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %8
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
store i32 %17, i32* %3
br label %5
18: ; preds = %5
%19 = load i32, i32* %2
%20 = mul nsw i32 2, %19
%21 = sub nsw i32 %20, 1
ret i32 %21
}

LLVM IR (-O2):
@.str = [37 x i8] c"NumTreeNodes: nc %d not a power of 2\00"
define i32 @NumTreeNodes(i32 %0) {
%2 = icmp sgt i32 %0, 2
br i1 %2, label %3, label %12
3: ; preds = %1, %9
%4 = phi i32 [ %10, %9 ], [ %0, %1 ]
%5 = and i32 %4, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @HError(i32 7172, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %9
9: ; preds = %7, %3
%10 = lshr i32 %4, 1
%11 = icmp ugt i32 %4, 5
br i1 %11, label %3, label %12
12: ; preds = %9, %1
%13 = shl nsw i32 %0, 1
%14 = add nsw i32 %13, -1
ret i32 %14
}