#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*/ assert(int);
int sqr(int);
int power(int base, int exp) {
  assert(exp >= 0);
  if (exp == 0)
    return 1;
  if (exp % 2)
    return base * power(base, exp - 1);
  else
    return sqr(power(base, exp / 2));
}


x86 assembly (clang, -O0):
<power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1165 <power+0x35>
movl   $0x1,-0x4(%rbp)
jmp    11bc <power+0x8c>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     119d <power+0x6d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1030 <power@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <power+0x8c>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1030 <power@plt>
mov    %eax,%edi
call   1050 <sqr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r14d
mov    %esi,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
test   %ebx,%ebx
je     117c <power+0x4c>
mov    %ebx,%ebp
neg    %ebp
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
test   $0x1,%bl
je     1184 <power+0x54>
add    $0xffffffff,%ebx
imul   %r14d,%r15d
mov    %ebp,%edi
shr    $0x1f,%edi
call   1040 <assert@plt>
inc    %ebp
jne    1160 <power+0x30>
jmp    11a0 <power+0x70>
mov    $0x1,%r15d
jmp    11a0 <power+0x70>
mov    %ebx,%esi
shr    $0x1f,%esi
add    %ebx,%esi
sar    %esi
mov    %r14d,%edi
call   1030 <power@plt>
mov    %eax,%edi
call   1050 <sqr@plt>
imul   %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @power(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp sge i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %30
13: ; preds = %2
%14 = load i32, i32* %5
%15 = srem i32 %14, 2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32, i32* %4
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
%22 = call i32 @power(i32 %19, i32 %21)
%23 = mul nsw i32 %18, %22
store i32 %23, i32* %3
br label %30
24: ; preds = %13
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = sdiv i32 %26, 2
%28 = call i32 @power(i32 %25, i32 %27)
%29 = call i32 @sqr(i32 %28)
store i32 %29, i32* %3
br label %30
30: ; preds = %24, %17, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @power(i32 %0, i32 %1) {
%3 = xor i32 %1, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = icmp eq i32 %1, 0
br i1 %6, label %19, label %7
7: ; preds = %2, %12
%8 = phi i32 [ %13, %12 ], [ %1, %2 ]
%9 = phi i32 [ %14, %12 ], [ 1, %2 ]
%10 = and i32 %8, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %7
%13 = add nsw i32 %8, -1
%14 = mul nsw i32 %9, %0
%15 = sub i32 0, %8
%16 = lshr i32 %15, 31
%17 = tail call i32 @assert(i32 %16)
%18 = icmp eq i32 %13, 0
br i1 %18, label %19, label %7
19: ; preds = %12, %2, %21
%20 = phi i32 [ %25, %21 ], [ 1, %2 ], [ %14, %12 ]
ret i32 %20
21: ; preds = %7
%22 = sdiv i32 %8, 2
%23 = tail call i32 @power(i32 %0, i32 %22)
%24 = tail call i32 @sqr(i32 %23)
%25 = mul nsw i32 %24, %9
br label %19
}