#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 gadd(int, int);
int gdiv(int, int);
int gmul(int, int);
int /*<<< orphan*/ printf(char *);
int galoisTest() {
  uint8_t a, b, c;
  int isOk = 1 == 1;
  a = 0x01;
  b = 0x0A;
  c = 0x0B;
  if ((gadd(a, b) != c)) {
    printf("Galois addition failed\n");
    isOk = 1 == 0;
  }
  if ((gmul(a, b) != b) || (gmul(0x02, 0x02) != 0x04)) {
    printf("Galois multiplication failed\n");
    isOk = 1 == 0;
  }
  if ((gdiv(b, a) != b) || (gdiv(0x02, 0x02) != 0x01)) {
    printf("Galois division failed\n");
    isOk = 1 == 0;
  }
  return isOk;
}


x86 assembly (clang, -O0):
<galoisTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0xb,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <gadd@plt>
cmp    -0xc(%rbp),%eax
je     118b <galoisTest+0x4b>
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <gmul@plt>
cmp    -0x8(%rbp),%eax
jne    11b4 <galoisTest+0x74>
mov    $0x2,%esi
mov    %esi,%edi
call   1060 <gmul@plt>
cmp    $0x4,%eax
je     11c7 <galoisTest+0x87>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <gdiv@plt>
cmp    -0x8(%rbp),%eax
jne    11f0 <galoisTest+0xb0>
mov    $0x2,%esi
mov    %esi,%edi
call   1050 <gdiv@plt>
cmp    $0x1,%eax
je     1203 <galoisTest+0xc3>
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<galoisTest>:
push   %rbx
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0xa,%esi
call   1030 <gadd@plt>
cmp    $0xb,%eax
je     1168 <galoisTest+0x28>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    $0x1,%edi
mov    $0xa,%esi
call   1060 <gmul@plt>
cmp    $0xa,%eax
jne    1190 <galoisTest+0x50>
mov    $0x2,%edi
mov    $0x2,%esi
call   1060 <gmul@plt>
cmp    $0x4,%eax
je     119e <galoisTest+0x5e>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gdiv@plt>
cmp    $0xa,%eax
jne    11c6 <galoisTest+0x86>
mov    $0x2,%edi
mov    $0x2,%esi
call   1050 <gdiv@plt>
cmp    $0x1,%eax
je     11d4 <galoisTest+0x94>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Galois addition failed\0A\00"
@.str.1 = [30 x i8] c"Galois multiplication failed\0A\00"
@.str.2 = [24 x i8] c"Galois division failed\0A\00"
define i32 @galoisTest() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 1, i32* %4
store i32 1, i32* %1
store i32 10, i32* %2
store i32 11, i32* %3
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = call i32 @gadd(i32 %5, i32 %6)
%8 = load i32, i32* %3
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %12
12: ; preds = %10, %0
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = call i32 @gmul(i32 %13, i32 %14)
%16 = load i32, i32* %2
%17 = icmp ne i32 %15, %16
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = call i32 @gmul(i32 2, i32 2)
%20 = icmp ne i32 %19, 4
br i1 %20, label %21, label %23
21: ; preds = %18, %12
%22 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %2
%25 = load i32, i32* %1
%26 = call i32 @gdiv(i32 %24, i32 %25)
%27 = load i32, i32* %2
%28 = icmp ne i32 %26, %27
br i1 %28, label %32, label %29
29: ; preds = %23
%30 = call i32 @gdiv(i32 2, i32 2)
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %29, %23
%33 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@str = [23 x i8] c"Galois division failed\00"
@str.3 = [29 x i8] c"Galois multiplication failed\00"
@str.4 = [23 x i8] c"Galois addition failed\00"
define i32 @galoisTest() {
%1 = tail call i32 @gadd(i32 1, i32 10)
%2 = icmp eq i32 %1, 11
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = phi i32 [ 0, %3 ], [ 1, %0 ]
%7 = tail call i32 @gmul(i32 1, i32 10)
%8 = icmp eq i32 %7, 10
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @gmul(i32 2, i32 2)
%11 = icmp eq i32 %10, 4
br i1 %11, label %14, label %12
12: ; preds = %9, %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = phi i32 [ 0, %12 ], [ %6, %9 ]
%16 = tail call i32 @gdiv(i32 10, i32 1)
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @gdiv(i32 2, i32 2)
%20 = icmp eq i32 %19, 1
br i1 %20, label %23, label %21
21: ; preds = %18, %14
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = phi i32 [ 0, %21 ], [ %15, %18 ]
ret i32 %24
}