#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 galois_shift_inverse(int, int);
int galois_shift_multiply(int, int, int);
int galois_shift_divide(int a, int b, int w) {
  int inverse;
  if (b == 0)
    return -1;
  if (a == 0)
    return 0;
  inverse = galois_shift_inverse(b, w);
  return galois_shift_multiply(a, inverse, w);
}


x86 assembly (clang, -O0):
<galois_shift_divide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1147 <galois_shift_divide+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    117c <galois_shift_divide+0x5c>
cmpl   $0x0,-0x8(%rbp)
jne    115d <galois_shift_divide+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    117c <galois_shift_divide+0x5c>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <galois_shift_inverse@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <galois_shift_multiply@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<galois_shift_divide>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
je     1149 <galois_shift_divide+0x29>
mov    %edi,%ebp
test   %edi,%edi
je     1150 <galois_shift_divide+0x30>
mov    %edx,%ebx
mov    %esi,%edi
mov    %edx,%esi
call   1040 <galois_shift_inverse@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <galois_shift_multiply@plt>
mov    $0xffffffff,%eax
jmp    1152 <galois_shift_divide+0x32>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @galois_shift_divide(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %24
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 0, i32* %4
br label %24
16: ; preds = %12
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i32 @galois_shift_inverse(i32 %17, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %5
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = call i32 @galois_shift_multiply(i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %4
br label %24
24: ; preds = %16, %15, %11
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
define i32 @galois_shift_divide(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = icmp eq i32 %0, 0
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = tail call i32 @galois_shift_inverse(i32 %1, i32 %2)
%9 = tail call i32 @galois_shift_multiply(i32 %0, i32 %8, i32 %2)
br label %10
10: ; preds = %5, %3, %7
%11 = phi i32 [ %9, %7 ], [ -1, %3 ], [ 0, %5 ]
ret i32 %11
}