#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 /*<<< orphan*/ scanf(char *, int *);
int getChoosing(int turn, int sticks) {
  int choosing = 0, limit;
  if (turn == 0) {
    printf("\n users turn :\n");
    scanf("%d", &choosing);
  } else {
    printf("\ncomputer's turn");
    if (sticks >= 9)
      limit = 9;
    else if (sticks >= 5)
      limit = 5;
    else
      limit = 1;
    if ((sticks - limit) <= 3) {
      if (sticks - limit != 0)
        choosing = sticks - limit;
      else
        choosing = ((rand()) % 3) + 1;
    } else
      choosing = 3;
    printf("\ncomputer chose %d\n", choosing);
  }
  return (choosing);
}


x86 assembly (clang, -O0):
<getChoosing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1172 <getChoosing+0x42>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1216 <getChoosing+0xe6>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x9,-0x8(%rbp)
jl     1196 <getChoosing+0x66>
movl   $0x9,-0x10(%rbp)
jmp    11b8 <getChoosing+0x88>
cmpl   $0x5,-0x8(%rbp)
jl     11ac <getChoosing+0x7c>
movl   $0x5,-0x10(%rbp)
jmp    11b3 <getChoosing+0x83>
movl   $0x1,-0x10(%rbp)
jmp    11b8 <getChoosing+0x88>
mov    -0x8(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x3,%eax
jg     11fe <getChoosing+0xce>
mov    -0x8(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x0,%eax
je     11e4 <getChoosing+0xb4>
mov    -0x8(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11f9 <getChoosing+0xc9>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
jmp    1205 <getChoosing+0xd5>
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getChoosing>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
test   %edi,%edi
je     11c6 <getChoosing+0x86>
mov    %esi,%ebx
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ecx,%ecx
cmp    $0x5,%ebx
setl   %cl
shl    $0x2,%ecx
or     $0xfffffffb,%ecx
cmp    $0x9,%ebx
mov    $0xfffffff7,%eax
cmovl  %ecx,%eax
add    %ebx,%eax
mov    $0x3,%ebx
cmp    $0x3,%eax
jg     11b4 <getChoosing+0x74>
mov    %eax,%ebx
test   %eax,%eax
jne    11b4 <getChoosing+0x74>
xor    %eax,%eax
call   1060 <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),%ebx
add    $0x1,%ebx
lea    0xe59(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e7 <getChoosing+0xa7>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe27(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"\0A users turn :\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"\0Acomputer's turn\00"
@.str.3 = [20 x i8] c"\0Acomputer chose %d\0A\00"
define i32 @getChoosing(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %46
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 9
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 9, i32* %6
br label %23
17: ; preds = %12
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 5
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 5, i32* %6
br label %22
21: ; preds = %17
store i32 1, i32* %6
br label %22
22: ; preds = %21, %20
br label %23
23: ; preds = %22, %16
%24 = load i32, i32* %4
%25 = load i32, i32* %6
%26 = sub nsw i32 %24, %25
%27 = icmp sle i32 %26, 3
br i1 %27, label %28, label %42
28: ; preds = %23
%29 = load i32, i32* %4
%30 = load i32, i32* %6
%31 = sub nsw i32 %29, %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* %4
%35 = load i32, i32* %6
%36 = sub nsw i32 %34, %35
store i32 %36, i32* %5
br label %41
37: ; preds = %28
%38 = call i32 (...) @rand()
%39 = srem i32 %38, 3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %41
41: ; preds = %37, %33
br label %43
42: ; preds = %23
store i32 3, i32* %5
br label %43
43: ; preds = %42, %41
%44 = load i32, i32* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %43, %9
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"\0Acomputer's turn\00"
@.str.3 = [20 x i8] c"\0Acomputer chose %d\0A\00"
@str = [15 x i8] c"\0A users turn :\00"
define i32 @getChoosing(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
br label %27
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp sgt i32 %1, 8
%13 = icmp sgt i32 %1, 4
%14 = select i1 %13, i32 -5, i32 -1
%15 = select i1 %12, i32 -9, i32 %14
%16 = add i32 %15, %1
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %10
%19 = icmp eq i32 %16, 0
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, 3
%23 = add nsw i32 %22, 1
br label %24
24: ; preds = %10, %18, %20
%25 = phi i32 [ %23, %20 ], [ %16, %18 ], [ 3, %10 ]
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %6
%28 = phi i32 [ %25, %24 ], [ %9, %6 ]
ret i32 %28
}