#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ sleep(int);
int stat(char *, struct stat *);
int main() {
  int i;
  char lbuf_kc9lhw[600], lbuf_wb9sky[600];
  FILE *fp_kc9lhw_i, *fp_wb9sky_i, *fp_kc9lhw_o, *fp_wb9sky_o;
  struct stat sb;
  if (stat("lockfaketrack", &sb) == -1) {
    rename("unlockfaketrack", "lockfaketrack");
    fp_kc9lhw_i = fopen("kc9lhwtrack.txt_old", "r");
    fp_wb9sky_i = fopen("wb9skytrack.txt_old", "r");
    fp_kc9lhw_o = fopen("kc9lhwtrack.txt", "w");
    fp_wb9sky_o = fopen("wb9skytrack.txt", "w");
    for (i = 0; i < 143; i++) {
      fgets(lbuf_kc9lhw, 500, fp_kc9lhw_i);
      fgets(lbuf_wb9sky, 500, fp_wb9sky_i);
      if (i > 20)
        sleep(4);
      fputs(lbuf_kc9lhw, fp_kc9lhw_o);
      fputs(lbuf_wb9sky, fp_wb9sky_o);
      fflush(fp_kc9lhw_o);
      fflush(fp_wb9sky_o);
    }
    fclose(fp_kc9lhw_i);
    fclose(fp_wb9sky_i);
    fclose(fp_kc9lhw_o);
    fclose(fp_wb9sky_o);
    rename("lockfaketrack", "unlockfaketrack");
  } else {
    printf("fake_track already running\n");
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe59(%rip),%rdi
lea    -0x4e8(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    1325 <main+0x195>
lea    0xe3b(%rip),%rdi
lea    0xe36(%rip),%rsi
call   10a0 <rename@plt>
lea    0xe38(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x4c8(%rbp)
lea    0xe34(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x4d0(%rbp)
lea    0xe2e(%rip),%rdi
lea    0xe37(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x4d8(%rbp)
lea    0xe26(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x4e0(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8f,-0x8(%rbp)
jge    12dd <main+0x14d>
lea    -0x260(%rbp),%rdi
mov    -0x4c8(%rbp),%rdx
mov    $0x1f4,%esi
call   1060 <fgets@plt>
lea    -0x4c0(%rbp),%rdi
mov    -0x4d0(%rbp),%rdx
mov    $0x1f4,%esi
call   1060 <fgets@plt>
cmpl   $0x14,-0x8(%rbp)
jle    1291 <main+0x101>
mov    $0x4,%edi
call   10b0 <sleep@plt>
lea    -0x260(%rbp),%rdi
mov    -0x4d8(%rbp),%rsi
call   1050 <fputs@plt>
lea    -0x4c0(%rbp),%rdi
mov    -0x4e0(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x4d8(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x4e0(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1240 <main+0xb0>
mov    -0x4c8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4d0(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4d8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4e0(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xcee(%rip),%rdi
lea    0xce5(%rip),%rsi
call   10a0 <rename@plt>
jmp    1331 <main+0x1a1>
lea    0xd30(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x4f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4c8,%rsp
lea    0xe5a(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     11c8 <main+0x38>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
jmp    12ea <main+0x15a>
lea    0xe31(%rip),%rdi
lea    0xe2c(%rip),%rsi
call   10a0 <rename@plt>
lea    0xe2e(%rip),%rdi
lea    0xe3b(%rip),%rbx
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,(%rsp)
lea    0xe2a(%rip),%rdi
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xe2c(%rip),%rdi
lea    0xe35(%rip),%rbx
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,%r12
lea    0xe25(%rip),%rdi
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
xor    %r14d,%r14d
lea    0x270(%rsp),%r13
lea    0x10(%rsp),%rbp
jmp    1283 <main+0xf3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <fputs@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %r12,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
add    $0x1,%r14d
cmp    $0x8f,%r14d
je     12b6 <main+0x126>
mov    %r13,%rdi
mov    $0x1f4,%esi
mov    (%rsp),%rdx
call   1060 <fgets@plt>
mov    %rbp,%rdi
mov    $0x1f4,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
cmp    $0x15,%r14d
jb     1250 <main+0xc0>
mov    $0x4,%edi
call   10b0 <sleep@plt>
jmp    1250 <main+0xc0>
mov    (%rsp),%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd24(%rip),%rdi
lea    0xd1b(%rip),%rsi
call   10a0 <rename@plt>
mov    $0x1,%eax
add    $0x4c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [14 x i8] c"lockfaketrack\00"
@.str.1 = [16 x i8] c"unlockfaketrack\00"
@.str.2 = [20 x i8] c"kc9lhwtrack.txt_old\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [20 x i8] c"wb9skytrack.txt_old\00"
@.str.5 = [16 x i8] c"kc9lhwtrack.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [16 x i8] c"wb9skytrack.txt\00"
@.str.8 = [28 x i8] c"fake_track already running\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [600 x i8]
%4 = alloca [600 x i8]
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.stat
store i32 0, i32* %1
%10 = call i32 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.stat* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %56
12: ; preds = %0
%13 = call i32 @rename(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %14, i32** %5
%15 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %6
%16 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %16, i32** %7
%17 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %17, i32** %8
store i32 0, i32* %2
br label %18
18: ; preds = %43, %12
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 143
br i1 %20, label %21, label %46
21: ; preds = %18
%22 = getelementptr inbounds [600 x i8], [600 x i8]* %3, i64 0, i64 0
%23 = load i32*, i32** %5
%24 = call i32 @fgets(i8* %22, i32 500, i32* %23)
%25 = getelementptr inbounds [600 x i8], [600 x i8]* %4, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32 @fgets(i8* %25, i32 500, i32* %26)
%28 = load i32, i32* %2
%29 = icmp sgt i32 %28, 20
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @sleep(i32 4)
br label %32
32: ; preds = %30, %21
%33 = getelementptr inbounds [600 x i8], [600 x i8]* %3, i64 0, i64 0
%34 = load i32*, i32** %7
%35 = call i32 @fputs(i8* %33, i32* %34)
%36 = getelementptr inbounds [600 x i8], [600 x i8]* %4, i64 0, i64 0
%37 = load i32*, i32** %8
%38 = call i32 @fputs(i8* %36, i32* %37)
%39 = load i32*, i32** %7
%40 = call i32 @fflush(i32* %39)
%41 = load i32*, i32** %8
%42 = call i32 @fflush(i32* %41)
br label %43
43: ; preds = %32
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %18
46: ; preds = %18
%47 = load i32*, i32** %5
%48 = call i32 @fclose(i32* %47)
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %7
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %8
%54 = call i32 @fclose(i32* %53)
%55 = call i32 @rename(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %58
56: ; preds = %0
%57 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %58
58: ; preds = %56, %46
ret i32 1
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [14 x i8] c"lockfaketrack\00"
@.str.1 = [16 x i8] c"unlockfaketrack\00"
@.str.2 = [20 x i8] c"kc9lhwtrack.txt_old\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [20 x i8] c"wb9skytrack.txt_old\00"
@.str.5 = [16 x i8] c"kc9lhwtrack.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [16 x i8] c"wb9skytrack.txt\00"
@str = [27 x i8] c"fake_track already running\00"
define i32 @main() {
%1 = alloca [600 x i8]
%2 = alloca [600 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [600 x i8], [600 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [600 x i8], [600 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i32 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %35
9: ; preds = %0
%10 = tail call i32 @rename(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %15
15: ; preds = %9, %22
%16 = phi i32 [ 0, %9 ], [ %27, %22 ]
%17 = call i32 @fgets(i8* %4, i32 500, i32* %11)
%18 = call i32 @fgets(i8* %5, i32 500, i32* %12)
%19 = icmp ugt i32 %16, 20
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @sleep(i32 4)
br label %22
22: ; preds = %20, %15
%23 = call i32 @fputs(i8* %4, i32* %13)
%24 = call i32 @fputs(i8* %5, i32* %14)
%25 = call i32 @fflush(i32* %13)
%26 = call i32 @fflush(i32* %14)
%27 = add nuw nsw i32 %16, 1
%28 = icmp eq i32 %27, 143
br i1 %28, label %29, label %15
29: ; preds = %22
%30 = call i32 @fclose(i32* %11)
%31 = call i32 @fclose(i32* %12)
%32 = call i32 @fclose(i32* %13)
%33 = call i32 @fclose(i32* %14)
%34 = call i32 @rename(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %37
35: ; preds = %0
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
ret i32 1
}