#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ sqlite3;
typedef scalar_t__ clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
float CLOCKS_PER_SEC;
long atol(char *);
scalar_t__ clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ file_exists(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ i_large_handle_position_over_in_iteration_minus_one(
    long, short, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, short);
int /*<<< orphan*/ stdout;
void iterationLarge(short iteration, sqlite3 *db) {
  long position;
  long input_count = 0;
  long result_count = 0;
  char input_file_name[30];
  sprintf(input_file_name, "moves.iteration%.2hi.txt", iteration - 1);
  if (!file_exists(input_file_name)) {
    printf("Input file %s does not exist!\n", input_file_name);
    return;
  }
  FILE *input_file = fopen(input_file_name, "r");
  FILE *fp = fopen("moves.1.txt", "w");
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  clock_t t0 = clock();
  while ((read = getline(&line, &len, input_file)) != -1) {
    position = atol(line);
    result_count += i_large_handle_position_over_in_iteration_minus_one(
        position, iteration, fp, db);
    input_count++;
    if (input_count % 1000 == 0) {
      printf("Processed %ld positions\r", input_count);
      fflush(stdout);
    }
  }
  printf("Processed %ld positions\n", input_count);
  fclose(input_file);
  fclose(fp);
  clock_t t = clock() - t0;
  printf("Found %ld results in %f seconds.\n", result_count,
         ((float)t) / CLOCKS_PER_SEC);
}


x86 assembly (clang, -O0):
<iterationLarge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
movswl -0x2(%rbp),%eax
sub    $0x1,%eax
lea    0xe28(%rip),%rsi
movswl %ax,%edx
call   10c0 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%eax
jne    1209 <iterationLarge+0x69>
lea    -0x50(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1342 <iterationLarge+0x1a2>
lea    -0x50(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x58(%rbp)
lea    0xe16(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x80(%rbp)
mov    -0x58(%rbp),%rdx
lea    -0x68(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10b0 <getline@plt>
mov    %eax,-0x74(%rbp)
cmp    $0xffffffff,%eax
je     12e2 <iterationLarge+0x142>
mov    -0x68(%rbp),%rdi
call   1090 <atol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2(%rbp),%ax
mov    -0x60(%rbp),%rdx
mov    -0x10(%rbp),%rcx
movswl %ax,%esi
call   1070 <i_large_handle_position_over_in_iteration_minus_one@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    12dd <iterationLarge+0x13d>
mov    -0x20(%rbp),%rsi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    124f <iterationLarge+0xaf>
mov    -0x20(%rbp),%rsi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x60(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x28(%rbp),%rsi
cvtsi2ssq -0x88(%rbp),%xmm0
ff ff
mov    0x2cbc(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd3f(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterationLarge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,0x38(%rsp)
mov    %edi,%r14d
lea    -0x1(%r14),%eax
movswl %ax,%edx
lea    0xe3c(%rip),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %eax,%eax
je     130a <iterationLarge+0x16a>
lea    0xe50(%rip),%rsi
lea    0x40(%rsp),%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
lea    0xe3e(%rip),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,0x18(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x28(%rsp)
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,0x30(%rsp)
lea    0x8(%rsp),%rdi
lea    0x28(%rsp),%rsi
mov    %rbp,0x20(%rsp)
mov    %rbp,%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     131f <iterationLarge+0x17f>
mov    $0x1,%r12d
movswl %r14w,%eax
mov    %eax,0x14(%rsp)
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1294 <iterationLarge+0xf4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r14,%rbx
lea    0x8(%rsp),%rdi
lea    0x28(%rsp),%rsi
mov    0x20(%rsp),%rdx
call   10b0 <getline@plt>
add    $0x1,%r12
cmp    $0xffffffff,%eax
je     1322 <iterationLarge+0x182>
mov    %r15,%r13
mov    %r12,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%rbp
add    $0xffffffffffffffff,%rbp
mov    0x8(%rsp),%rdi
call   1090 <atol@plt>
mov    %rax,%rdi
mov    0x14(%rsp),%esi
mov    0x18(%rsp),%rdx
mov    0x38(%rsp),%rcx
call   1070 <i_large_handle_position_over_in_iteration_minus_one@plt>
mov    %rax,%r14
add    $0x1,%r15
cmp    %r13,%rbp
jne    1270 <iterationLarge+0xd0>
lea    0xd5b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    1270 <iterationLarge+0xd0>
lea    0xd08(%rip),%rdi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1378 <iterationLarge+0x1d8>
xor    %r15d,%r15d
lea    0xd38(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rsp),%rdi
call   1050 <fclose@plt>
mov    0x18(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    0x30(%rsp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2c89(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd0c(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"moves.iteration%.2hi.txt\00"
@.str.1 = [31 x i8] c"Input file %s does not exist!\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"moves.1.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"Processed %ld positions\0D\00"
@stdout = global i32 0
@.str.6 = [25 x i8] c"Processed %ld positions\0A\00"
@.str.7 = [34 x i8] c"Found %ld results in %f seconds.\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
define void @iterationLarge(i16 signext %0, i32* %1) {
%3 = alloca i16
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca [30 x i8]
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
store i16 %0, i16* %3
store i32* %1, i32** %4
store i64 0, i64* %6
store i64 0, i64* %7
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%17 = load i16, i16* %3
%18 = sext i16 %17 to i32
%19 = sub nsw i32 %18, 1
%20 = trunc i32 %19 to i16
%21 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i16 signext %20)
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%23 = call i32 @file_exists(i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %2
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %75
28: ; preds = %2
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %9
%31 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %31, i32** %10
store i8* null, i8** %11
store i64 0, i64* %12
%32 = call i64 (...) @clock()
store i64 %32, i64* %14
br label %33
33: ; preds = %57, %28
%34 = load i32*, i32** %9
%35 = call i32 @getline(i8** %11, i64* %12, i32* %34)
store i32 %35, i32* %13
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %58
37: ; preds = %33
%38 = load i8*, i8** %11
%39 = call i64 @atol(i8* %38)
store i64 %39, i64* %5
%40 = load i64, i64* %5
%41 = load i16, i16* %3
%42 = load i32*, i32** %10
%43 = load i32*, i32** %4
%44 = call i64 @i_large_handle_position_over_in_iteration_minus_one(i64 %40, i16 signext %41, i32* %42, i32* %43)
%45 = load i64, i64* %7
%46 = add nsw i64 %45, %44
store i64 %46, i64* %7
%47 = load i64, i64* %6
%48 = add nsw i64 %47, 1
store i64 %48, i64* %6
%49 = load i64, i64* %6
%50 = srem i64 %49, 1000
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %37
%53 = load i64, i64* %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i64 %53)
%55 = load i32, i32* @stdout
%56 = call i32 @fflush(i32 %55)
br label %57
57: ; preds = %52, %37
br label %33
58: ; preds = %33
%59 = load i64, i64* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i64 %59)
%61 = load i32*, i32** %9
%62 = call i32 @fclose(i32* %61)
%63 = load i32*, i32** %10
%64 = call i32 @fclose(i32* %63)
%65 = call i64 (...) @clock()
%66 = load i64, i64* %14
%67 = sub nsw i64 %65, %66
store i64 %67, i64* %15
%68 = load i64, i64* %7
%69 = load i64, i64* %15
%70 = sitofp i64 %69 to float
%71 = load float, float* @CLOCKS_PER_SEC
%72 = fdiv float %70, %71
%73 = fpext float %72 to double
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i64 %68, double %73)
br label %75
75: ; preds = %58, %25
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"moves.iteration%.2hi.txt\00"
@.str.1 = [31 x i8] c"Input file %s does not exist!\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"moves.1.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"Processed %ld positions\0D\00"
@stdout = global i32 0
@.str.6 = [25 x i8] c"Processed %ld positions\0A\00"
@.str.7 = [34 x i8] c"Found %ld results in %f seconds.\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
define void @iterationLarge(i16 signext %0, i32* %1) {
%3 = alloca [30 x i8]
%4 = alloca i8*
%5 = alloca i64
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = add i16 %0, -1
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i16 signext %7)
%9 = call i32 @file_exists(i8* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %51
13: ; preds = %2
%14 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%17 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%18 = call i64 (...) @clock()
%19 = call i32 @getline(i8** %4, i64* %5, i32* %14)
%20 = icmp eq i32 %19, -1
br i1 %20, label %38, label %21
21: ; preds = %13, %35
%22 = phi i64 [ %28, %35 ], [ 0, %13 ]
%23 = phi i64 [ %27, %35 ], [ 0, %13 ]
%24 = load i8*, i8** %4
%25 = call i64 @atol(i8* %24)
%26 = call i64 @i_large_handle_position_over_in_iteration_minus_one(i64 %25, i16 signext %0, i32* %15, i32* %1)
%27 = add nsw i64 %26, %23
%28 = add nuw nsw i64 %22, 1
%29 = urem i64 %28, 1000
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %21
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i64 %28)
%33 = load i32, i32* @stdout
%34 = call i32 @fflush(i32 %33)
br label %35
35: ; preds = %31, %21
%36 = call i32 @getline(i8** %4, i64* %5, i32* %14)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %21
38: ; preds = %35, %13
%39 = phi i64 [ 0, %13 ], [ %27, %35 ]
%40 = phi i64 [ 0, %13 ], [ %28, %35 ]
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i64 %40)
%42 = call i32 @fclose(i32* %14)
%43 = call i32 @fclose(i32* %15)
%44 = call i64 (...) @clock()
%45 = sub nsw i64 %44, %18
%46 = sitofp i64 %45 to float
%47 = load float, float* @CLOCKS_PER_SEC
%48 = fdiv float %46, %47
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i64 %39, double %49)
br label %51
51: ; preds = %38, %11
ret void
}