#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 /*<<< orphan*/ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  FILE *scores;
  int s[10] = {1000, 990, 985, 984, 944, 932, 931, 929, 928, 927};
  int x;
  time_t then;
  scores = fopen("scores.dat", "w");
  if (scores == NULL) {
    puts("Error creating file");
    return 1;
  }
  for (x = 0; x < 10; x++)
    fprintf(scores, "%d\n", s[x]);
  fclose(scores);
  time(&then);
  while (difftime(time(NULL), then) < 1.3)
    ;
  puts("...");
  then = time(NULL);
  while (difftime(time(NULL), then) < 1.3)
    ;
  puts("High score saved to disk!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
lea    0xe9d(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ce <main+0x5e>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x12c>
movl   $0x0,-0x44(%rbp)
cmpl   $0xa,-0x44(%rbp)
jge    1205 <main+0x95>
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
lea    0xe67(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11d5 <main+0x65>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x48(%rbp),%rdi
call   1080 <time@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
mov    -0x48(%rbp),%esi
call   1050 <difftime@plt>
movaps %xmm0,%xmm1
movsd  0xdcb(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1244 <main+0xd4>
jmp    1217 <main+0xa7>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x48(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
mov    -0x48(%rbp),%esi
call   1050 <difftime@plt>
movaps %xmm0,%xmm1
movsd  0xd86(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1289 <main+0x119>
jmp    125c <main+0xec>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe9d(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12b0 <main+0x150>
mov    %rax,%rbx
lea    0xe9f(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3de,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3d9,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3d8,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3b0,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3a4,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3a3,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3a1,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3a0,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x39f,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0x4(%rsp),%rdi
call   1070 <time@plt>
nopl   0x0(%rax)
xor    %edi,%edi
call   1070 <time@plt>
mov    0x4(%rsp),%esi
mov    %eax,%edi
call   1050 <difftime@plt>
movsd  0xda6(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1240 <main+0xe0>
lea    0xdc6(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x4(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1070 <time@plt>
mov    0x4(%rsp),%esi
mov    %eax,%edi
call   1050 <difftime@plt>
movsd  0xd66(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1280 <main+0x120>
lea    0xd8a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    12c1 <main+0x161>
lea    0xd5e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.s = [10 x i32] [i32 1000, i32 990, i32 985, i32 984, i32 944, i32 932, i32 931, i32 929, i32 928, i32 927]
@.str = [11 x i8] c"scores.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [20 x i8] c"Error creating file\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [4 x i8] c"...\00"
@.str.5 = [27 x i8] c"High score saved to disk!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [10 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [10 x i32]* %3 to i8*
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %47
12: ; preds = %0
store i32 0, i32* %4
br label %13
13: ; preds = %23, %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 10
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32*, i32** %2
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %13
26: ; preds = %13
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
%29 = call i32 @time(i32* %5)
br label %30
30: ; preds = %35, %26
%31 = call i32 @time(i32* null)
%32 = load i32, i32* %5
%33 = call double @difftime(i32 %31, i32 %32)
%34 = fcmp olt double %33, 1.300000e+00
br i1 %34, label %35, label %36
35: ; preds = %30
br label %30
36: ; preds = %30
%37 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @time(i32* null)
store i32 %38, i32* %5
br label %39
39: ; preds = %44, %36
%40 = call i32 @time(i32* null)
%41 = load i32, i32* %5
%42 = call double @difftime(i32 %40, i32 %41)
%43 = fcmp olt double %42, 1.300000e+00
br i1 %43, label %44, label %45
44: ; preds = %39
br label %39
45: ; preds = %39
%46 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %47
47: ; preds = %45, %10
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [11 x i8] c"scores.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [20 x i8] c"Error creating file\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [4 x i8] c"...\00"
@.str.5 = [27 x i8] c"High score saved to disk!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %18, label %5
5: ; preds = %0
%6 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 1000)
%7 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 990)
%8 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 985)
%9 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 984)
%10 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 944)
%11 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 932)
%12 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 931)
%13 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 929)
%14 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 928)
%15 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 927)
%16 = tail call i32 @fclose(i32* %3)
%17 = call i32 @time(i32* %1)
br label %20
18: ; preds = %0
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %35
20: ; preds = %20, %5
%21 = call i32 @time(i32* null)
%22 = load i32, i32* %1
%23 = call double @difftime(i32 %21, i32 %22)
%24 = fcmp olt double %23, 1.300000e+00
br i1 %24, label %20, label %25
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @time(i32* null)
store i32 %27, i32* %1
br label %28
28: ; preds = %28, %25
%29 = call i32 @time(i32* null)
%30 = load i32, i32* %1
%31 = call double @difftime(i32 %29, i32 %30)
%32 = fcmp olt double %31, 1.300000e+00
br i1 %32, label %28, label %33
33: ; preds = %28
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33, %18
%36 = phi i32 [ 1, %18 ], [ 0, %33 ]
ret i32 %36
}