#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 */
typedef int uint8_t;

/* Variables and functions */
int gfmul(int, int);
uint8_t gfpow(uint8_t a, int b) {
  uint8_t v = 1;
  b %= 255;
  if (b < 0)
    b += 255;
  while (b) {
    if (b & 1)
      v = gfmul(v, a);
    a = gfmul(a, a);
    b >>= 1;
  }
  return v;
}


x86 assembly (clang, -O0):
<gfpow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1148 <gfpow+0x38>
mov    -0x8(%rbp),%eax
add    $0xff,%eax
mov    %eax,-0x8(%rbp)
jmp    114d <gfpow+0x3d>
cmpl   $0x0,-0x8(%rbp)
je     1190 <gfpow+0x80>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1174 <gfpow+0x64>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <gfmul@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <gfmul@plt>
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114d <gfpow+0x3d>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfpow>:
push   %rbp
push   %r14
push   %rbx
movslq %esi,%rax
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%ebp
add    $0xff,%ebp
add    %ecx,%eax
cmovns %eax,%ebp
test   %ebp,%ebp
je     118b <gfpow+0x7b>
mov    %edi,%ebx
mov    $0x1,%r14d
jmp    1176 <gfpow+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %ebx,%esi
call   1030 <gfmul@plt>
mov    %eax,%ebx
mov    %ebp,%eax
sar    %eax
cmp    $0x1,%ebp
mov    %eax,%ebp
jbe    1191 <gfpow+0x81>
test   $0x1,%bpl
je     1160 <gfpow+0x50>
mov    %r14d,%edi
mov    %ebx,%esi
call   1030 <gfmul@plt>
mov    %eax,%r14d
jmp    1160 <gfpow+0x50>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gfpow(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %5
%6 = load i32, i32* %4
%7 = srem i32 %6, 255
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 255
store i32 %12, i32* %4
br label %13
13: ; preds = %10, %2
br label %14
14: ; preds = %25, %13
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i32, i32* %4
%19 = and i32 %18, 1
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %5
%23 = load i32, i32* %3
%24 = call i32 @gfmul(i32 %22, i32 %23)
store i32 %24, i32* %5
br label %25
25: ; preds = %21, %17
%26 = load i32, i32* %3
%27 = load i32, i32* %3
%28 = call i32 @gfmul(i32 %26, i32 %27)
store i32 %28, i32* %3
%29 = load i32, i32* %4
%30 = ashr i32 %29, 1
store i32 %30, i32* %4
br label %14
31: ; preds = %14
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @gfpow(i32 %0, i32 %1) {
%3 = srem i32 %1, 255
%4 = icmp slt i32 %3, 0
%5 = add nsw i32 %3, 255
%6 = select i1 %4, i32 %5, i32 %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %2, %16
%9 = phi i32 [ %17, %16 ], [ 1, %2 ]
%10 = phi i32 [ %19, %16 ], [ %6, %2 ]
%11 = phi i32 [ %18, %16 ], [ %0, %2 ]
%12 = and i32 %10, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = tail call i32 @gfmul(i32 %9, i32 %11)
br label %16
16: ; preds = %14, %8
%17 = phi i32 [ %15, %14 ], [ %9, %8 ]
%18 = tail call i32 @gfmul(i32 %11, i32 %11)
%19 = ashr i32 %10, 1
%20 = icmp ult i32 %10, 2
br i1 %20, label %21, label %8
21: ; preds = %16, %2
%22 = phi i32 [ 1, %2 ], [ %17, %16 ]
ret i32 %22
}