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

/* Variables and functions */
int /*<<< orphan*/ ez_daemonize();
int /*<<< orphan*/ fflush(void *);
void *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, void *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  int i = 0;
  ez_daemonize();
  FILE *fd = fopen("./output", "a+");
  if (fd == ((void *)0)) {
    printf("Error open output");
    return 0;
  }
  for (; i < 10000; i++) {
    printf("Error %d\n", i);
    fwrite("ferror\n", 7, 1, fd);
    fflush(fd);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <ez_daemonize@plt>
lea    0xe75(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c0 <main+0x60>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1225 <main+0xc5>
jmp    11c5 <main+0x65>
cmpl   $0x2710,-0x14(%rbp)
jge    121e <main+0xbe>
mov    -0x14(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rcx
lea    0xe3a(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c5 <main+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <ez_daemonize@plt>
lea    0xe8b(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e0 <main+0x80>
mov    %rax,%rbx
lea    0xe8e(%rip),%r14
lea    0xe91(%rip),%r15
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
add    $0x1,%ebp
cmp    $0x2710,%ebp
jne    11a0 <main+0x40>
jmp    11ee <main+0x8e>
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"./output\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [18 x i8] c"Error open output\00"
@.str.3 = [10 x i8] c"Error %d\0A\00"
@.str.4 = [8 x i8] c"ferror\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = call i32 (...) @ez_daemonize()
%9 = call i8* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %30
14: ; preds = %2
br label %15
15: ; preds = %26, %14
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 10000
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %7
%22 = call i32 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7, i32 1, i8* %21)
%23 = load i8*, i8** %7
%24 = call i32 @fflush(i8* %23)
%25 = call i32 @sleep(i32 1)
br label %26
26: ; preds = %18
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %15
29: ; preds = %15
store i32 0, i32* %3
br label %30
30: ; preds = %29, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [9 x i8] c"./output\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [18 x i8] c"Error open output\00"
@.str.3 = [10 x i8] c"Error %d\0A\00"
@.str.4 = [8 x i8] c"ferror\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @ez_daemonize()
%4 = tail call i8* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %16
8: ; preds = %2, %8
%9 = phi i32 [ %14, %8 ], [ 0, %2 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = tail call i32 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7, i32 1, i8* %4)
%12 = tail call i32 @fflush(i8* %4)
%13 = tail call i32 @sleep(i32 1)
%14 = add nuw nsw i32 %9, 1
%15 = icmp eq i32 %14, 10000
br i1 %15, label %16, label %8
16: ; preds = %8, %6
ret i32 0
}