#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;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int, int,
                           int, int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  FILE *fp;
  int no = 0;
  char buf[1024];
  time_t stamp;
  struct tm *tm;
  fp = fopen("/tmp/out", "a+");
  if (fp == NULL) {
    perror("fopen()");
    exit(1);
  }
  while (fgets(buf, 1024, fp) != NULL)
    no++;
  while (1) {
    time(&stamp);
    tm = localtime(&stamp);
    fprintf(fp, "%d %d-%d-%d %d:%d:%d\n", ++no, tm->tm_year + 1900,
            tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
    fflush(fp);
    sleep(1);
  }
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e1 <main+0x51>
lea    0xe3a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11e6 <main+0x56>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1213 <main+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e6 <main+0x56>
jmp    1218 <main+0x88>
lea    -0x424(%rbp),%rdi
call   1060 <time@plt>
lea    -0x424(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x43c(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x430(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    %ecx,-0x438(%rbp)
mov    -0x430(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    %r8d,-0x434(%rbp)
mov    -0x430(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x430(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x430(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x430(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xd6d(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    1218 <main+0x88>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe58(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     125f <main+0xcf>
mov    %rax,%r13
xor    %r12d,%r12d
lea    0x10(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
add    $0x1,%r12d
test   %rax,%rax
jne    11d0 <main+0x40>
lea    0xc(%rsp),%r14
lea    0xe1f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1060 <time@plt>
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    (%rax),%ecx
mov    $0x76c,%edx
add    %edx,%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
add    $0x1,%r8d
mov    0xc(%rax),%ebx
mov    0x10(%rax),%ebp
mov    0x14(%rax),%eax
sub    $0x8,%rsp
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
push   %rax
push   %rbp
push   %rbx
call   1050 <fprintf@plt>
add    $0x20,%rsp
mov    %r13,%rdi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
add    $0x1,%r12d
jmp    1200 <main+0x70>
lea    0xda6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [9 x i8] c"/tmp/out\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [8 x i8] c"fopen()\00"
@.str.3 = [22 x i8] c"%d %d-%d-%d %d:%d:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca %struct.tm*
store i32 0, i32* %1
store i32 0, i32* %3
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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 %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = load i32*, i32** %2
%17 = call i32* @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %14
22: ; preds = %14
br label %23
23: ; preds = %22, %23
%24 = call i32 @time(i32* %5)
%25 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %25, %struct.tm** %6
%26 = load i32*, i32** %2
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = load %struct.tm*, %struct.tm** %6
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1900
%33 = load %struct.tm*, %struct.tm** %6
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
%37 = load %struct.tm*, %struct.tm** %6
%38 = getelementptr inbounds %struct.tm, %struct.tm* %37, i32 0, i32 2
%39 = load i32, i32* %38
%40 = load %struct.tm*, %struct.tm** %6
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 3
%42 = load i32, i32* %41
%43 = load %struct.tm*, %struct.tm** %6
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 4
%45 = load i32, i32* %44
%46 = load %struct.tm*, %struct.tm** %6
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 5
%48 = load i32, i32* %47
%49 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %32, i32 %36, i32 %39, i32 %42, i32 %45, i32 %48)
%50 = load i32*, i32** %2
%51 = call i32 @fflush(i32* %50)
%52 = call i32 @sleep(i32 1)
br label %23
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [9 x i8] c"/tmp/out\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [8 x i8] c"fopen()\00"
@.str.3 = [22 x i8] c"%d %d-%d-%d %d:%d:%d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0, %10
%11 = phi i32 [ %14, %10 ], [ 0, %0 ]
%12 = call i32* @fgets(i8* %3, i32 1024, i32* %5)
%13 = icmp eq i32* %12, null
%14 = add nuw nsw i32 %11, 1
br i1 %13, label %15, label %10
15: ; preds = %10, %15
%16 = phi i32 [ %19, %15 ], [ %11, %10 ]
%17 = call i32 @time(i32* %2)
%18 = call %struct.tm* @localtime(i32* %2)
%19 = add nuw nsw i32 %16, 1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
%26 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 2
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 4
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 5
%33 = load i32, i32* %32
%34 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %22, i32 %25, i32 %27, i32 %29, i32 %31, i32 %33)
%35 = call i32 @fflush(i32* %5)
%36 = call i32 @sleep(i32 1)
br label %15
}