#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 *calloc(int, int);
scalar_t__ coincideNumero(int *, int *, int);
int elegirCantDigitos();
int elegirNivel(int);
int /*<<< orphan*/ generaAleatorio(int *, int);
int /*<<< orphan*/ leerNumero(int *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(void) {
  srand(time(0));
  int *incognita;
  int *numero;
  int digits, nivel, i, j;
  digits = elegirCantDigitos();
  incognita = malloc(digits * sizeof(int));
  numero = calloc(digits, sizeof(int));
  if (incognita == NULL || numero == NULL) {
    return 0;
  }
  generaAleatorio(incognita, digits);
  nivel = elegirNivel(10);
  for (i = 1; i <= nivel; i++) {
    leerNumero(numero, digits);
    printf("Numero ingresado = ");
    for (j = 0; j < digits; j++) {
      printf("%d", numero[j]);
    }
    printf("\n");
    if (coincideNumero(incognita, numero, digits)) {
      printf("\n~~~ GANASTE! ~~~\n\n");
      return 1;
    } else if (i == nivel)
      printf("\n~~~ Perdiste ~~~\n\n");
    else
      printf("\n~~~ Intenta de nuevo ~~~\n\n");
  }
  printf("El numero era: ");
  for (i = 0; i < digits; i++) {
    printf("%d", incognita[i]);
  }
  printf("\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1060 <elegirCantDigitos@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1201 <main+0x61>
cmpq   $0x0,-0x18(%rbp)
jne    120d <main+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x1d1>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <generaAleatorio@plt>
mov    $0xa,%edi
call   10b0 <elegirNivel@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1314 <main+0x174>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <leerNumero@plt>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    128d <main+0xed>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    125a <main+0xba>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <coincideNumero@plt>
cmp    $0x0,%rax
je     12cf <main+0x12f>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1371 <main+0x1d1>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    12ee <main+0x14e>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12fc <main+0x15c>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1301 <main+0x161>
jmp    1306 <main+0x166>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122d <main+0x8d>
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    135c <main+0x1bc>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1329 <main+0x189>
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   1080 <elegirCantDigitos@plt>
mov    %eax,%ebx
lea    0x0(,%rbx,4),%edi
call   10b0 <malloc@plt>
mov    %rax,%r13
mov    %rbx,0x8(%rsp)
mov    %ebx,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
test   %r13,%r13
je     1355 <main+0x195>
mov    %rax,%rbx
test   %rax,%rax
je     1355 <main+0x195>
mov    %r13,%rdi
mov    0x8(%rsp),%rbp
mov    %ebp,%esi
call   10a0 <generaAleatorio@plt>
mov    $0xa,%edi
call   10d0 <elegirNivel@plt>
mov    %ebp,%r12d
mov    %eax,0x14(%rsp)
test   %eax,%eax
jle    12f8 <main+0x138>
mov    $0x1,%r14d
lea    0xdc3(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%r15
mov    %rbx,%rdi
mov    0x8(%rsp),%r13
mov    %r13d,%esi
call   10e0 <leerNumero@plt>
lea    0xd86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13d,%r13d
jle    12a7 <main+0xe7>
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    (%rbx,%r13,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r13
cmp    %r13,%r12
jne    1290 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%r13
mov    %r15,%rdi
mov    %rbx,%rsi
mov    0x8(%rsp),%rdx
call   10c0 <coincideNumero@plt>
test   %rax,%rax
jne    1344 <main+0x184>
mov    0x14(%rsp),%r15d
cmp    %r15d,%r14d
lea    0xd4f(%rip),%rdi
lea    0xd63(%rip),%rax
cmove  %rax,%rdi
call   1040 <puts@plt>
lea    0x1(%r14),%eax
cmp    %r15d,%r14d
mov    %eax,%r14d
jne    1260 <main+0xa0>
lea    0xd18(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1338 <main+0x178>
lea    0xd00(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1320 <main+0x160>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1350 <main+0x190>
lea    0xd0a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Numero ingresado = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [20 x i8] c"\0A~~~ GANASTE! ~~~\0A\0A\00"
@.str.4 = [20 x i8] c"\0A~~~ Perdiste ~~~\0A\0A\00"
@.str.5 = [28 x i8] c"\0A~~~ Intenta de nuevo ~~~\0A\0A\00"
@.str.6 = [16 x i8] c"El numero era: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @time(i32 0)
%9 = call i32 @srand(i32 %8)
%10 = call i32 (...) @elegirCantDigitos()
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i32* @malloc(i32 %14)
store i32* %15, i32** %2
%16 = load i32, i32* %4
%17 = call i32* @calloc(i32 %16, i32 4)
store i32* %17, i32** %3
%18 = load i32*, i32** %2
%19 = icmp eq i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %0
%21 = load i32*, i32** %3
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20, %0
store i32 0, i32* %1
br label %92
24: ; preds = %20
%25 = load i32*, i32** %2
%26 = load i32, i32* %4
%27 = call i32 @generaAleatorio(i32* %25, i32 %26)
%28 = call i32 @elegirNivel(i32 10)
store i32 %28, i32* %5
store i32 1, i32* %6
br label %29
29: ; preds = %71, %24
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %74
33: ; preds = %29
%34 = load i32*, i32** %3
%35 = load i32, i32* %4
%36 = call i32 @leerNumero(i32* %34, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %38
38: ; preds = %49, %33
%39 = load i32, i32* %7
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i32*, i32** %3
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %38
52: ; preds = %38
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32*, i32** %2
%55 = load i32*, i32** %3
%56 = load i32, i32* %4
%57 = call i64 @coincideNumero(i32* %54, i32* %55, i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %52
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %92
61: ; preds = %52
%62 = load i32, i32* %6
%63 = load i32, i32* %5
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %69
67: ; preds = %61
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %69
69: ; preds = %67, %65
br label %70
70: ; preds = %69
br label %71
71: ; preds = %70
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %6
br label %29
74: ; preds = %29
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %6
br label %76
76: ; preds = %87, %74
%77 = load i32, i32* %6
%78 = load i32, i32* %4
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %90
80: ; preds = %76
%81 = load i32*, i32** %2
%82 = load i32, i32* %6
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %81, i64 %83
%85 = load i32, i32* %84
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %80
%88 = load i32, i32* %6
%89 = add nsw i32 %88, 1
store i32 %89, i32* %6
br label %76
90: ; preds = %76
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %92
92: ; preds = %90, %59, %23
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
@.str = [20 x i8] c"Numero ingresado = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.6 = [16 x i8] c"El numero era: \00"
@str = [27 x i8] c"\0A~~~ Intenta de nuevo ~~~\0A\00"
@str.7 = [19 x i8] c"\0A~~~ Perdiste ~~~\0A\00"
@str.8 = [19 x i8] c"\0A~~~ GANASTE! ~~~\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32 0)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32 (...) @elegirCantDigitos()
%4 = shl i32 %3, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = tail call i32* @calloc(i32 %3, i32 4)
%7 = icmp eq i32* %5, null
%8 = icmp eq i32* %6, null
%9 = or i1 %7, %8
br i1 %9, label %54, label %10
10: ; preds = %0
%11 = tail call i32 @generaAleatorio(i32* %5, i32 %3)
%12 = tail call i32 @elegirNivel(i32 10)
%13 = icmp slt i32 %12, 1
br i1 %13, label %40, label %14
14: ; preds = %10
%15 = icmp sgt i32 %3, 0
%16 = zext i32 %3 to i64
br label %17
17: ; preds = %14, %34
%18 = phi i32 [ 1, %14 ], [ %38, %34 ]
%19 = tail call i32 @leerNumero(i32* %6, i32 %3)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br i1 %15, label %21, label %28
21: ; preds = %17, %21
%22 = phi i64 [ %26, %21 ], [ 0, %17 ]
%23 = getelementptr inbounds i32, i32* %6, i64 %22
%24 = load i32, i32* %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, %16
br i1 %27, label %28, label %21
28: ; preds = %21, %17
%29 = tail call i32 @putchar(i32 10)
%30 = tail call i64 @coincideNumero(i32* %5, i32* %6, i32 %3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
br label %54
34: ; preds = %28
%35 = icmp eq i32 %18, %12
%36 = select i1 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0)
%37 = tail call i32 @puts(i8* dereferenceable(1) %36)
%38 = add nuw i32 %18, 1
%39 = icmp eq i32 %18, %12
br i1 %39, label %40, label %17
40: ; preds = %34, %10
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%42 = icmp sgt i32 %3, 0
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = zext i32 %3 to i64
br label %45
45: ; preds = %43, %45
%46 = phi i64 [ 0, %43 ], [ %50, %45 ]
%47 = getelementptr inbounds i32, i32* %5, i64 %46
%48 = load i32, i32* %47
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = add nuw nsw i64 %46, 1
%51 = icmp eq i64 %50, %44
br i1 %51, label %52, label %45
52: ; preds = %45, %40
%53 = tail call i32 @putchar(i32 10)
br label %54
54: ; preds = %0, %52, %32
%55 = phi i32 [ 1, %32 ], [ 1, %52 ], [ 0, %0 ]
ret i32 %55
}