#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 */
char *asctime(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ init_daemon();
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main() {
  FILE *fp;
  time_t t;
  init_daemon();
  while (1) {
    sleep(2);
    if ((fp = fopen("test.txt", "a")) != NULL) {
      t = time(0);
      fprintf(fp, "i an here at %s\n", asctime(localtime(&t)));
      fclose(fp);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <init_daemon@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
lea    0xe59(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11ff <main+0x7f>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rdx
lea    0xe1a(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1196 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <init_daemon@plt>
lea    0xe65(%rip),%r14
lea    0xe67(%rip),%r13
lea    0xc(%rsp),%r15
lea    0xe5d(%rip),%r12
xchg   %ax,%ax
mov    $0x2,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11b0 <main+0x30>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
call   1040 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11b0 <main+0x30>

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [17 x i8] c"i an here at %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @init_daemon()
br label %5
5: ; preds = %0, %17
%6 = call i32 @sleep(i32 2)
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 = icmp ne i32* %7, null
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = call i32 @time(i32 0)
store i32 %10, i32* %3
%11 = load i32*, i32** %2
%12 = call i32 @localtime(i32* %3)
%13 = call i8* @asctime(i32 %12)
%14 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %9, %5
br label %5
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [17 x i8] c"i an here at %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @init_daemon()
br label %4
4: ; preds = %14, %0
%5 = call i32 @sleep(i32 2)
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = call i32 @time(i32 0)
store i32 %9, i32* %1
%10 = call i32 @localtime(i32* %1)
%11 = call i8* @asctime(i32 %10)
%12 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = call i32 @fclose(i32* %6)
br label %14
14: ; preds = %8, %4
br label %4
}