#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 */

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ init_daemon();
int open(char *, int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int fd;
  char *cont = "hello sundy\n";
  init_daemon();
  while (1) {
    fd = open("/tmp/sundy.log", O_RDWR | O_CREAT | O_APPEND, 0666);
    if (fd > 0) {
      write(fd, cont, strlen(cont));
      close(fd);
    }
    sleep(5);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <init_daemon@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
or     (%rax),%esi
mov    0x2e2e(%rip),%rax
or     (%rax),%esi
lea    0xe6a(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11e7 <main+0x87>
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   1060 <close@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
jmp    1181 <main+0x21>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <init_daemon@plt>
mov    0x2e67(%rip),%r15
mov    0x2e78(%rip),%r12
mov    0x2e41(%rip),%r13
lea    0xe7f(%rip),%r14
lea    0xe6b(%rip),%rbx
jmp    11aa <main+0x4a>
nopw   0x0(%rax,%rax,1)
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    (%r12),%esi
or     (%r15),%esi
or     0x0(%r13),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
test   %eax,%eax
jle    11a0 <main+0x40>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11a0 <main+0x40>

LLVM IR (-O0):
@.str = [13 x i8] c"hello sundy\0A\00"
@.str.1 = [15 x i8] c"/tmp/sundy.log\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = call i32 (...) @init_daemon()
br label %5
5: ; preds = %0, %22
%6 = load i32, i32* @O_RDWR
%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 ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 438)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %5
%15 = load i32, i32* %2
%16 = load i8*, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @write(i32 %15, i8* %16, i32 %18)
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %14, %5
%23 = call i32 @sleep(i32 5)
br label %5
}

LLVM IR (-O2):
@.str = [13 x i8] c"hello sundy\0A\00"
@.str.1 = [15 x i8] c"/tmp/sundy.log\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @init_daemon()
br label %2
2: ; preds = %14, %0
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @O_APPEND
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 438)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @close(i32 %8)
br label %14
14: ; preds = %10, %2
%15 = tail call i32 @sleep(i32 5)
br label %2
}