#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, ...);
int main() {
  int i, max, n, x, f[21], r, my_turn;
  f[1] = f[2] = 1;
  for (i = 3; i <= 20; i++)
    f[i] = f[i - 1] + f[i + 2];
  printf("Number of Stones? (2 ... 10000)?");
  scanf("%d", &n);
  if (n < 2 || n > 10000)
    return EXIT_FAILURE;
  for (my_turn = 1; n != 0; my_turn ^= 1) {
    printf("You can pick up to %d stones.\n", max);
    if (my_turn) {
      x = n;
      for (i = 20; x != f[i]; i--)
        if (x > f[i])
          x -= f[i];
      if (x > max)
        x = 1;
      printf("I'll take %d stones.\n", x);
    } else
      do {
        printf("How many stones will you take?");
        r = scanf("%d", &x);
        scanf("%*[^\n]");
      } while (r != 1 || x < 1 || x > max);
    n -= x;
    max = 2 * x;
    if (max > n)
      max = n;
    printf("You have %d stones remaining.\n", n);
  }
  if (my_turn)
    printf("Nooo, I lost. Looks like you won!\n");
  else
    printf("Heh, you lost... Loser.\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
movl   $0x1,-0x6c(%rbp)
movl   $0x3,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jg     117f <main+0x5f>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x70(%rbp,%rax,4),%ecx
mov    -0x8(%rbp),%eax
add    $0x2,%eax
cltq
add    -0x70(%rbp,%rax,4),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1147 <main+0x27>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x2,-0x10(%rbp)
jl     11b6 <main+0x96>
cmpl   $0x2710,-0x10(%rbp)
jle    11c7 <main+0xa7>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    135a <main+0x23a>
movl   $0x1,-0x78(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1323 <main+0x203>
mov    -0xc(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x78(%rbp)
je     126e <main+0x14e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x14,-0x8(%rbp)
mov    -0x14(%rbp),%eax
movslq -0x8(%rbp),%rcx
cmp    -0x70(%rbp,%rcx,4),%eax
je     1245 <main+0x125>
mov    -0x14(%rbp),%eax
movslq -0x8(%rbp),%rcx
cmp    -0x70(%rbp,%rcx,4),%eax
jle    1232 <main+0x112>
movslq -0x8(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1237 <main+0x117>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1200 <main+0xe0>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1258 <main+0x138>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12de <main+0x1be>
jmp    1273 <main+0x153>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd99(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    %eax,-0x74(%rbp)
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x74(%rbp)
mov    %al,-0x79(%rbp)
jne    12ce <main+0x1ae>
mov    $0x1,%al
cmpl   $0x1,-0x14(%rbp)
mov    %al,-0x79(%rbp)
jl     12ce <main+0x1ae>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
setg   %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    1273 <main+0x153>
jmp    12de <main+0x1be>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1304 <main+0x1e4>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%esi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%eax
xor    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11ce <main+0xae>
cmpl   $0x0,-0x78(%rbp)
je     1340 <main+0x220>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    134e <main+0x22e>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeeb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Number of Stones? (2 ... 10000)?\00"
@.str.1 = [3 x i8] c"%d\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [31 x i8] c"You can pick up to %d stones.\0A\00"
@.str.3 = [22 x i8] c"I'll take %d stones.\0A\00"
@.str.4 = [31 x i8] c"How many stones will you take?\00"
@.str.5 = [7 x i8] c"%*[^\0A]\00"
@.str.6 = [31 x i8] c"You have %d stones remaining.\0A\00"
@.str.7 = [35 x i8] c"Nooo, I lost. Looks like you won!\0A\00"
@.str.8 = [25 x i8] c"Heh, you lost... Loser.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [21 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 2
store i32 1, i32* %9
%10 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 1
store i32 1, i32* %10
store i32 3, i32* %2
br label %11
11: ; preds = %29, %0
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 20
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = load i32, i32* %2
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %19, %24
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %27
store i32 %25, i32* %28
br label %29
29: ; preds = %14
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %11
32: ; preds = %11
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 2
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 10000
br i1 %39, label %40, label %42
40: ; preds = %37, %32
%41 = load i32, i32* @EXIT_FAILURE
store i32 %41, i32* %1
br label %130
42: ; preds = %37
store i32 1, i32* %8
br label %43
43: ; preds = %118, %42
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %121
46: ; preds = %43
%47 = load i32, i32* %3
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %8
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %86
51: ; preds = %46
%52 = load i32, i32* %4
store i32 %52, i32* %5
store i32 20, i32* %2
br label %53
53: ; preds = %75, %51
%54 = load i32, i32* %5
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = icmp ne i32 %54, %58
br i1 %59, label %60, label %78
60: ; preds = %53
%61 = load i32, i32* %5
%62 = load i32, i32* %2
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = icmp sgt i32 %61, %65
br i1 %66, label %67, label %74
67: ; preds = %60
%68 = load i32, i32* %2
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = load i32, i32* %5
%73 = sub nsw i32 %72, %71
store i32 %73, i32* %5
br label %74
74: ; preds = %67, %60
br label %75
75: ; preds = %74
%76 = load i32, i32* %2
%77 = add nsw i32 %76, -1
store i32 %77, i32* %2
br label %53
78: ; preds = %53
%79 = load i32, i32* %5
%80 = load i32, i32* %3
%81 = icmp sgt i32 %79, %80
br i1 %81, label %82, label %83
82: ; preds = %78
store i32 1, i32* %5
br label %83
83: ; preds = %82, %78
%84 = load i32, i32* %5
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %84)
br label %104
86: ; preds = %46
br label %87
87: ; preds = %101, %86
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%89 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 %89, i32* %7
%90 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %91
91: ; preds = %87
%92 = load i32, i32* %7
%93 = icmp ne i32 %92, 1
br i1 %93, label %101, label %94
94: ; preds = %91
%95 = load i32, i32* %5
%96 = icmp slt i32 %95, 1
br i1 %96, label %101, label %97
97: ; preds = %94
%98 = load i32, i32* %5
%99 = load i32, i32* %3
%100 = icmp sgt i32 %98, %99
br label %101
101: ; preds = %97, %94, %91
%102 = phi i1 [ true, %94 ], [ true, %91 ], [ %100, %97 ]
br i1 %102, label %87, label %103
103: ; preds = %101
br label %104
104: ; preds = %103, %83
%105 = load i32, i32* %5
%106 = load i32, i32* %4
%107 = sub nsw i32 %106, %105
store i32 %107, i32* %4
%108 = load i32, i32* %5
%109 = mul nsw i32 2, %108
store i32 %109, i32* %3
%110 = load i32, i32* %3
%111 = load i32, i32* %4
%112 = icmp sgt i32 %110, %111
br i1 %112, label %113, label %115
113: ; preds = %104
%114 = load i32, i32* %4
store i32 %114, i32* %3
br label %115
115: ; preds = %113, %104
%116 = load i32, i32* %4
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %116)
br label %118
118: ; preds = %115
%119 = load i32, i32* %8
%120 = xor i32 %119, 1
store i32 %120, i32* %8
br label %43
121: ; preds = %43
%122 = load i32, i32* %8
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %126
124: ; preds = %121
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
br label %128
126: ; preds = %121
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %128
128: ; preds = %126, %124
%129 = load i32, i32* @EXIT_SUCCESS
store i32 %129, i32* %1
br label %130
130: ; preds = %128, %40
%131 = load i32, i32* %1
ret i32 %131
}

LLVM IR (-O2):
@.str = [33 x i8] c"Number of Stones? (2 ... 10000)?\00"
@.str.1 = [3 x i8] c"%d\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add i32 %5, -10001
%7 = icmp ult i32 %6, -9999
%8 = load i32, i32* @EXIT_FAILURE
ret i32 %8
}