#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int checkArguments(int, char **, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getBoardSize(int /*<<< orphan*/ *);
int getTransformations(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ transformAndPrintGame(int /*<<< orphan*/ *, int, int);
int main(int argc, char **argv) {
  char *game;
  int retValue = checkArguments(argc, argv, &game);
  if (retValue == EXIT_FAILURE) {
    return EXIT_FAILURE;
  }
  FILE *gameFile;
  gameFile = fopen(game, "r");
  if (gameFile == NULL) {
    fprintf(stderr, "normalize-game: Could not open file %s\n", game);
    return EXIT_FAILURE;
  }
  fprintf(stderr, "normalize-game: Normalizing game: %s\n", game);
  int boardSize = getBoardSize(gameFile);
  if (boardSize < 0) {
    fprintf(stderr,
            "normalize-game: Could not find board size in game file %s\n",
            game);
    return EXIT_FAILURE;
  }
  fprintf(stderr, "normalize-game: Board size: %d\n", boardSize);
  int transformations = getTransformations(gameFile, boardSize);
  if (transformations == -99) {
    printf("normalize-game: File contains no moves.\n");
    transformations = 0;
  } else if (transformations < 0) {
    fprintf(
        stderr,
        "normalize-game: Serious error occured when reading game file: %d\n",
        transformations);
    return EXIT_FAILURE;
  }
  fprintf(stderr, "normalize-game: Transformations: %d\n", transformations);
  transformAndPrintGame(gameFile, boardSize, transformations);
  fclose(gameFile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <checkArguments@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e25(%rip),%rcx
cmp    (%rcx),%eax
jne    11cc <main+0x4c>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1337 <main+0x1b7>
mov    -0x18(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1217 <main+0x97>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1337 <main+0x1b7>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <getBoardSize@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1274 <main+0xf4>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1337 <main+0x1b7>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10a0 <getTransformations@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffff9d,-0x30(%rbp)
jne    12bf <main+0x13f>
lea    0xdfd(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x30(%rbp)
jmp    12f9 <main+0x179>
cmpl   $0x0,-0x30(%rbp)
jge    12f4 <main+0x174>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1337 <main+0x1b7>
jmp    12f9 <main+0x179>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1030 <transformAndPrintGame@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdx
call   1070 <checkArguments@plt>
mov    0x2e3b(%rip),%rbp
cmp    0x0(%rbp),%eax
je     1291 <main+0x111>
mov    0x8(%rsp),%rdi
lea    0xe4e(%rip),%rsi
call   1090 <fopen@plt>
mov    0x2e22(%rip),%r12
mov    (%r12),%edi
mov    0x8(%rsp),%rdx
test   %rax,%rax
je     1221 <main+0xa1>
mov    %rax,%rbx
lea    0xe54(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <getBoardSize@plt>
mov    (%r12),%edi
test   %eax,%eax
js     122a <main+0xaa>
mov    %eax,%r15d
lea    0xe94(%rip),%rsi
xor    %r14d,%r14d
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   10a0 <getTransformations@plt>
cmp    $0xffffff9d,%eax
jne    123f <main+0xbf>
lea    0xef8(%rip),%rdi
call   1040 <puts@plt>
jmp    1246 <main+0xc6>
lea    0xdda(%rip),%rsi
jmp    1236 <main+0xb6>
mov    0x8(%rsp),%rdx
lea    0xe1a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    128e <main+0x10e>
test   %eax,%eax
js     127a <main+0xfa>
mov    %eax,%r14d
mov    (%r12),%edi
lea    0xe9c(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <transformAndPrintGame@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2d58(%rip),%rbp
jmp    128e <main+0x10e>
mov    (%r12),%edi
lea    0xe26(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"normalize-game: Could not open file %s\0A\00"
@.str.2 = [38 x i8] c"normalize-game: Normalizing game: %s\0A\00"
@.str.3 = [59 x i8] c"normalize-game: Could not find board size in game file %s\0A\00"
@.str.4 = [32 x i8] c"normalize-game: Board size: %d\0A\00"
@.str.5 = [41 x i8] c"normalize-game: File contains no moves.\0A\00"
@.str.6 = [66 x i8] c"normalize-game: Serious error occured when reading game file: %d\0A\00"
@.str.7 = [37 x i8] c"normalize-game: Transformations: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @checkArguments(i32 %11, i8** %12, i8** %6)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = load i32, i32* @EXIT_FAILURE
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %73
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %6
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %73
29: ; preds = %19
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %8
%34 = call i32 @getBoardSize(i32* %33)
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %6
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
store i32 %41, i32* %3
br label %73
42: ; preds = %29
%43 = load i32, i32* @stderr
%44 = load i32, i32* %9
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %8
%47 = load i32, i32* %9
%48 = call i32 @getTransformations(i32* %46, i32 %47)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = icmp eq i32 %49, -99
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %10
br label %62
53: ; preds = %42
%54 = load i32, i32* %10
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = load i32, i32* %10
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0), i32 %58)
%60 = load i32, i32* @EXIT_FAILURE
store i32 %60, i32* %3
br label %73
61: ; preds = %53
br label %62
62: ; preds = %61, %51
%63 = load i32, i32* @stderr
%64 = load i32, i32* %10
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %64)
%66 = load i32*, i32** %8
%67 = load i32, i32* %9
%68 = load i32, i32* %10
%69 = call i32 @transformAndPrintGame(i32* %66, i32 %67, i32 %68)
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* @EXIT_SUCCESS
store i32 %72, i32* %3
br label %73
73: ; preds = %62, %56, %37, %24, %17
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"normalize-game: Could not open file %s\0A\00"
@.str.2 = [38 x i8] c"normalize-game: Normalizing game: %s\0A\00"
@.str.3 = [59 x i8] c"normalize-game: Could not find board size in game file %s\0A\00"
@.str.4 = [32 x i8] c"normalize-game: Board size: %d\0A\00"
@.str.6 = [66 x i8] c"normalize-game: Serious error occured when reading game file: %d\0A\00"
@.str.7 = [37 x i8] c"normalize-game: Transformations: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [40 x i8] c"normalize-game: File contains no moves.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @checkArguments(i32 %0, i8** %1, i8** %3)
%6 = load i32, i32* @EXIT_FAILURE
%7 = icmp eq i32 %5, %6
br i1 %7, label %44, label %8
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
br i1 %11, label %14, label %16
14: ; preds = %8
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %41
16: ; preds = %8
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%18 = call i32 @getBoardSize(i32* %10)
%19 = icmp slt i32 %18, 0
%20 = load i32, i32* @stderr
br i1 %19, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %41
24: ; preds = %16
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%26 = call i32 @getTransformations(i32* %10, i32 %18)
%27 = icmp eq i32 %26, -99
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %35
30: ; preds = %24
%31 = icmp slt i32 %26, 0
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0), i32 %26)
br label %41
35: ; preds = %30, %28
%36 = phi i32 [ 0, %28 ], [ %26, %30 ]
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%39 = call i32 @transformAndPrintGame(i32* %10, i32 %18, i32 %36)
%40 = call i32 @fclose(i32* %10)
br label %41
41: ; preds = %21, %35, %32, %14
%42 = phi i32* [ @EXIT_FAILURE, %14 ], [ @EXIT_FAILURE, %21 ], [ @EXIT_SUCCESS, %35 ], [ @EXIT_FAILURE, %32 ]
%43 = load i32, i32* %42
br label %44
44: ; preds = %2, %41
%45 = phi i32 [ %43, %41 ], [ %5, %2 ]
ret i32 %45
}