#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_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fildes = open("temp.file", O_WRONLY | O_APPEND | O_CREAT);
  int count = 0x100000;
  while (count > 0) {
    write(fildes, "hello world\n", 12);
    count--;
  }
  close(fildes);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2e79(%rip),%rax
or     (%rax),%esi
mov    0x2ea0(%rip),%rax
or     (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
movl   $0x100000,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    119c <main+0x6c>
mov    -0x8(%rbp),%edi
lea    0xe86(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1170 <main+0x40>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e95(%rip),%rax
mov    0x2e86(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2eab(%rip),%rax
or     (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    $0x100001,%ebp
lea    0xea1(%rip),%r14
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1170 <main+0x40>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"temp.file\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@.str.1 = [13 x i8] c"hello world\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_APPEND
%6 = or i32 %4, %5
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
store i32 1048576, i32* %3
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* %2
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%16 = load i32, i32* %3
%17 = add nsw i32 %16, -1
store i32 %17, i32* %3
br label %10
18: ; preds = %10
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [10 x i8] c"temp.file\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@.str.1 = [13 x i8] c"hello world\0A\00"
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = load i32, i32* @O_APPEND
%3 = or i32 %2, %1
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %0, %7
%8 = phi i32 [ 1048576, %0 ], [ %10, %7 ]
%9 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%10 = add nsw i32 %8, -1
%11 = icmp ugt i32 %8, 1
br i1 %11, label %7, label %12
12: ; preds = %7
%13 = tail call i32 @close(i32 %6)
ret i32 0
}