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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ init_daemon();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ *stderr;
int main() {
  FILE *fp;
  init_daemon();
  while (1) {
    sleep(2);
    if ((fp = fopen("/root/test.log", "a")) >= 0) {
      fprintf(fp, "stcik into...\n");
      fclose(fp);
    }
    fprintf(stderr, "shitshit\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <init_daemon@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xe89(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jb     11aa <main+0x5a>
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%rdi
lea    0xe65(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1166 <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   1030 <init_daemon@plt>
lea    0xe97(%rip),%r14
lea    0xe9f(%rip),%r15
lea    0xe9a(%rip),%r12
mov    0x2e62(%rip),%rbp
lea    0xe9b(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    $0xe,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x0(%rbp),%rcx
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r13,%rdi
call   1060 <fwrite@plt>
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [15 x i8] c"/root/test.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [15 x i8] c"stcik into...\0A\00"
@stderr = global i32* null
@.str.3 = [10 x i8] c"shitshit\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32 (...) @init_daemon()
br label %4
4: ; preds = %0, %13
%5 = call i32 @sleep(i32 2)
%6 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp uge i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32*, i32** %2
%10 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32*, i32** %2
%12 = call i32 @fclose(i32* %11)
br label %13
13: ; preds = %8, %4
%14 = load i32*, i32** @stderr
%15 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %4
}

LLVM IR (-O2):
@.str = [15 x i8] c"/root/test.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [15 x i8] c"stcik into...\0A\00"
@stderr = global i32* null
@.str.3 = [10 x i8] c"shitshit\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @init_daemon()
br label %2
2: ; preds = %2, %0
%3 = tail call i32 @sleep(i32 2)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 14, i64 1, i32* %4)
%6 = tail call i32 @fclose(i32* %4)
%7 = load i32*, i32** @stderr
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 9, i64 1, i32* %7)
br label %2
}