#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*/ free(long *);
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, long *);
int /*<<< orphan*/ win_pos(long);
int main(void) {
  long t, *a, i;
  scanf("%ld", &t);
  a = (long *)malloc(t * sizeof(long));
  for (i = 0; i < t; i++) {
    scanf("%ld", &a[i]);
  }
  for (i = 0; i < t; i++) {
    printf("%ld\n", win_pos(a[i]));
  }
  free(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11c2 <main+0x72>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe54(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1188 <main+0x38>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1208 <main+0xb8>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <win_pos@plt>
mov    %eax,%esi
lea    0xe12(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ca <main+0x7a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
cmpq   $0x0,(%rsp)
jle    11dd <main+0x8d>
xor    %r12d,%r12d
lea    0xe78(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r12
mov    (%rsp),%rax
add    $0x8,%rbx
cmp    %rax,%r12
jl     1190 <main+0x40>
test   %rax,%rax
jle    11dd <main+0x8d>
xor    %ebx,%ebx
lea    0xe4a(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1040 <win_pos@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    (%rsp),%rbx
jl     11c0 <main+0x70>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64*
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %2)
%6 = load i64, i64* %2
%7 = mul i64 %6, 8
%8 = call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i64*
store i64* %9, i64** %3
store i64 0, i64* %4
br label %10
10: ; preds = %19, %0
%11 = load i64, i64* %4
%12 = load i64, i64* %2
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i64*, i64** %3
%16 = load i64, i64* %4
%17 = getelementptr inbounds i64, i64* %15, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %17)
br label %19
19: ; preds = %14
%20 = load i64, i64* %4
%21 = add nsw i64 %20, 1
store i64 %21, i64* %4
br label %10
22: ; preds = %10
store i64 0, i64* %4
br label %23
23: ; preds = %34, %22
%24 = load i64, i64* %4
%25 = load i64, i64* %2
%26 = icmp slt i64 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i64*, i64** %3
%29 = load i64, i64* %4
%30 = getelementptr inbounds i64, i64* %28, i64 %29
%31 = load i64, i64* %30
%32 = call i32 @win_pos(i64 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %27
%35 = load i64, i64* %4
%36 = add nsw i64 %35, 1
store i64 %36, i64* %4
br label %23
37: ; preds = %23
%38 = load i64*, i64** %3
%39 = call i32 @free(i64* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = load i64, i64* %1
%5 = shl i64 %4, 3
%6 = call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i64*
%8 = load i64, i64* %1
%9 = icmp sgt i64 %8, 0
br i1 %9, label %12, label %28
10: ; preds = %12
%11 = icmp sgt i64 %17, 0
br i1 %11, label %19, label %28
12: ; preds = %0, %12
%13 = phi i64 [ %16, %12 ], [ 0, %0 ]
%14 = getelementptr inbounds i64, i64* %7, i64 %13
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i64, i64* %1
%18 = icmp slt i64 %16, %17
br i1 %18, label %12, label %10
19: ; preds = %10, %19
%20 = phi i64 [ %25, %19 ], [ 0, %10 ]
%21 = getelementptr inbounds i64, i64* %7, i64 %20
%22 = load i64, i64* %21
%23 = call i32 @win_pos(i64 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %20, 1
%26 = load i64, i64* %1
%27 = icmp slt i64 %25, %26
br i1 %27, label %19, label %28
28: ; preds = %19, %0, %10
%29 = call i32 @free(i64* %7)
ret i32 0
}