#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 */
unsigned long long multiply_with_overflow(unsigned long long,
                                          unsigned long long, int *);
int /*<<< orphan*/ set_overflow(int);
unsigned int word_size();
long long int int_power_helper(unsigned long long int vy,
                               unsigned long long int vx, int overflow) {
  unsigned long long int r = 1;
  unsigned int i;
  unsigned int ws;
  int overflow_next = 0;
  ws = word_size();
  for (i = 0; i < ws && vx != 0; i++) {
    if (vx & 1) {
      if (overflow_next)
        overflow = 1;
      r = multiply_with_overflow(r, vy, &overflow);
    }
    vx >>= 1;
    vy = multiply_with_overflow(vy, vy, &overflow_next);
  }
  set_overflow(overflow);
  return r;
}


x86 assembly (clang, -O0):
<int_power_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x1,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <word_size@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x28(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jae    117f <int_power_helper+0x4f>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    118f <int_power_helper+0x5f>
jmp    11f6 <int_power_helper+0xc6>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11c7 <int_power_helper+0x97>
cmpl   $0x0,-0x2c(%rbp)
je     11b2 <int_power_helper+0x82>
movl   $0x1,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <multiply_with_overflow@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <multiply_with_overflow@plt>
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1163 <int_power_helper+0x33>
mov    -0x14(%rbp),%edi
call   1040 <set_overflow@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_power_helper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %edx,(%rsp)
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   1030 <word_size@plt>
mov    $0x1,%r14d
test   %eax,%eax
je     11d1 <int_power_helper+0xa1>
test   %rbx,%rbx
je     11d1 <int_power_helper+0xa1>
mov    %eax,%ebp
mov    $0x1,%r14d
mov    $0x1,%r13d
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
test   $0x1,%bl
je     11a4 <int_power_helper+0x74>
cmpl   $0x0,0x4(%rsp)
je     1193 <int_power_helper+0x63>
movl   $0x1,(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rsp,%rdx
call   1050 <multiply_with_overflow@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <multiply_with_overflow@plt>
cmp    %ebp,%r13d
jae    11cd <int_power_helper+0x9d>
mov    %rax,%r15
mov    %rbx,%rax
shr    %rax
add    $0x1,%r13d
cmp    $0x1,%rbx
mov    %rax,%rbx
ja     1180 <int_power_helper+0x50>
mov    (%rsp),%r12d
mov    %r12d,%edi
call   1040 <set_overflow@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @int_power_helper(i64 %0, i64 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i64 %0, i64* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i64 1, i64* %7
store i32 0, i32* %10
%11 = call i32 (...) @word_size()
store i32 %11, i32* %9
store i32 0, i32* %8
br label %12
12: ; preds = %39, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i64, i64* %5
%18 = icmp ne i64 %17, 0
br label %19
19: ; preds = %16, %12
%20 = phi i1 [ false, %12 ], [ %18, %16 ]
br i1 %20, label %21, label %42
21: ; preds = %19
%22 = load i64, i64* %5
%23 = and i64 %22, 1
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i32, i32* %10
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1, i32* %6
br label %29
29: ; preds = %28, %25
%30 = load i64, i64* %7
%31 = load i64, i64* %4
%32 = call i64 @multiply_with_overflow(i64 %30, i64 %31, i32* %6)
store i64 %32, i64* %7
br label %33
33: ; preds = %29, %21
%34 = load i64, i64* %5
%35 = lshr i64 %34, 1
store i64 %35, i64* %5
%36 = load i64, i64* %4
%37 = load i64, i64* %4
%38 = call i64 @multiply_with_overflow(i64 %36, i64 %37, i32* %10)
store i64 %38, i64* %4
br label %39
39: ; preds = %33
%40 = load i32, i32* %8
%41 = add i32 %40, 1
store i32 %41, i32* %8
br label %12
42: ; preds = %19
%43 = load i32, i32* %6
%44 = call i32 @set_overflow(i32 %43)
%45 = load i64, i64* %7
ret i64 %45
}

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