#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 */
long long calculateWinner(long long, long long *, long long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long long *);
int main() {
  long long int starting_player;
  printf("Enter starting player:\n");
  scanf("%lld", &starting_player);
  long long int no_of_piles;
  printf("Enter number of piles:\n");
  scanf("%lld", &no_of_piles);
  printf("Enter number of stones in each pile:\n");
  long long int piles[no_of_piles], i;
  for (i = 0; i < no_of_piles; i++)
    scanf("%lld", &piles[i]);
  long long int ans = calculateWinner(starting_player, piles, no_of_piles);
  printf("Player %lld will win.", ans);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x41(%rbp)
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
mov    %rdi,-0x50(%rbp)
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x41(%rbp),%al
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x50(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x41(%rbp),%al
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11f9 <main+0xc9>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe35(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bf <main+0x8f>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
call   1040 <calculateWinner@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rbx
lea    -0x38(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r12
mov    -0x30(%rbp),%rax
mov    %rsp,%r14
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x30(%rbp),%rdx
test   %rdx,%rdx
jle    11ec <main+0xac>
xor    %r13d,%r13d
lea    0xe3d(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r13
mov    -0x30(%rbp),%rdx
add    $0x8,%rbx
cmp    %rdx,%r13
jl     11d0 <main+0x90>
mov    -0x38(%rbp),%rdi
mov    %r14,%rsi
call   1050 <calculateWinner@plt>
lea    0xe06(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter starting player:\0A\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [24 x i8] c"Enter number of piles:\0A\00"
@.str.3 = [38 x i8] c"Enter number of stones in each pile:\0A\00"
@.str.4 = [22 x i8] c"Player %lld will win.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%13 = load i64, i64* %3
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %4
%15 = alloca i64, i64 %13
store i64 %13, i64* %5
store i64 0, i64* %6
br label %16
16: ; preds = %24, %0
%17 = load i64, i64* %6
%18 = load i64, i64* %3
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i64, i64* %6
%22 = getelementptr inbounds i64, i64* %15, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %22)
br label %24
24: ; preds = %20
%25 = load i64, i64* %6
%26 = add nsw i64 %25, 1
store i64 %26, i64* %6
br label %16
27: ; preds = %16
%28 = load i64, i64* %2
%29 = load i64, i64* %3
%30 = call i64 @calculateWinner(i64 %28, i64* %15, i64 %29)
store i64 %30, i64* %7
%31 = load i64, i64* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i64 %31)
%33 = load i8*, i8** %4
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%lld\00"
@.str.4 = [22 x i8] c"Player %lld will win.\00"
@str = [23 x i8] c"Enter starting player:\00"
@str.5 = [23 x i8] c"Enter number of piles:\00"
@str.6 = [37 x i8] c"Enter number of stones in each pile:\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%6 = bitcast i64* %2 to i8*
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
%10 = load i64, i64* %2
%11 = call i8* @llvm.stacksave()
%12 = alloca i64, i64 %10
%13 = load i64, i64* %2
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %0, %15
%16 = phi i64 [ %19, %15 ], [ 0, %0 ]
%17 = getelementptr inbounds i64, i64* %12, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i64, i64* %2
%21 = icmp slt i64 %19, %20
br i1 %21, label %15, label %22
22: ; preds = %15, %0
%23 = phi i64 [ %13, %0 ], [ %20, %15 ]
%24 = load i64, i64* %1
%25 = call i64 @calculateWinner(i64 %24, i64* %12, i64 %23)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i64 %25)
ret i32 0
}