#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*/ EXIT_FAILURE;
scalar_t__ atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ removeEndLine(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
void trainer_dp_6(int retry) {
  printf("DATA PROCESSING LEVEL 6\n\n");
  printf("INSTRUCTION : TST\n");
  printf("PROBLEM: In the following code, r0 is not equal to 21. What must it "
         "be equal to then?\n\n");
  printf("===CODE====\n");
  printf("tst r0, r0\n");
  printf("jz end\n");
  printf("mov r0, #21\n");
  printf("end: \n\n");
  printf("answer : ");
  char buffer[10];
  if (fgets(buffer, 10, stdin) == NULL) {
    perror("Fgets error\n");
    exit(EXIT_FAILURE);
  }
  removeEndLine(buffer);
  if (atoi(buffer) == 0 && strlen(buffer) > 0) {
    printf(
        "Yes! tst with the variable itself is a way to check if it is zero.\n");
    return;
  } else {
    printf("Sorry, wrong answer!\n");
  }
  printf("Do you want to retry? [y/n] ");
  char retryBuffer[10];
  if (fgets(retryBuffer, 10, stdin) == NULL) {
    perror("Fgets error\n");
    exit(EXIT_FAILURE);
  }
  removeEndLine(retryBuffer);
  if (strcmp(retryBuffer, "y") == 0) {
    trainer_dp_6(retry + 1);
  }
}


x86 assembly (clang, -O0):
<trainer_dp_6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe5e(%rip),%rdi
call   1060 <printf@plt>
lea    0xe6c(%rip),%rdi
call   1060 <printf@plt>
lea    0xe73(%rip),%rdi
call   1060 <printf@plt>
lea    0xebf(%rip),%rdi
call   1060 <printf@plt>
lea    0xec0(%rip),%rdi
call   1060 <printf@plt>
lea    0xec0(%rip),%rdi
call   1060 <printf@plt>
lea    0xebc(%rip),%rdi
call   1060 <printf@plt>
lea    0xebd(%rip),%rdi
call   1060 <printf@plt>
lea    0xeb9(%rip),%rdi
call   1060 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    0x2dd6(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1242 <trainer_dp_6+0xb2>
lea    0xe96(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0xe(%rbp),%rdi
call   1040 <removeEndLine@plt>
lea    -0xe(%rbp),%rdi
call   10a0 <atoi@plt>
cmp    $0x0,%rax
jne    1282 <trainer_dp_6+0xf2>
lea    -0xe(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jle    1282 <trainer_dp_6+0xf2>
lea    0xe5a(%rip),%rdi
call   1060 <printf@plt>
jmp    1303 <trainer_dp_6+0x173>
lea    0xe8d(%rip),%rdi
call   1060 <printf@plt>
lea    0xe97(%rip),%rdi
call   1060 <printf@plt>
lea    -0x18(%rbp),%rdi
mov    0x2d43(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    12d5 <trainer_dp_6+0x145>
lea    0xe03(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1040 <removeEndLine@plt>
lea    -0x18(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1303 <trainer_dp_6+0x173>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1030 <trainer_dp_6@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trainer_dp_6>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
lea    0xe84(%rip),%rdi
call   1040 <puts@plt>
lea    0xe91(%rip),%rdi
call   1040 <puts@plt>
lea    0xe97(%rip),%rdi
call   1040 <puts@plt>
lea    0xee2(%rip),%rdi
call   1040 <puts@plt>
lea    0xee2(%rip),%rdi
call   1040 <puts@plt>
lea    0xee1(%rip),%rdi
call   1040 <puts@plt>
lea    0xedc(%rip),%rdi
call   1040 <puts@plt>
lea    0xedc(%rip),%rdi
call   1040 <puts@plt>
lea    0xdee(%rip),%rdi
call   1070 <printf@plt>
mov    0x2dca(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0xc(%rsp),%rdi
mov    $0xa,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     12d5 <trainer_dp_6+0x135>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <removeEndLine@plt>
mov    %rbx,%rdi
call   10b0 <atoi@plt>
test   %rax,%rax
je     12b1 <trainer_dp_6+0x111>
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb1(%rip),%rdi
call   1070 <printf@plt>
mov    0x0(%rbp),%edx
lea    0x16(%rsp),%rdi
mov    $0xa,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     12d5 <trainer_dp_6+0x135>
lea    0x16(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <removeEndLine@plt>
lea    0xd9e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    12cc <trainer_dp_6+0x12c>
add    $0x1,%r14d
mov    %r14d,%edi
call   1030 <trainer_dp_6@plt>
jmp    12cc <trainer_dp_6+0x12c>
lea    0xc(%rsp),%rdi
call   1060 <strlen@plt>
test   %rax,%rax
jle    1253 <trainer_dp_6+0xb3>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd2e(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"DATA PROCESSING LEVEL 6\0A\0A\00"
@.str.1 = [19 x i8] c"INSTRUCTION : TST\0A\00"
@.str.2 = [88 x i8] c"PROBLEM: In the following code, r0 is not equal to 21. What must it be equal to then?\0A\0A\00"
@.str.3 = [13 x i8] c"===CODE====\0A\00"
@.str.4 = [12 x i8] c"tst r0, r0\0A\00"
@.str.5 = [8 x i8] c"jz end\0A\00"
@.str.6 = [13 x i8] c"mov r0,\0A\00"
@.str.7 = [8 x i8] c"end: \0A\0A\00"
@.str.8 = [10 x i8] c"answer : \00"
@stdin = global i32 0
@.str.9 = [13 x i8] c"Fgets error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.10 = [68 x i8] c"Yes! tst with the variable itself is a way to check if it is zero.\0A\00"
@.str.11 = [22 x i8] c"Sorry, wrong answer!\0A\00"
@.str.12 = [29 x i8] c"Do you want to retry? [y/n] \00"
@.str.13 = [2 x i8] c"y\00"
define void @trainer_dp_6(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca [10 x i8]
store i32 %0, i32* %2
%5 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32* @fgets(i8* %14, i32 10, i32 %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %1
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%24 = call i32 @removeEndLine(i8* %23)
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%26 = call i64 @atoi(i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%30 = call i64 @strlen(i8* %29)
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.10, i64 0, i64 0))
br label %55
34: ; preds = %28, %22
%35 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
br label %36
36: ; preds = %34
%37 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%39 = load i32, i32* @stdin
%40 = call i32* @fgets(i8* %38, i32 10, i32 %39)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %36
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%48 = call i32 @removeEndLine(i8* %47)
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
br label %55
55: ; preds = %32, %52, %46
ret void
}

LLVM IR (-O2):
@.str.8 = [10 x i8] c"answer : \00"
@stdin = global i32 0
@.str.9 = [13 x i8] c"Fgets error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.12 = [29 x i8] c"Do you want to retry? [y/n] \00"
@.str.13 = [2 x i8] c"y\00"
@str = [25 x i8] c"DATA PROCESSING LEVEL 6\0A\00"
@str.14 = [18 x i8] c"INSTRUCTION : TST\00"
@str.15 = [87 x i8] c"PROBLEM: In the following code, r0 is not equal to 21. What must it be equal to then?\0A\00"
@str.16 = [12 x i8] c"===CODE====\00"
@str.17 = [11 x i8] c"tst r0, r0\00"
@str.18 = [7 x i8] c"jz end\00"
@str.19 = [12 x i8] c"mov r0,\00"
@str.20 = [7 x i8] c"end: \0A\00"
@str.21 = [21 x i8] c"Sorry, wrong answer!\00"
@str.22 = [67 x i8] c"Yes! tst with the variable itself is a way to check if it is zero.\00"
define void @trainer_dp_6(i32 %0) {
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.14, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @str.15, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.16, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.17, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.18, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.19, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.20, i64 0, i64 0))
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32* @fgets(i8* %13, i32 10, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %1
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %1
%22 = call i32 @removeEndLine(i8* %13)
%23 = call i64 @atoi(i8* %13)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = call i64 @strlen(i8* %13)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.22, i64 0, i64 0))
br label %48
30: ; preds = %25, %21
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.21, i64 0, i64 0))
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%34 = load i32, i32* @stdin
%35 = call i32* @fgets(i8* %33, i32 10, i32 %34)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = call i32 @removeEndLine(i8* %33)
%43 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = add nsw i32 %0, 1
br label %47
47: ; preds = %45, %41
br label %48
48: ; preds = %47, %28
ret void
}