#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 */
int /*<<< orphan*/ _IONBF;
char *ctime(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ itoa(int, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp;
  char buf[64];
  int line_num = 0;
  if ((fp = fopen("times", "a+")) == NULL) {
    perror("fopen times failed");
    return -1;
  }
  setvbuf(fp, NULL, _IONBF, 0);
  while ((fgets(buf, 64, fp)) != NULL)
    line_num++;
  if (ferror(fp)) {
    perror("fgets error");
    return -1;
  }
  char num_str[4 + 64];
  time_t *tloc = (time_t *)malloc(sizeof(time_t));
  while (1) {
    itoa(++line_num, num_str);
    time(tloc);
    strcat(num_str, "	");
    strcat(num_str, ctime(tloc));
    fputs(num_str, fp);
    fputs(num_str, stdout);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x64(%rbp)
lea    0xe19(%rip),%rdi
lea    0xe18(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1219 <main+0x59>
lea    0xe01(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132f <main+0x16f>
mov    -0x18(%rbp),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     125b <main+0x9b>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1231 <main+0x71>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1286 <main+0xc6>
lea    0xda7(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132f <main+0x16f>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,-0xb8(%rbp)
mov    -0x64(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0xc4(%rbp)
mov    %edi,-0x64(%rbp)
lea    -0xb0(%rbp),%rsi
call   10d0 <itoa@plt>
mov    -0xb8(%rbp),%rdi
call   1070 <time@plt>
lea    -0xb0(%rbp),%rdi
lea    0xd5c(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0xb0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0xb8(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xc0(%rbp),%rdi
mov    %rax,%rsi
call   10c0 <strcat@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fputs@plt>
lea    -0xb0(%rbp),%rdi
mov    0x2cc0(%rip),%rax
mov    (%rax),%rsi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
jmp    1297 <main+0xd7>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe28(%rip),%rdi
lea    0xe27(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12b8 <main+0xf8>
mov    %rax,%r14
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
add    $0x1,%r15d
test   %rax,%rax
jne    1210 <main+0x50>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12c1 <main+0x101>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
lea    0x40(%rsp),%rbx
lea    0xdd5(%rip),%r13
mov    0x2d7e(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
call   10d0 <itoa@plt>
mov    %r12,%rdi
call   1070 <time@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <strcat@plt>
mov    %r12,%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
add    $0x1,%r15d
jmp    1260 <main+0xa0>
lea    0xd4a(%rip),%rdi
jmp    12c8 <main+0x108>
lea    0xd54(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"times\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [19 x i8] c"fopen times failed\00"
@_IONBF = global i32 0
@.str.3 = [12 x i8] c"fgets error\00"
@.str.4 = [2 x i8] c"\09\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [64 x i8]
%8 = alloca i32
%9 = alloca [68 x i8]
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%11 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load i32, i32* @_IONBF
%18 = call i32 @setvbuf(i32* %16, i32* null, i32 %17, i32 0)
br label %19
19: ; preds = %24, %15
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%21 = load i32*, i32** %6
%22 = call i32* @fgets(i8* %20, i32 64, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %19
27: ; preds = %19
%28 = load i32*, i32** %6
%29 = call i64 @ferror(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
33: ; preds = %27
%34 = call i64 @malloc(i32 4)
%35 = inttoptr i64 %34 to i32*
store i32* %35, i32** %10
br label %36
36: ; preds = %33, %36
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
%39 = getelementptr inbounds [68 x i8], [68 x i8]* %9, i64 0, i64 0
%40 = call i32 @itoa(i32 %38, i8* %39)
%41 = load i32*, i32** %10
%42 = call i32 @time(i32* %41)
%43 = getelementptr inbounds [68 x i8], [68 x i8]* %9, i64 0, i64 0
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%45 = getelementptr inbounds [68 x i8], [68 x i8]* %9, i64 0, i64 0
%46 = load i32*, i32** %10
%47 = call i8* @ctime(i32* %46)
%48 = call i32 @strcat(i8* %45, i8* %47)
%49 = getelementptr inbounds [68 x i8], [68 x i8]* %9, i64 0, i64 0
%50 = load i32*, i32** %6
%51 = call i32 @fputs(i8* %49, i32* %50)
%52 = getelementptr inbounds [68 x i8], [68 x i8]* %9, i64 0, i64 0
%53 = load i32*, i32** @stdout
%54 = call i32 @fputs(i8* %52, i32* %53)
%55 = call i32 @sleep(i32 1)
br label %36
56: ; preds = %31, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [6 x i8] c"times\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [19 x i8] c"fopen times failed\00"
@_IONBF = global i32 0
@.str.3 = [12 x i8] c"fgets error\00"
@.str.4 = [2 x i8] c"\09\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = alloca [68 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %39
10: ; preds = %2
%11 = load i32, i32* @_IONBF
%12 = tail call i32 @setvbuf(i32* %6, i32* null, i32 %11, i32 0)
br label %13
13: ; preds = %13, %10
%14 = phi i32 [ 0, %10 ], [ %17, %13 ]
%15 = call i32* @fgets(i8* %5, i32 64, i32* %6)
%16 = icmp eq i32* %15, null
%17 = add nuw nsw i32 %14, 1
br i1 %16, label %18, label %13
18: ; preds = %13
%19 = call i64 @ferror(i32* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %39
23: ; preds = %18
%24 = getelementptr inbounds [68 x i8], [68 x i8]* %4, i64 0, i64 0
%25 = call i64 @malloc(i32 4)
%26 = inttoptr i64 %25 to i32*
br label %27
27: ; preds = %27, %23
%28 = phi i32 [ %14, %23 ], [ %29, %27 ]
%29 = add nuw nsw i32 %28, 1
%30 = call i32 @itoa(i32 %29, i8* %24)
%31 = call i32 @time(i32* %26)
%32 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%33 = call i8* @ctime(i32* %26)
%34 = call i32 @strcat(i8* %24, i8* %33)
%35 = call i32 @fputs(i8* %24, i32* %6)
%36 = load i32*, i32** @stdout
%37 = call i32 @fputs(i8* %24, i32* %36)
%38 = call i32 @sleep(i32 1)
br label %27
39: ; preds = %21, %8
ret i32 -1
}