#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 EXIT_SUCCESS;
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd = -1;
  int i = 0;
  fd = open("/tmp/exlog.txt", O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
  if (fd != -1) {
    for (i = 0; i < 1000000; i++)
      write(fd, "AAAA", 4);
  } else
    perror("Open error:");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    0x2e5b(%rip),%rax
or     (%rax),%esi
mov    0x2e4a(%rip),%rax
or     (%rax),%esi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
lea    0xe7f(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     11ce <main+0x9e>
movl   $0x0,-0xc(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jge    11c9 <main+0x99>
mov    -0x8(%rbp),%edi
lea    0xe5e(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119a <main+0x6a>
jmp    11da <main+0xaa>
lea    0xe3f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2ebd(%rip),%rax
mov    0x2e76(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e63(%rip),%rax
or     (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    0x2e83(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe98(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     11a2 <main+0x72>
mov    %eax,%ebx
mov    $0xf4240,%ebp
lea    0xe8f(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    1180 <main+0x50>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
jmp    1194 <main+0x64>

LLVM IR (-O0):
@.str = [15 x i8] c"/tmp/exlog.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"AAAA\00"
@.str.2 = [12 x i8] c"Open error:\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_WRONLY
%6 = or i32 %4, %5
%7 = load i32, i32* @O_APPEND
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %26
15: ; preds = %0
store i32 0, i32* %3
br label %16
16: ; preds = %22, %15
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 1000000
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* %2
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
br label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %16
25: ; preds = %16
br label %28
26: ; preds = %0
%27 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %25
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@.str = [15 x i8] c"/tmp/exlog.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"AAAA\00"
@.str.2 = [12 x i8] c"Open error:\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_CREAT
%2 = load i32, i32* @O_WRONLY
%3 = or i32 %2, %1
%4 = load i32, i32* @O_APPEND
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %16, label %11
11: ; preds = %0, %11
%12 = phi i32 [ %14, %11 ], [ 0, %0 ]
%13 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %14, 1000000
br i1 %15, label %18, label %11
16: ; preds = %0
%17 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %11, %16
%19 = load i32, i32* @EXIT_SUCCESS
ret i32 %19
}