#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 INT_MAX;
int /*<<< orphan*/ assert(int);
int btor_pow_2_util(int x) {
  int result = 1;
  assert(x >= 0);
  while (x > 0) {
    assert(result <= INT_MAX / 2);
    result <<= 1;
    x--;
  }
  assert(result > 0);
  return result;
}


x86 assembly (clang, -O0):
<btor_pow_2_util>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x4(%rbp)
jle    117f <btor_pow_2_util+0x6f>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1133 <btor_pow_2_util+0x23>
cmpl   $0x0,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<btor_pow_2_util>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
test   %ebx,%ebx
jle    1165 <btor_pow_2_util+0x55>
add    $0x1,%ebx
mov    $0x1,%ebp
mov    0x2eb5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xor    %edi,%edi
cmp    %ecx,%ebp
setle  %dil
call   1030 <assert@plt>
add    %ebp,%ebp
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1140 <btor_pow_2_util+0x30>
jmp    116a <btor_pow_2_util+0x5a>
mov    $0x1,%ebp
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
call   1030 <assert@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define i32 @btor_pow_2_util(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
%4 = load i32, i32* %2
%5 = icmp sge i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* @INT_MAX
%14 = sdiv i32 %13, 2
%15 = icmp sle i32 %12, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %3
%19 = shl i32 %18, 1
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = add nsw i32 %20, -1
store i32 %21, i32* %2
br label %8
22: ; preds = %8
%23 = load i32, i32* %3
%24 = icmp sgt i32 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @btor_pow_2_util(i32 %0) {
%2 = xor i32 %0, -1
%3 = lshr i32 %2, 31
%4 = tail call i32 @assert(i32 %3)
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %17
6: ; preds = %1, %6
%7 = phi i32 [ %14, %6 ], [ 1, %1 ]
%8 = phi i32 [ %15, %6 ], [ %0, %1 ]
%9 = load i32, i32* @INT_MAX
%10 = sdiv i32 %9, 2
%11 = icmp sle i32 %7, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = shl i32 %7, 1
%15 = add nsw i32 %8, -1
%16 = icmp ugt i32 %8, 1
br i1 %16, label %6, label %17
17: ; preds = %6, %1
%18 = phi i32 [ 1, %1 ], [ %14, %6 ]
%19 = icmp sgt i32 %18, 0
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
ret i32 %18
}