#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 */
long long build_value(int /*<<< orphan*/, int);
int /*<<< orphan*/ err(int);
unsigned long long extract_value(long long, int *);
int /*<<< orphan*/ int_power_helper(unsigned long long, unsigned long long,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ set_carry(int);
int /*<<< orphan*/ set_overflow(int);
long long int intPower(long long int y, long long int x) {
  int sx, sy, sr;
  unsigned long long int vx = extract_value(x, &sx);
  unsigned long long int vy = extract_value(y, &sy);
  if (vx == 0 && vy == 0) {
    err(1);
    return 0;
  }
  set_carry(0);
  set_overflow(0);
  if (vx == 0) {
    if (vy == 0) {
      set_overflow(1);
      return 0;
    }
    return 1;
  } else if (vy == 0)
    return 0;
  if (sx) {
    set_carry(1);
    return 0;
  }
  sr = (sy && (vx & 1)) ? 1 : 0;
  return build_value(int_power_helper(vy, vx, 0), sr);
}


x86 assembly (clang, -O0):
<intPower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <extract_value@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <extract_value@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bf <intPower+0x5f>
cmpq   $0x0,-0x38(%rbp)
jne    11bf <intPower+0x5f>
mov    $0x1,%edi
call   1080 <err@plt>
movq   $0x0,-0x8(%rbp)
jmp    1296 <intPower+0x136>
xor    %edi,%edi
call   1050 <set_carry@plt>
xor    %edi,%edi
call   1060 <set_overflow@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1207 <intPower+0xa7>
cmpq   $0x0,-0x38(%rbp)
jne    11fa <intPower+0x9a>
mov    $0x1,%edi
call   1060 <set_overflow@plt>
movq   $0x0,-0x8(%rbp)
jmp    1296 <intPower+0x136>
movq   $0x1,-0x8(%rbp)
jmp    1296 <intPower+0x136>
cmpq   $0x0,-0x38(%rbp)
jne    121f <intPower+0xbf>
movq   $0x0,-0x8(%rbp)
jmp    1296 <intPower+0x136>
jmp    1224 <intPower+0xc4>
cmpl   $0x0,-0x1c(%rbp)
je     1245 <intPower+0xe5>
mov    $0x1,%edi
call   1050 <set_carry@plt>
movq   $0x0,-0x8(%rbp)
jmp    1296 <intPower+0x136>
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x39(%rbp)
je     1266 <intPower+0x106>
mov    -0x30(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1030 <int_power_helper@plt>
mov    %eax,%edi
mov    -0x24(%rbp),%esi
call   1040 <build_value@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intPower>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1070 <extract_value@plt>
mov    %rax,%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <extract_value@plt>
mov    %rax,%rbx
mov    %r14,%rax
or     %rbx,%rax
jne    11ab <intPower+0x4b>
mov    $0x1,%edi
call   1080 <err@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
call   1050 <set_carry@plt>
xor    %edi,%edi
call   1060 <set_overflow@plt>
test   %r14,%r14
je     11d6 <intPower+0x76>
test   %rbx,%rbx
je     11a0 <intPower+0x40>
cmpl   $0x0,0xc(%rsp)
je     11ec <intPower+0x8c>
mov    $0x1,%edi
call   1050 <set_carry@plt>
jmp    11a0 <intPower+0x40>
mov    $0x1,%eax
test   %rbx,%rbx
jne    11a2 <intPower+0x42>
mov    $0x1,%edi
call   1060 <set_overflow@plt>
jmp    11a0 <intPower+0x40>
cmpl   $0x0,0x8(%rsp)
setne  %al
mov    %r14d,%ecx
and    %al,%cl
movzbl %cl,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <int_power_helper@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <build_value@plt>
jmp    11a2 <intPower+0x42>

LLVM IR (-O0):
define i64 @intPower(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%11 = load i64, i64* %5
%12 = call i64 @extract_value(i64 %11, i32* %6)
store i64 %12, i64* %9
%13 = load i64, i64* %4
%14 = call i64 @extract_value(i64 %13, i32* %7)
store i64 %14, i64* %10
%15 = load i64, i64* %9
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i64, i64* %10
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @err(i32 1)
store i64 0, i64* %3
br label %59
22: ; preds = %17, %2
%23 = call i32 @set_carry(i32 0)
%24 = call i32 @set_overflow(i32 0)
%25 = load i64, i64* %9
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i64, i64* %10
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @set_overflow(i32 1)
store i64 0, i64* %3
br label %59
32: ; preds = %27
store i64 1, i64* %3
br label %59
33: ; preds = %22
%34 = load i64, i64* %10
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i64 0, i64* %3
br label %59
37: ; preds = %33
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @set_carry(i32 1)
store i64 0, i64* %3
br label %59
43: ; preds = %38
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i64, i64* %9
%48 = and i64 %47, 1
%49 = icmp ne i64 %48, 0
br label %50
50: ; preds = %46, %43
%51 = phi i1 [ false, %43 ], [ %49, %46 ]
%52 = zext i1 %51 to i64
%53 = select i1 %51, i32 1, i32 0
store i32 %53, i32* %8
%54 = load i64, i64* %10
%55 = load i64, i64* %9
%56 = call i32 @int_power_helper(i64 %54, i64 %55, i32 0)
%57 = load i32, i32* %8
%58 = call i64 @build_value(i32 %56, i32 %57)
store i64 %58, i64* %3
br label %59
59: ; preds = %50, %41, %36, %32, %30, %20
%60 = load i64, i64* %3
ret i64 %60
}

LLVM IR (-O2):
define i64 @intPower(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i64 @extract_value(i64 %1, i32* %3)
%8 = call i64 @extract_value(i64 %0, i32* %4)
%9 = icmp eq i64 %7, 0
%10 = icmp eq i64 %8, 0
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err(i32 1)
br label %35
14: ; preds = %2
%15 = call i32 @set_carry(i32 0)
%16 = call i32 @set_overflow(i32 0)
br i1 %9, label %17, label %20
17: ; preds = %14
br i1 %10, label %18, label %35
18: ; preds = %17
%19 = call i32 @set_overflow(i32 1)
br label %35
20: ; preds = %14
br i1 %10, label %35, label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @set_carry(i32 1)
br label %35
26: ; preds = %21
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
%29 = and i64 %7, 1
%30 = icmp ne i64 %29, 0
%31 = select i1 %28, i1 %30, i1 false
%32 = zext i1 %31 to i32
%33 = call i32 @int_power_helper(i64 %8, i64 %7, i32 0)
%34 = call i64 @build_value(i32 %33, i32 %32)
br label %35
35: ; preds = %20, %17, %26, %24, %18, %12
%36 = phi i64 [ 0, %12 ], [ 0, %18 ], [ 0, %24 ], [ %34, %26 ], [ 1, %17 ], [ 0, %20 ]
ret i64 %36
}