#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 int gf16777216_inverse(unsigned int);
unsigned int gf16777216_multiply(unsigned int, unsigned int);
unsigned int gf16777216_exp(unsigned int element, int exponent) {
  unsigned int acc;
  int i;
  if (exponent == 0) {
    return 1;
  }
  if (exponent < 0) {
    return gf16777216_exp(gf16777216_inverse(element), -exponent);
  }
  acc = 0;
  for (i = sizeof(int) * 8 - 1; i >= 0; ++i) {
    acc = gf16777216_multiply(acc, acc);
    if (exponent & (1 << i) != 0) {
      acc = gf16777216_multiply(acc, element);
    }
  }
  return acc;
}


x86 assembly (clang, -O0):
<gf16777216_exp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1154 <gf16777216_exp+0x24>
movl   $0x1,-0x4(%rbp)
jmp    11ed <gf16777216_exp+0xbd>
cmpl   $0x0,-0xc(%rbp)
jge    117a <gf16777216_exp+0x4a>
mov    -0x8(%rbp),%edi
call   1040 <gf16777216_inverse@plt>
mov    %eax,%edi
xor    %esi,%esi
sub    -0xc(%rbp),%esi
call   1030 <gf16777216_exp@plt>
mov    %eax,-0x4(%rbp)
jmp    11ed <gf16777216_exp+0xbd>
movl   $0x0,-0x10(%rbp)
movl   $0x1f,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11e7 <gf16777216_exp+0xb7>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <gf16777216_multiply@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    $0x0,%ecx
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11d4 <gf16777216_exp+0xa4>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <gf16777216_multiply@plt>
mov    %eax,-0x10(%rbp)
jmp    11d9 <gf16777216_exp+0xa9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <gf16777216_exp+0x58>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gf16777216_exp>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
je     1134 <gf16777216_exp+0x14>
mov    %esi,%r14d
mov    %edi,%ebx
js     113e <gf16777216_exp+0x1e>
mov    %r14d,%ebp
jmp    1163 <gf16777216_exp+0x43>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <gf16777216_inverse@plt>
mov    %eax,%ebx
neg    %ebp
test   %r14d,%r14d
mov    %ebp,%r14d
jg     1150 <gf16777216_exp+0x30>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edi
mov    %eax,%esi
call   1040 <gf16777216_multiply@plt>
test   $0x1,%bpl
je     1170 <gf16777216_exp+0x50>
mov    %eax,%edi
mov    %ebx,%esi
call   1040 <gf16777216_multiply@plt>
jmp    1170 <gf16777216_exp+0x50>

LLVM IR (-O0):
define i32 @gf16777216_exp(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %45
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %4
%16 = call i32 @gf16777216_inverse(i32 %15)
%17 = load i32, i32* %5
%18 = sub nsw i32 0, %17
%19 = call i32 @gf16777216_exp(i32 %16, i32 %18)
store i32 %19, i32* %3
br label %45
20: ; preds = %11
store i32 0, i32* %6
store i32 31, i32* %7
br label %21
21: ; preds = %40, %20
%22 = load i32, i32* %7
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %43
24: ; preds = %21
%25 = load i32, i32* %6
%26 = load i32, i32* %6
%27 = call i32 @gf16777216_multiply(i32 %25, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = shl i32 1, %29
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i32
%33 = and i32 %28, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %24
%36 = load i32, i32* %6
%37 = load i32, i32* %4
%38 = call i32 @gf16777216_multiply(i32 %36, i32 %37)
store i32 %38, i32* %6
br label %39
39: ; preds = %35, %24
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %21
43: ; preds = %21
%44 = load i32, i32* %6
store i32 %44, i32* %3
br label %45
45: ; preds = %43, %14, %10
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
define i32 @gf16777216_exp(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %24, label %4
4: ; preds = %2
%5 = icmp slt i32 %1, 0
br i1 %5, label %11, label %6
6: ; preds = %11, %4
%7 = phi i32 [ %1, %4 ], [ %15, %11 ]
%8 = phi i32 [ %0, %4 ], [ %14, %11 ]
%9 = and i32 %7, 1
%10 = icmp eq i32 %9, 0
br label %17
11: ; preds = %4, %11
%12 = phi i32 [ %14, %11 ], [ %0, %4 ]
%13 = phi i32 [ %15, %11 ], [ %1, %4 ]
%14 = tail call i32 @gf16777216_inverse(i32 %12)
%15 = sub nsw i32 0, %13
%16 = icmp sgt i32 %13, 0
br i1 %16, label %11, label %6
17: ; preds = %20, %6
%18 = phi i32 [ 0, %6 ], [ %21, %20 ]
%19 = tail call i32 @gf16777216_multiply(i32 %18, i32 %18)
br i1 %10, label %20, label %22
20: ; preds = %17, %22
%21 = phi i32 [ %23, %22 ], [ %19, %17 ]
br label %17
22: ; preds = %17
%23 = tail call i32 @gf16777216_multiply(i32 %19, i32 %8)
br label %20
24: ; preds = %2
ret i32 1
}