#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 */
long gf_mult(long, long);
long gf_div(long a, long b) {
  long r = -1, mult;
  for (int i = 0; i <= 256; ++i) {
    mult = gf_mult(b, i);
    if ((mult % 27) == 1) {
      r = i;
      break;
    }
  }
  return gf_mult(a, r);
}


x86 assembly (clang, -O0):
<gf_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jg     1185 <gf_div+0x75>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rsi
call   1030 <gf_mult@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x1b,%ecx
cqto
idiv   %rcx
cmp    $0x1,%rdx
jne    1172 <gf_div+0x62>
movslq -0x24(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1185 <gf_div+0x75>
jmp    1177 <gf_div+0x67>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112f <gf_div+0x1f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <gf_mult@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gf_div>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
movabs $0x97b425ed097b426,%r12
42 7b 09
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <gf_mult@plt>
mov    %rax,%rcx
imul   %r12
mov    %rdx,%rax
shr    $0x3f,%rax
add    %rdx,%rax
lea    (%rax,%rax,8),%rax
lea    (%rax,%rax,2),%rax
sub    %rax,%rcx
cmp    $0x1,%rcx
je     1170 <gf_div+0x60>
add    $0x1,%rbx
cmp    $0x101,%rbx
jne    1130 <gf_div+0x20>
mov    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <gf_mult@plt>

LLVM IR (-O0):
define i64 @gf_div(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 -1, i64* %5
store i32 0, i32* %7
br label %8
8: ; preds = %23, %2
%9 = load i32, i32* %7
%10 = icmp sle i32 %9, 256
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i64, i64* %4
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = call i64 @gf_mult(i64 %12, i64 %14)
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = srem i64 %16, 27
%18 = icmp eq i64 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
store i64 %21, i64* %5
br label %26
22: ; preds = %11
br label %23
23: ; preds = %22
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %8
26: ; preds = %19, %8
%27 = load i64, i64* %3
%28 = load i64, i64* %5
%29 = call i64 @gf_mult(i64 %27, i64 %28)
ret i64 %29
}

LLVM IR (-O2):
define i64 @gf_div(i64 %0, i64 %1) {
br label %3
3: ; preds = %2, %8
%4 = phi i64 [ 0, %2 ], [ %9, %8 ]
%5 = tail call i64 @gf_mult(i64 %1, i64 %4)
%6 = srem i64 %5, 27
%7 = icmp eq i64 %6, 1
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = add nuw nsw i64 %4, 1
%10 = icmp eq i64 %9, 257
br i1 %10, label %13, label %3
11: ; preds = %3
%12 = and i64 %4, 4294967295
br label %13
13: ; preds = %8, %11
%14 = phi i64 [ %12, %11 ], [ -1, %8 ]
%15 = tail call i64 @gf_mult(i64 %0, i64 %14)
ret i64 %15
}