#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*/ printf(char *, ...);
int randomInt(int);
int /*<<< orphan*/ scanf(char *, int *);
void priklad_tri(int max_cislo) {
  printf("===== PRIKLAD 3 =====\n");
  int error_count = 0;
  int random_number = randomInt(max_cislo);
  int player_tip;
  bool gameover = false;
  while (!gameover) {
    printf("Zadejte svuj tip. Hledane cislo je mezi 0 a %d:", max_cislo);
    scanf("%d", &player_tip);
    if (player_tip == random_number) {
      printf("Tipovane cislo je spravne. Celkem jste udelal/a %d chyb.\n",
             error_count);
      gameover = true;
    } else if (player_tip > random_number) {
      printf("Bohuzel hledane cislo je mensi nez vami zadane cislo.\n");
      error_count++;
    } else {
      printf("Bohuzel hledane cislo je vetsi nez vami zadane cislo.\n");
      error_count++;
    }
  }
  printf("===== KONEC PRIKLADU 3 =====\n");
}


x86 assembly (clang, -O0):
<priklad_tri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <randomInt@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1178 <priklad_tri+0x48>
jmp    120b <priklad_tri+0xdb>
mov    -0x4(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11c2 <priklad_tri+0x92>
mov    -0x8(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1206 <priklad_tri+0xd6>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11ea <priklad_tri+0xba>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1201 <priklad_tri+0xd1>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1206 <priklad_tri+0xd6>
jmp    1162 <priklad_tri+0x32>
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priklad_tri>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0xf18(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1050 <randomInt@plt>
mov    %eax,%ebp
lea    0xe95(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebp,%eax
jne    11bb <priklad_tri+0x7b>
lea    0xe9c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3e(%rip),%r15
lea    0xe67(%rip),%r12
lea    0x4(%rsp),%r13
xor    %ebx,%ebx
jmp    1208 <priklad_tri+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <puts@plt>
add    $0x1,%ebx
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebp,%eax
je     1190 <priklad_tri+0x50>
lea    0xec7(%rip),%rdi
cmp    %ebp,%eax
jg     11e0 <priklad_tri+0xa0>
lea    0xe86(%rip),%rdi
jmp    11e0 <priklad_tri+0xa0>

LLVM IR (-O0):
@.str = [23 x i8] c"===== PRIKLAD 3 =====\0A\00"
@.str.1 = [48 x i8] c"Zadejte svuj tip. Hledane cislo je mezi 0 a %d:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [58 x i8] c"Tipovane cislo je spravne. Celkem jste udelal/a %d chyb.\0A\00"
@.str.4 = [55 x i8] c"Bohuzel hledane cislo je mensi nez vami zadane cislo.\0A\00"
@.str.5 = [55 x i8] c"Bohuzel hledane cislo je vetsi nez vami zadane cislo.\0A\00"
@.str.6 = [30 x i8] c"===== KONEC PRIKLADU 3 =====\0A\00"
define void @priklad_tri(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
%8 = load i32, i32* %2
%9 = call i32 @randomInt(i32 %8)
store i32 %9, i32* %4
store i32 0, i32* %6
br label %10
10: ; preds = %37, %1
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %22)
store i32 1, i32* %6
br label %37
24: ; preds = %14
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %36
32: ; preds = %24
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %36
36: ; preds = %32, %28
br label %37
37: ; preds = %36, %21
br label %10
38: ; preds = %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [48 x i8] c"Zadejte svuj tip. Hledane cislo je mezi 0 a %d:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [58 x i8] c"Tipovane cislo je spravne. Celkem jste udelal/a %d chyb.\0A\00"
@str = [22 x i8] c"===== PRIKLAD 3 =====\00"
@str.7 = [29 x i8] c"===== KONEC PRIKLADU 3 =====\00"
@str.8 = [54 x i8] c"Bohuzel hledane cislo je vetsi nez vami zadane cislo.\00"
@str.9 = [54 x i8] c"Bohuzel hledane cislo je mensi nez vami zadane cislo.\00"
define void @priklad_tri(i32 %0) {
%2 = alloca i32
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @randomInt(i32 %0)
%5 = bitcast i32* %2 to i8*
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, %4
br i1 %9, label %21, label %10
10: ; preds = %1, %10
%11 = phi i32 [ %19, %10 ], [ %8, %1 ]
%12 = phi i32 [ %16, %10 ], [ 0, %1 ]
%13 = icmp sgt i32 %11, %4
%14 = select i1 %13, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @str.8, i64 0, i64 0)
%15 = call i32 @puts(i8* dereferenceable(1) %14)
%16 = add nuw nsw i32 %12, 1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, %4
br i1 %20, label %21, label %10
21: ; preds = %10, %1
%22 = phi i32 [ 0, %1 ], [ %16, %10 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
ret void
}