#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned long upow(unsigned long b, unsigned long n) {
  unsigned long p = 1, q, i = 0;
  while (i < n) {
    q = p * b;
    if (q < p) {
      fprintf(stderr, "overflow: cannot count up to b^n\n");
      exit(-1);
    }
    ++i;
    p = q;
  }
  return p;
}


x86 assembly (clang, -O0):
<upow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a1 <upow+0x81>
mov    -0x18(%rbp),%rax
imul   -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1188 <upow+0x68>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <upow+0x20>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upow>:
mov    $0x1,%eax
test   %rsi,%rsi
je     1142 <upow+0x22>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rcx
imul   %rdi,%rax
cmp    %rcx,%rax
jb     1143 <upow+0x23>
add    $0xffffffffffffffff,%rsi
jne    1130 <upow+0x10>
ret
push   %rax
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"overflow: cannot count up to b^n\0A\00"
define i64 @upow(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 1, i64* %5
store i64 0, i64* %7
br label %8
8: ; preds = %23, %2
%9 = load i64, i64* %7
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load i64, i64* %5
%14 = load i64, i64* %3
%15 = mul i64 %13, %14
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = load i64, i64* %5
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %12
%24 = load i64, i64* %7
%25 = add i64 %24, 1
store i64 %25, i64* %7
%26 = load i64, i64* %6
store i64 %26, i64* %5
br label %8
27: ; preds = %8
%28 = load i64, i64* %5
ret i64 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"overflow: cannot count up to b^n\0A\00"
define i64 @upow(i64 %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %16, label %6
4: ; preds = %6
%5 = icmp eq i64 %11, %1
br i1 %5, label %16, label %6
6: ; preds = %2, %4
%7 = phi i64 [ %11, %4 ], [ 0, %2 ]
%8 = phi i64 [ %9, %4 ], [ 1, %2 ]
%9 = mul i64 %8, %0
%10 = icmp ult i64 %9, %8
%11 = add nuw i64 %7, 1
br i1 %10, label %12, label %4
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %4, %2
%17 = phi i64 [ 1, %2 ], [ %9, %4 ]
ret i64 %17
}