#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int position, x;
  srand(time(NULL));
  while (x != 0) {
    position = rand() % 3 + 1;
    printf("gioco delle 3 carte\n\n");
    printf("indovina dove si trova la carta vincente ([0] per uscire)\n");
    printf("indica il tuo numero vincente [1] [2] [3] -> ");
    scanf("%d", &x);
    if (x == position) {
      printf("hai indovinato!\n");
      getchar();
    } else if (x == 0) {
      break;
    } else {
      printf("hai perso, la carta vincente era la %d\n", position);
      getchar();
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
cmpl   $0x0,-0x18(%rbp)
je     1236 <main+0xd6>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1205 <main+0xa5>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
jmp    1231 <main+0xd1>
cmpl   $0x0,-0x18(%rbp)
jne    1214 <main+0xb4>
jmp    1236 <main+0xd6>
mov    -0x14(%rbp),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
jmp    1231 <main+0xd1>
jmp    1186 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xec9(%rip),%r14
lea    0xed7(%rip),%r15
lea    0xe62(%rip),%r12
lea    0xe89(%rip),%r13
lea    0x4(%rsp),%rbx
jmp    11ca <main+0x5a>
nopl   0x0(%rax)
lea    0xef1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmpl   $0x0,0x4(%rsp)
je     1235 <main+0xc5>
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebp,%eax
je     11b0 <main+0x40>
test   %eax,%eax
je     1235 <main+0xc5>
lea    0xe07(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bc <main+0x4c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"gioco delle 3 carte\0A\0A\00"
@.str.1 = [59 x i8] c"indovina dove si trova la carta vincente ([0] per uscire)\0A\00"
@.str.2 = [46 x i8] c"indica il tuo numero vincente [1] [2] [3] -> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [17 x i8] c"hai indovinato!\0A\00"
@.str.5 = [40 x i8] c"hai perso, la carta vincente era la %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
br label %10
10: ; preds = %36, %2
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 (...) @getchar()
br label %36
27: ; preds = %13
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
br label %37
31: ; preds = %27
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = call i32 (...) @getchar()
br label %35
35: ; preds = %31
br label %36
36: ; preds = %35, %24
br label %10
37: ; preds = %30, %10
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [46 x i8] c"indica il tuo numero vincente [1] [2] [3] -> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [40 x i8] c"hai perso, la carta vincente era la %d\0A\00"
@str = [21 x i8] c"gioco delle 3 carte\0A\00"
@str.6 = [58 x i8] c"indovina dove si trova la carta vincente ([0] per uscire)\00"
@str.7 = [16 x i8] c"hai indovinato!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
br label %7
7: ; preds = %2, %23
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 3
%10 = add nsw i32 %9, 1
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.6, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, %10
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %23
19: ; preds = %7
%20 = icmp eq i32 %15, 0
br i1 %20, label %27, label %21
21: ; preds = %19
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %10)
br label %23
23: ; preds = %21, %17
%24 = call i32 (...) @getchar()
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %7
27: ; preds = %23, %19
ret i32 0
}