#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*/ plot_fatal_error(char *);
unsigned long long lpow(unsigned long long l, int i) {
  unsigned long long res = 1;
  for (; i > 0; --i) {
    res *= l;
    if (res < l) {
      plot_fatal_error("lpow: overflow detected");
    }
  }
  return res;
}


x86 assembly (clang, -O0):
<lpow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x1,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    116b <lpow+0x5b>
mov    -0x8(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1158 <lpow+0x48>
lea    0xead(%rip),%rdi
call   1030 <plot_fatal_error@plt>
jmp    115d <lpow+0x4d>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1127 <lpow+0x17>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lpow>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    115b <lpow+0x4b>
mov    %esi,%ebx
mov    %rdi,%r14
add    $0x1,%ebx
mov    $0x1,%r15d
lea    0xecf(%rip),%r12
jmp    1148 <lpow+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jle    1161 <lpow+0x51>
imul   %r14,%r15
cmp    %r14,%r15
jae    1140 <lpow+0x30>
mov    %r12,%rdi
call   1030 <plot_fatal_error@plt>
jmp    1140 <lpow+0x30>
mov    $0x1,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"lpow: overflow detected\00"
define i64 @lpow(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i64 %0, i64* %3
store i32 %1, i32* %4
store i64 1, i64* %5
br label %6
6: ; preds = %19, %2
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i64, i64* %3
%11 = load i64, i64* %5
%12 = mul i64 %11, %10
store i64 %12, i64* %5
%13 = load i64, i64* %5
%14 = load i64, i64* %3
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @plot_fatal_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
br label %6
22: ; preds = %6
%23 = load i64, i64* %5
ret i64 %23
}

LLVM IR (-O2):
@.str = [24 x i8] c"lpow: overflow detected\00"
define i64 @lpow(i64 %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %14
4: ; preds = %2, %11
%5 = phi i64 [ %7, %11 ], [ 1, %2 ]
%6 = phi i32 [ %12, %11 ], [ %1, %2 ]
%7 = mul i64 %5, %0
%8 = icmp ult i64 %7, %0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @plot_fatal_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %4, %9
%12 = add nsw i32 %6, -1
%13 = icmp sgt i32 %6, 1
br i1 %13, label %4, label %14
14: ; preds = %11, %2
%15 = phi i64 [ 1, %2 ], [ %7, %11 ]
ret i64 %15
}