#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 rand();
int scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int a, b, x;
  srand(time(NULL));
  printf("Player A: ");
  if (scanf("%d%*[^\n]", &a) != 1) {
    return 1;
  }
  printf("Player B: ");
  if (scanf("%d%*[^\n]", &b) != 1) {
    return 1;
  }
  x = rand() % 10;
  a = a > x ? a - x : x - a;
  b = b > x ? b - x : x - b;
  printf("Secret Number is %d\n", x);
  if (a == b) {
    printf("Draw...\n");
  } else {
    printf("Player %c Win!\n", a < b ? 'A' : 'B');
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     11a2 <main+0x52>
movl   $0x1,-0x4(%rbp)
jmp    1293 <main+0x143>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe54(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     11d5 <main+0x85>
movl   $0x1,-0x4(%rbp)
jmp    1293 <main+0x143>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1201 <main+0xb1>
mov    -0x8(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    120a <main+0xba>
mov    -0x10(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    122a <main+0xda>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1233 <main+0xe3>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1269 <main+0x119>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128c <main+0x13c>
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%edx
mov    $0x42,%esi
mov    $0x41,%eax
cmp    %edx,%ecx
cmovl  %eax,%esi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    $0x1,%ebx
cmp    $0x1,%eax
jne    1256 <main+0xf6>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe56(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1256 <main+0xf6>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    0x8(%rsp),%eax
mov    %eax,%ecx
sub    %esi,%ecx
neg    %ecx
sub    %esi,%eax
cmovle %ecx,%eax
mov    0xc(%rsp),%ecx
mov    %ecx,%edx
sub    %esi,%edx
neg    %edx
sub    %esi,%ecx
cmovle %edx,%ecx
mov    %ecx,0xc(%rsp)
mov    %eax,0x8(%rsp)
lea    0xe03(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%eax
cmp    %eax,0xc(%rsp)
jne    123b <main+0xdb>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
jmp    1256 <main+0xf6>
setl   %al
movzbl %al,%eax
mov    $0x42,%esi
sub    %eax,%esi
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Player A: \00"
@.str.1 = [9 x i8] c"%d%*[^\0A]\00"
@.str.2 = [11 x i8] c"Player B: \00"
@.str.3 = [21 x i8] c"Secret Number is %d\0A\00"
@.str.4 = [9 x i8] c"Draw...\0A\00"
@.str.5 = [16 x i8] c"Player %c Win!\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 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 1, i32* %1
br label %60
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %1
br label %60
16: ; preds = %11
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 10
store i32 %18, i32* %4
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = icmp sgt i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* %2
%24 = load i32, i32* %4
%25 = sub nsw i32 %23, %24
br label %30
26: ; preds = %16
%27 = load i32, i32* %4
%28 = load i32, i32* %2
%29 = sub nsw i32 %27, %28
br label %30
30: ; preds = %26, %22
%31 = phi i32 [ %25, %22 ], [ %29, %26 ]
store i32 %31, i32* %2
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = sub nsw i32 %36, %37
br label %43
39: ; preds = %30
%40 = load i32, i32* %4
%41 = load i32, i32* %3
%42 = sub nsw i32 %40, %41
br label %43
43: ; preds = %39, %35
%44 = phi i32 [ %38, %35 ], [ %42, %39 ]
store i32 %44, i32* %3
%45 = load i32, i32* %4
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %2
%48 = load i32, i32* %3
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %59
52: ; preds = %43
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = icmp slt i32 %53, %54
%56 = zext i1 %55 to i64
%57 = select i1 %55, i32 65, i32 66
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %52, %50
store i32 0, i32* %1
br label %60
60: ; preds = %59, %15, %10
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [11 x i8] c"Player A: \00"
@.str.1 = [9 x i8] c"%d%*[^\0A]\00"
@.str.2 = [11 x i8] c"Player B: \00"
@.str.3 = [21 x i8] c"Secret Number is %d\0A\00"
@.str.5 = [16 x i8] c"Player %c Win!\0A\00"
@str = [8 x i8] c"Draw...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %37
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 10
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, %16
%19 = sub nsw i32 %17, %16
%20 = sub nsw i32 %16, %17
%21 = select i1 %18, i32 %19, i32 %20
store i32 %21, i32* %1
%22 = load i32, i32* %2
%23 = icmp sgt i32 %22, %16
%24 = sub nsw i32 %22, %16
%25 = sub nsw i32 %16, %22
%26 = select i1 %23, i32 %24, i32 %25
store i32 %26, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %14
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %37
33: ; preds = %14
%34 = icmp slt i32 %28, %29
%35 = select i1 %34, i32 65, i32 66
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31, %33, %10, %0
%38 = phi i32 [ 1, %0 ], [ 1, %10 ], [ 0, %33 ], [ 0, %31 ]
ret i32 %38
}