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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int get_timestr(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *file;
  char before[60] = "none\n", current[60];
  if ((file = fopen("testReadWrite.log", "a+")) == NULL) {
    printf("File could not be opened. \n");
    return -1;
  }
  if (get_timestr(current, sizeof(current)) == -1) {
    printf("Can't get time str!!\n");
    return -1;
  }
  while (1) {
    fgets(before, sizeof(before), file);
    if (feof(file))
      break;
  }
  printf("The previous time update was %s", before);
  printf("The current time is %s\n", current);
  fprintf(file, "%s\n", current);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1060 <memset@plt>
movb   $0x6e,-0x50(%rbp)
movb   $0x6f,-0x4f(%rbp)
movb   $0x6e,-0x4e(%rbp)
movb   $0x65,-0x4d(%rbp)
movb   $0xa,-0x4c(%rbp)
lea    0xe43(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f1 <main+0x71>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <main+0x127>
lea    -0x90(%rbp),%rdi
mov    $0x3c,%esi
call   1050 <get_timestr@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0xa5>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <main+0x127>
jmp    122a <main+0xaa>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3c,%esi
call   1070 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     1254 <main+0xd4>
jmp    1259 <main+0xd9>
jmp    122a <main+0xaa>
lea    -0x50(%rbp),%rsi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movups %xmm0,0x2c(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x656e6f6e,(%rsp)
movb   $0xa,0x4(%rsp)
lea    0xe4c(%rip),%rdi
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1242 <main+0xc2>
mov    %rax,%rbx
lea    0x40(%rsp),%rdi
mov    $0x3c,%esi
call   1060 <get_timestr@plt>
cmp    $0xffffffff,%eax
je     124b <main+0xcb>
mov    %rsp,%rbp
nop
mov    %rbp,%rdi
mov    $0x3c,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     11e0 <main+0x60>
lea    0xe11(%rip),%rdi
xor    %ebp,%ebp
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1e(%rip),%rdi
lea    0x40(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    125c <main+0xdc>
lea    0xe19(%rip),%rdi
jmp    1252 <main+0xd2>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"testReadWrite.log\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [28 x i8] c"File could not be opened. \0A\00"
@.str.3 = [22 x i8] c"Can't get time str!!\0A\00"
@.str.4 = [32 x i8] c"The previous time update was %s\00"
@.str.5 = [24 x i8] c"The current time is %s\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [60 x i8]
%4 = alloca [60 x i8]
store i32 0, i32* %1
%5 = bitcast [60 x i8]* %3 to i8*
%6 = bitcast i8* %5 to [60 x i8]*
%7 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i32 0, i32 0
store i8 110, i8* %7
%8 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i32 0, i32 1
store i8 111, i8* %8
%9 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i32 0, i32 2
store i8 110, i8* %9
%10 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i32 0, i32 3
store i8 101, i8* %10
%11 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i32 0, i32 4
store i8 10, i8* %11
%12 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
16: ; preds = %0
%17 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%18 = call i32 @get_timestr(i8* %17, i32 60)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
22: ; preds = %16
br label %23
23: ; preds = %22, %31
%24 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%25 = load i32*, i32** %2
%26 = call i32 @fgets(i8* %24, i32 60, i32* %25)
%27 = load i32*, i32** %2
%28 = call i64 @feof(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
br label %32
31: ; preds = %23
br label %23
32: ; preds = %30
%33 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %2
%38 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%39 = call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = load i32*, i32** %2
%41 = call i32 @fclose(i32* %40)
store i32 0, i32* %1
br label %42
42: ; preds = %32, %20, %14
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [18 x i8] c"testReadWrite.log\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.4 = [32 x i8] c"The previous time update was %s\00"
@.str.5 = [24 x i8] c"The current time is %s\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@str = [21 x i8] c"Can't get time str!!\00"
@str.7 = [27 x i8] c"File could not be opened. \00"
define i32 @main() {
%1 = alloca [60 x i8]
%2 = alloca [60 x i8]
%3 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 0
store i8 110, i8* %3
%4 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 1
store i8 111, i8* %4
%5 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 2
store i8 110, i8* %5
%6 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 3
store i8 101, i8* %6
%7 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 4
store i8 10, i8* %7
%8 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
br label %27
13: ; preds = %0
%14 = call i32 @get_timestr(i8* %8, i32 60)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %27
18: ; preds = %13, %18
%19 = call i32 @fgets(i8* %3, i32 60, i32* %9)
%20 = call i64 @feof(i32* %9)
%21 = icmp eq i64 %20, 0
br i1 %21, label %18, label %22
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%25 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%26 = call i32 @fclose(i32* %9)
br label %27
27: ; preds = %22, %16, %11
%28 = phi i32 [ -1, %11 ], [ -1, %16 ], [ 0, %22 ]
ret i32 %28
}