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


x86 assembly (clang, -O0):
<gf65536_exp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1154 <gf65536_exp+0x24>
movl   $0x1,-0x4(%rbp)
jmp    11e1 <gf65536_exp+0xb1>
cmpl   $0x0,-0xc(%rbp)
jge    117a <gf65536_exp+0x4a>
mov    -0x8(%rbp),%edi
call   1030 <gf65536_inverse@plt>
mov    %eax,%edi
xor    %esi,%esi
sub    -0xc(%rbp),%esi
call   1050 <gf65536_exp@plt>
mov    %eax,-0x4(%rbp)
jmp    11e1 <gf65536_exp+0xb1>
movl   $0x1,-0x10(%rbp)
movl   $0x1f,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11db <gf65536_exp+0xab>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <gf65536_multiply@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11c8 <gf65536_exp+0x98>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <gf65536_multiply@plt>
mov    %eax,-0x10(%rbp)
jmp    11cd <gf65536_exp+0x9d>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <gf65536_exp+0x58>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gf65536_exp>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
je     1133 <gf65536_exp+0x13>
mov    %esi,%ebx
mov    %edi,%r14d
js     113d <gf65536_exp+0x1d>
mov    %ebx,%ebp
jmp    1153 <gf65536_exp+0x33>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebx,%ebp
nop
mov    %r14d,%edi
call   1030 <gf65536_inverse@plt>
mov    %eax,%r14d
neg    %ebp
test   %ebx,%ebx
mov    %ebp,%ebx
jg     1140 <gf65536_exp+0x20>
mov    $0x1,%eax
mov    $0x1f,%ebx
jmp    1165 <gf65536_exp+0x45>
nop
add    $0xffffffff,%ebx
jae    1138 <gf65536_exp+0x18>
mov    %eax,%edi
mov    %eax,%esi
call   1040 <gf65536_multiply@plt>
bt     %ebx,%ebp
jae    1160 <gf65536_exp+0x40>
mov    %eax,%edi
mov    %r14d,%esi
call   1040 <gf65536_multiply@plt>
jmp    1160 <gf65536_exp+0x40>

LLVM IR (-O0):
define i32 @gf65536_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 %43
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 @gf65536_inverse(i32 %15)
%17 = load i32, i32* %5
%18 = sub nsw i32 0, %17
%19 = call i32 @gf65536_exp(i32 %16, i32 %18)
store i32 %19, i32* %3
br label %43
20: ; preds = %11
store i32 1, i32* %6
store i32 31, i32* %7
br label %21
21: ; preds = %38, %20
%22 = load i32, i32* %7
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %21
%25 = load i32, i32* %6
%26 = load i32, i32* %6
%27 = call i32 @gf65536_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 = and i32 %28, %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i32, i32* %6
%35 = load i32, i32* %4
%36 = call i32 @gf65536_multiply(i32 %34, i32 %35)
store i32 %36, i32* %6
br label %37
37: ; preds = %33, %24
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, -1
store i32 %40, i32* %7
br label %21
41: ; preds = %21
%42 = load i32, i32* %6
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %14, %10
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @gf65536_exp(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %28, label %4
4: ; preds = %2
%5 = icmp slt i32 %1, 0
br i1 %5, label %9, label %6
6: ; preds = %9, %4
%7 = phi i32 [ %1, %4 ], [ %13, %9 ]
%8 = phi i32 [ %0, %4 ], [ %12, %9 ]
br label %15
9: ; preds = %4, %9
%10 = phi i32 [ %12, %9 ], [ %0, %4 ]
%11 = phi i32 [ %13, %9 ], [ %1, %4 ]
%12 = tail call i32 @gf65536_inverse(i32 %10)
%13 = sub nsw i32 0, %11
%14 = icmp sgt i32 %11, 0
br i1 %14, label %9, label %6
15: ; preds = %6, %24
%16 = phi i32 [ 31, %6 ], [ %26, %24 ]
%17 = phi i32 [ 1, %6 ], [ %25, %24 ]
%18 = tail call i32 @gf65536_multiply(i32 %17, i32 %17)
%19 = shl nuw i32 1, %16
%20 = and i32 %19, %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = tail call i32 @gf65536_multiply(i32 %18, i32 %8)
br label %24
24: ; preds = %15, %22
%25 = phi i32 [ %23, %22 ], [ %18, %15 ]
%26 = add nsw i32 %16, -1
%27 = icmp eq i32 %16, 0
br i1 %27, label %28, label %15
28: ; preds = %24, %2
%29 = phi i32 [ 1, %2 ], [ %25, %24 ]
ret i32 %29
}