#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*/ cleanStdin();
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t);
int /*<<< orphan*/ insert(char **, size_t, int, char);
int scanf(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int playerChoice(char **matrix, size_t nbLines, size_t nbCol, char player) {
  int ret, x;
  do {
    fprintf(stdout, "Player %c, where do you want to play?\nColumn: ", player);
    fflush(stdout);
    ret = scanf("%d", &x);
    cleanStdin();
    if (ret != 1) {
      fprintf(stderr, "You must choose column between 1 and %zu\n", nbCol);
      continue;
    }
  } while (x < 1 || x > nbCol || !insert(matrix, nbLines, x - 1, player));
  return x;
}


x86 assembly (clang, -O0):
<playerChoice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
movsbq -0x19(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xe97(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <cleanStdin@plt>
cmpl   $0x1,-0x20(%rbp)
je     11d3 <playerChoice+0x83>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11d8 <playerChoice+0x88>
jmp    11d8 <playerChoice+0x88>
mov    $0x1,%al
cmpl   $0x1,-0x24(%rbp)
mov    %al,-0x25(%rbp)
jl     121c <playerChoice+0xcc>
movslq -0x24(%rbp),%rcx
mov    $0x1,%al
cmp    -0x18(%rbp),%rcx
mov    %al,-0x25(%rbp)
ja     121c <playerChoice+0xcc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
movsbl -0x19(%rbp),%ecx
call   1060 <insert@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1169 <playerChoice+0x19>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<playerChoice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
movslq %ecx,%r12
mov    0x2e63(%rip),%rbp
lea    0x4(%rsp),%r14
movsbl %cl,%r15d
xchg   %ax,%ax
mov    0x0(%rbp),%edi
lea    0xe76(%rip),%rsi
mov    %r12,%rdx
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1040 <fflush@plt>
lea    0xe8e(%rip),%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1070 <cleanStdin@plt>
cmp    $0x1,%r13d
je     11d1 <playerChoice+0x81>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
movslq 0x4(%rsp),%rdx
test   %rdx,%rdx
jle    1180 <playerChoice+0x30>
cmp    %rbx,%rdx
ja     1180 <playerChoice+0x30>
add    $0xffffffff,%edx
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %r15d,%ecx
call   1060 <insert@plt>
test   %eax,%eax
je     1180 <playerChoice+0x30>
mov    0x4(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [47 x i8] c"Player %c, where do you want to play?\0AColumn: \00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"You must choose column between 1 and %zu\0A\00"
define i32 @playerChoice(i8** %0, i64 %1, i64 %2, i8 signext %3) {
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i8 %3, i8* %8
br label %11
11: ; preds = %44, %4
%12 = load i32, i32* @stdout
%13 = load i8, i8* %8
%14 = sext i8 %13 to i64
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
store i32 %18, i32* %9
%19 = call i32 (...) @cleanStdin()
%20 = load i32, i32* %9
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %11
%23 = load i32, i32* @stderr
%24 = load i64, i64* %7
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 %24)
br label %27
26: ; preds = %11
br label %27
27: ; preds = %26, %22
%28 = load i32, i32* %10
%29 = icmp slt i32 %28, 1
br i1 %29, label %44, label %30
30: ; preds = %27
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = load i64, i64* %7
%34 = icmp ugt i64 %32, %33
br i1 %34, label %44, label %35
35: ; preds = %30
%36 = load i8**, i8*** %5
%37 = load i64, i64* %6
%38 = load i32, i32* %10
%39 = sub nsw i32 %38, 1
%40 = load i8, i8* %8
%41 = call i32 @insert(i8** %36, i64 %37, i32 %39, i8 signext %40)
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
br label %44
44: ; preds = %35, %30, %27
%45 = phi i1 [ true, %30 ], [ true, %27 ], [ %43, %35 ]
br i1 %45, label %11, label %46
46: ; preds = %44
%47 = load i32, i32* %10
ret i32 %47
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [47 x i8] c"Player %c, where do you want to play?\0AColumn: \00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"You must choose column between 1 and %zu\0A\00"
define i32 @playerChoice(i8** %0, i64 %1, i64 %2, i8 signext %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = sext i8 %3 to i64
br label %8
8: ; preds = %29, %4
%9 = load i32, i32* @stdout
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 %7)
%11 = load i32, i32* @stdout
%12 = call i32 @fflush(i32 %11)
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%14 = call i32 (...) @cleanStdin()
%15 = icmp eq i32 %13, 1
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 %2)
br label %19
19: ; preds = %8, %16
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 1
%22 = sext i32 %20 to i64
%23 = icmp ugt i64 %22, %2
%24 = or i1 %21, %23
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = add nsw i32 %20, -1
%27 = call i32 @insert(i8** %0, i64 %1, i32 %26, i8 signext %3)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25, %19
br label %8
30: ; preds = %25
%31 = load i32, i32* %5
ret i32 %31
}