#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*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int num = rand() % 101;
  int palpite, tentativas;
  tentativas = 0;
  printf("Sera que voce consegue acertar o numero que eu pensei?\nDigite um "
         "numero:\n\n");
  scanf("%d", &palpite);
  while (palpite != num) {
    if (palpite > num) {
      printf(
          "O seu palpite e MAIOR que o numero que eu pensei, tente outro!\n");
      scanf("%d", &palpite);
    } else {
      printf(
          "O seu palpite e MENOR que o numero que eu pensei, tente outro!\n");
      scanf("%d", &palpite);
    }
    tentativas++;
  }
  printf("Parabens, voce acertou! O numero sorteado foi o: %d\nVoce acertou "
         "ele apos: %d tentativas.\n",
         num, tentativas);
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x65,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     121d <main+0xbd>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11f1 <main+0x91>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
jmp    120f <main+0xaf>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe45(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b6 <main+0x56>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <getch@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%r14
imul   $0x288df0cb,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x24,%rax
add    %ecx,%eax
imul   $0x65,%eax,%eax
sub    %eax,%r14d
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %r14d,%eax
jne    1200 <main+0x90>
lea    0xe27(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <getch@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
lea    0xede(%rip),%r13
lea    0xe98(%rip),%rbp
lea    0xde9(%rip),%r15
lea    0x4(%rsp),%r12
jmp    123c <main+0xcc>
xchg   %ax,%ax
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
add    $0x1,%ebx
mov    0x4(%rsp),%eax
cmp    %r14d,%eax
je     11d5 <main+0x65>
mov    %r13,%rdi
cmp    %r14d,%eax
jg     1220 <main+0xb0>
mov    %rbp,%rdi
jmp    1220 <main+0xb0>

LLVM IR (-O0):
@.str = [75 x i8] c"Sera que voce consegue acertar o numero que eu pensei?\0ADigite um numero:\0A\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [64 x i8] c"O seu palpite e MAIOR que o numero que eu pensei, tente outro!\0A\00"
@.str.3 = [64 x i8] c"O seu palpite e MENOR que o numero que eu pensei, tente outro!\0A\00"
@.str.4 = [91 x i8] c"Parabens, voce acertou! O numero sorteado foi o: %d\0AVoce acertou ele apos: %d tentativas.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 101
store i32 %8, i32* %2
store i32 0, i32* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %11
11: ; preds = %25, %0
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %25
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %25
25: ; preds = %22, %19
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %11
28: ; preds = %11
%29 = load i32, i32* %2
%30 = load i32, i32* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %30)
%32 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [91 x i8] c"Parabens, voce acertou! O numero sorteado foi o: %d\0AVoce acertou ele apos: %d tentativas.\0A\00"
@str = [74 x i8] c"Sera que voce consegue acertar o numero que eu pensei?\0ADigite um numero:\0A\00"
@str.5 = [63 x i8] c"O seu palpite e MENOR que o numero que eu pensei, tente outro!\00"
@str.6 = [63 x i8] c"O seu palpite e MAIOR que o numero que eu pensei, tente outro!\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 101
%6 = bitcast i32* %1 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, %5
br i1 %10, label %21, label %11
11: ; preds = %0, %11
%12 = phi i32 [ %19, %11 ], [ %9, %0 ]
%13 = phi i32 [ %18, %11 ], [ 0, %0 ]
%14 = icmp sgt i32 %12, %5
%15 = select i1 %14, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([63 x i8], [63 x i8]* @str.5, i64 0, i64 0)
%16 = call i32 @puts(i8* dereferenceable(1) %15)
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%18 = add nuw nsw i32 %13, 1
%19 = load i32, i32* %1
%20 = icmp eq i32 %19, %5
br i1 %20, label %21, label %11
21: ; preds = %11, %0
%22 = phi i32 [ 0, %0 ], [ %18, %11 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.4, i64 0, i64 0), i32 %5, i32 %22)
%24 = call i32 (...) @getch()
ret i32 0
}