#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*/);
void 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);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1090 <creat_daemon@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    0x2e29(%rip),%rax
or     (%rax),%esi
mov    0x2de8(%rip),%rax
or     (%rax),%esi
lea    0xe1f(%rip),%rdi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1217 <main+0x67>
jmp    11fd <main+0x4d>
lea    0xe07(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    $0x3c,%edi
call   10d0 <sleep@plt>
jmp    11bf <main+0xf>

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

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 void @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
}