#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ print_checksum(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
void compare_checksums(char *file) {
  char name[128];
  char sum[40];
  char sum2[40];
  FILE *F = fopen(file, "r");
  if (!F) {
    fprintf(stderr, "Could not open %s.\n", file);
    return;
  }
  while (!feof(F)) {
    int num = fscanf(F, "%100[KQRBNP|v|rtbwz|.]: %32[0-9|a-f]\n", name, sum);
    if (num != 2 || strlen(sum) != 32) {
      fprintf(stderr, "Could not completely parse %s.\n", file);
      break;
    }
    FILE *G = fopen(name, "rb");
    if (!G) {
      fprintf(stderr, "Tablebase file %s not found.\n", name);
    } else {
      fclose(G);
      print_checksum(name, sum2);
      if (strcmp(sum, sum2) == 0)
        printf("%s: OK!\n", name);
      else
        printf("%s: FAIL!\n", name);
    }
  }
  fclose(F);
}


x86 assembly (clang, -O0):
<compare_checksums>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0xf8(%rbp)
cmpq   $0x0,-0xf8(%rbp)
jne    11e2 <compare_checksums+0x52>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe2a(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1335 <compare_checksums+0x1a5>
jmp    11e7 <compare_checksums+0x57>
mov    -0xf8(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1208 <compare_checksums+0x78>
jmp    1329 <compare_checksums+0x199>
mov    -0xf8(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    -0xc0(%rbp),%rcx
lea    0xdf2(%rip),%rsi
call   1060 <fscanf@plt>
mov    %eax,-0xfc(%rbp)
cmpl   $0x2,-0xfc(%rbp)
jne    1251 <compare_checksums+0xc1>
lea    -0xc0(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x20,%eax
je     126f <compare_checksums+0xdf>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdd7(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1329 <compare_checksums+0x199>
lea    -0x90(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
jne    12b8 <compare_checksums+0x128>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    0xdb1(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1324 <compare_checksums+0x194>
mov    -0x108(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x90(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
call   10a0 <print_checksum@plt>
lea    -0xc0(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    130c <compare_checksums+0x17c>
lea    -0x90(%rbp),%rsi
lea    0xd7b(%rip),%rdi
call   1050 <printf@plt>
jmp    131f <compare_checksums+0x18f>
lea    -0x90(%rbp),%rsi
lea    0xd6c(%rip),%rdi
call   1050 <printf@plt>
jmp    1324 <compare_checksums+0x194>
jmp    11e7 <compare_checksums+0x57>
mov    -0xf8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_checksums>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %rdi,%r14
lea    0xe55(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12a4 <compare_checksums+0x114>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12e5 <compare_checksums+0x155>
lea    0xe43(%rip),%r15
lea    0x60(%rsp),%r12
lea    0x30(%rsp),%r13
mov    %rsp,%rbp
jmp    1218 <compare_checksums+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    %r12,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12e5 <compare_checksums+0x155>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1060 <fscanf@plt>
cmp    $0x2,%eax
jne    12cd <compare_checksums+0x13d>
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    $0x20,%eax
jne    12cd <compare_checksums+0x13d>
mov    %r12,%rdi
lea    0xe0f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     11f0 <compare_checksums+0x60>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   10a0 <print_checksum@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1290 <compare_checksums+0x100>
lea    0xe05(%rip),%rdi
jmp    1297 <compare_checksums+0x107>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xde6(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
jmp    1208 <compare_checksums+0x78>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    %r14,%rdx
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Could not open %s.\0A\00"
@.str.2 = [38 x i8] c"%100[KQRBNP|v|rtbwz|.]: %32[0-9|a-f]\0A\00"
@.str.3 = [32 x i8] c"Could not completely parse %s.\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [30 x i8] c"Tablebase file %s not found.\0A\00"
@.str.6 = [9 x i8] c"%s: OK!\0A\00"
@.str.7 = [11 x i8] c"%s: FAIL!\0A\00"
define void @compare_checksums(i8* %0) {
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca [40 x i8]
%5 = alloca [40 x i8]
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %68
17: ; preds = %1
br label %18
18: ; preds = %64, %17
%19 = load i32*, i32** %6
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %65
23: ; preds = %18
%24 = load i32*, i32** %6
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%26 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%27 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 2
br i1 %29, label %34, label %30
30: ; preds = %23
%31 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = icmp ne i32 %32, 32
br i1 %33, label %34, label %38
34: ; preds = %30, %23
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %2
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %36)
br label %65
38: ; preds = %30
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %40, i32** %8
%41 = load i32*, i32** %8
%42 = icmp ne i32* %41, null
br i1 %42, label %47, label %43
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %45)
br label %64
47: ; preds = %38
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%51 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%52 = call i32 @print_checksum(i8* %50, i8* %51)
%53 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%54 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%55 = call i64 @strcmp(i8* %53, i8* %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %47
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%59 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %58)
br label %63
60: ; preds = %47
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%62 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %60, %57
br label %64
64: ; preds = %63, %43
br label %18
65: ; preds = %34, %18
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
br label %68
68: ; preds = %65, %13
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Could not open %s.\0A\00"
@.str.2 = [38 x i8] c"%100[KQRBNP|v|rtbwz|.]: %32[0-9|a-f]\0A\00"
@.str.3 = [32 x i8] c"Could not completely parse %s.\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [30 x i8] c"Tablebase file %s not found.\0A\00"
@.str.6 = [9 x i8] c"%s: OK!\0A\00"
@.str.7 = [11 x i8] c"%s: FAIL!\0A\00"
define void @compare_checksums(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca [40 x i8]
%4 = alloca [40 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = call i32 @feof(i32* %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %43
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %45
16: ; preds = %10, %40
%17 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %6)
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @strlen(i8* %6)
%21 = icmp eq i32 %20, 32
br i1 %21, label %25, label %22
22: ; preds = %16, %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %43
25: ; preds = %19
%26 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %40
31: ; preds = %25
%32 = call i32 @fclose(i32* %26)
%33 = call i32 @print_checksum(i8* %5, i8* %7)
%34 = call i64 @strcmp(i8* %6, i8* %7)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %5)
br label %40
38: ; preds = %31
%39 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %5)
br label %40
40: ; preds = %28, %38, %36
%41 = call i32 @feof(i32* %8)
%42 = icmp eq i32 %41, 0
br i1 %42, label %16, label %43
43: ; preds = %40, %10, %22
%44 = call i32 @fclose(i32* %8)
br label %45
45: ; preds = %43, %13
ret void
}