#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ move_the_king(char *, int *, int *, int *, int);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ remove_new_line(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcasecmp(char *, char const *);
void begin_game(const char *commands[]) {
  char commandBuffer[20];
  fgets(commandBuffer, 20, stdin);
  remove_new_line(commandBuffer);
  int numbers[8] = {0};
  numbers[0] = 1;
  int currentRow = 0, currentCol = 0;
  while (strcasecmp(commandBuffer, "stop") != 0) {
    int i;
    for (i = 0; i < 8; i++) {
      if (strcasecmp(commandBuffer, commands[i]) == 0) {
        break;
      }
    }
    move_the_king(commandBuffer, numbers, &currentRow, &currentCol, i);
    fgets(commandBuffer, 20, stdin);
    remove_new_line(commandBuffer);
  }
  print_array(numbers, 8);
}


x86 assembly (clang, -O0):
<begin_game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    -0x20(%rbp),%rdi
call   1080 <remove_new_line@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
movl   $0x1,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     1251 <begin_game+0xf1>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x8,-0x4c(%rbp)
jge    1213 <begin_game+0xb3>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1200 <begin_game+0xa0>
jmp    1213 <begin_game+0xb3>
jmp    1205 <begin_game+0xa5>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11d2 <begin_game+0x72>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%r8d
lea    -0x44(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1070 <move_the_king@plt>
lea    -0x20(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    -0x20(%rbp),%rdi
call   1080 <remove_new_line@plt>
jmp    11b1 <begin_game+0x51>
lea    -0x40(%rbp),%rdi
mov    $0x8,%esi
call   1040 <print_array@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<begin_game>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%r14
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1070 <remove_new_line@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movl   $0x1,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1302 <begin_game+0x1b2>
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xe24(%rip),%rbp
jmp    1226 <begin_game+0xd6>
xchg   %ax,%ax
xor    %r8d,%r8d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1060 <move_the_king@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1070 <remove_new_line@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1302 <begin_game+0x1b2>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11e0 <begin_game+0x90>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12c0 <begin_game+0x170>
mov    0x10(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12cb <begin_game+0x17b>
mov    0x18(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12d6 <begin_game+0x186>
mov    0x20(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12e1 <begin_game+0x191>
mov    0x28(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12ec <begin_game+0x19c>
mov    0x30(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12f7 <begin_game+0x1a7>
mov    0x38(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
cmp    $0x1,%rax
mov    $0x8,%r8d
sbb    $0x0,%r8d
jmp    11e3 <begin_game+0x93>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r8d
jmp    11e3 <begin_game+0x93>
mov    $0x2,%r8d
jmp    11e3 <begin_game+0x93>
mov    $0x3,%r8d
jmp    11e3 <begin_game+0x93>
mov    $0x4,%r8d
jmp    11e3 <begin_game+0x93>
mov    $0x5,%r8d
jmp    11e3 <begin_game+0x93>
mov    $0x6,%r8d
jmp    11e3 <begin_game+0x93>
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
call   1040 <print_array@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"stop\00"
define void @begin_game(i8** %0) {
%2 = alloca i8**
%3 = alloca [20 x i8]
%4 = alloca [8 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %2
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 20, i32 %9)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%12 = call i32 @remove_new_line(i8* %11)
%13 = bitcast [8 x i32]* %4 to i8*
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
store i32 1, i32* %14
store i32 0, i32* %5
store i32 0, i32* %6
br label %15
15: ; preds = %37, %1
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%17 = call i64 @strcasecmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %47
19: ; preds = %15
store i32 0, i32* %7
br label %20
20: ; preds = %34, %19
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %37
23: ; preds = %20
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%25 = load i8**, i8*** %2
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strcasecmp(i8* %24, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
br label %37
33: ; preds = %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %20
37: ; preds = %32, %20
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%39 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%40 = load i32, i32* %7
%41 = call i32 @move_the_king(i8* %38, i32* %39, i32* %5, i32* %6, i32 %40)
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%43 = load i32, i32* @stdin
%44 = call i32 @fgets(i8* %42, i32 20, i32 %43)
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%46 = call i32 @remove_new_line(i8* %45)
br label %15
47: ; preds = %15
%48 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%49 = call i32 @print_array(i32* %48, i32 8)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"stop\00"
define void @begin_game(i8** nocapture %0) {
%2 = alloca [20 x i8]
%3 = alloca [8 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 20, i32 %7)
%9 = call i32 @remove_new_line(i8* %6)
%10 = bitcast [8 x i32]* %3 to i8*
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
store i32 1, i32* %11
%12 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%13 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%14 = call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %65, label %16
16: ; preds = %1
%17 = getelementptr inbounds i8*, i8** %0, i64 1
%18 = getelementptr inbounds i8*, i8** %0, i64 2
%19 = getelementptr inbounds i8*, i8** %0, i64 3
%20 = getelementptr inbounds i8*, i8** %0, i64 4
%21 = getelementptr inbounds i8*, i8** %0, i64 5
%22 = getelementptr inbounds i8*, i8** %0, i64 6
%23 = getelementptr inbounds i8*, i8** %0, i64 7
br label %24
24: ; preds = %16, %57
%25 = load i8*, i8** %0
%26 = call i64 @strcasecmp(i8* %6, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %57, label %28
28: ; preds = %24
%29 = load i8*, i8** %17
%30 = call i64 @strcasecmp(i8* %6, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %57, label %32
32: ; preds = %28
%33 = load i8*, i8** %18
%34 = call i64 @strcasecmp(i8* %6, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %57, label %36
36: ; preds = %32
%37 = load i8*, i8** %19
%38 = call i64 @strcasecmp(i8* %6, i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %57, label %40
40: ; preds = %36
%41 = load i8*, i8** %20
%42 = call i64 @strcasecmp(i8* %6, i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %57, label %44
44: ; preds = %40
%45 = load i8*, i8** %21
%46 = call i64 @strcasecmp(i8* %6, i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %57, label %48
48: ; preds = %44
%49 = load i8*, i8** %22
%50 = call i64 @strcasecmp(i8* %6, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %48
%53 = load i8*, i8** %23
%54 = call i64 @strcasecmp(i8* %6, i8* %53)
%55 = icmp eq i64 %54, 0
%56 = select i1 %55, i32 7, i32 8
br label %57
57: ; preds = %52, %48, %44, %40, %36, %32, %28, %24
%58 = phi i32 [ 0, %24 ], [ 1, %28 ], [ 2, %32 ], [ 3, %36 ], [ 4, %40 ], [ 5, %44 ], [ 6, %48 ], [ %56, %52 ]
%59 = call i32 @move_the_king(i8* %6, i32* %11, i32* %4, i32* %5, i32 %58)
%60 = load i32, i32* @stdin
%61 = call i32 @fgets(i8* %6, i32 20, i32 %60)
%62 = call i32 @remove_new_line(i8* %6)
%63 = call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %24
65: ; preds = %57, %1
%66 = call i32 @print_array(i32* %11, i32 8)
ret void
}