#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int O_APPEND;
int O_CREAT;
int O_WRONLY;
char *asctime(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ creat_daemon();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(void) {
  time_t t;
  int fd;
  creat_daemon();
  while (1) {
    fd = open("daemon.log", O_WRONLY | O_CREAT | O_APPEND, 0644);
    if (fd == -1)
      do {
        perror("open error");
        exit(EXIT_FAILURE);
      } while (0);
    ;
    t = time(0);
    char *buf = asctime(localtime(&t));
    write(fd, buf, strlen(buf));
    close(fd);
    sleep(60);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <creat_daemon@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    0x2e22(%rip),%rax
or     (%rax),%esi
mov    0x2de1(%rip),%rax
or     (%rax),%esi
lea    0xe18(%rip),%rdi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    121e <main+0x6e>
jmp    1204 <main+0x54>
lea    0xe00(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    $0x3c,%edi
call   10d0 <sleep@plt>
jmp    11c6 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <creat_daemon@plt>
mov    0x2dff(%rip),%r13
mov    0x2e28(%rip),%r12
mov    (%r12),%esi
or     0x0(%r13),%esi
mov    0x2de1(%rip),%r14
or     (%r14),%esi
lea    0xe17(%rip),%rdi
mov    $0x1a4,%edx
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1273 <main+0xc3>
mov    %eax,%ebp
lea    0xdff(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    $0x3c,%edi
call   10d0 <sleep@plt>
mov    (%r12),%esi
or     0x0(%r13),%esi
or     (%r14),%esi
mov    %r15,%rdi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1210 <main+0x60>
lea    0xd91(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"daemon.log\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 (...) @creat_daemon()
br label %6
6: ; preds = %0, %21
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_APPEND
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11, i32 420)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %6
br label %16
16: ; preds = %15
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; No predecessors!
br label %21
21: ; preds = %20, %6
%22 = call i32 @time(i32 0)
store i32 %22, i32* %2
%23 = call i32 @localtime(i32* %2)
%24 = call i8* @asctime(i32 %23)
store i8* %24, i8** %4
%25 = load i32, i32* %3
%26 = load i8*, i8** %4
%27 = load i8*, i8** %4
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @write(i32 %25, i8* %26, i32 %28)
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
%32 = call i32 @sleep(i32 60)
br label %6
}

LLVM IR (-O2):
@.str = [11 x i8] c"daemon.log\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @creat_daemon()
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_APPEND
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8, i32 420)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %15, %0
%12 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0, %15
%16 = phi i32 [ %29, %15 ], [ %9, %0 ]
%17 = call i32 @time(i32 0)
store i32 %17, i32* %1
%18 = call i32 @localtime(i32* %1)
%19 = call i8* @asctime(i32 %18)
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %16, i8* %19, i32 %20)
%22 = call i32 @close(i32 %16)
%23 = call i32 @sleep(i32 60)
%24 = load i32, i32* @O_WRONLY
%25 = load i32, i32* @O_CREAT
%26 = or i32 %25, %24
%27 = load i32, i32* @O_APPEND
%28 = or i32 %26, %27
%29 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %28, i32 420)
%30 = icmp eq i32 %29, -1
br i1 %30, label %11, label %15
}