#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_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int i;
  char data[1024];
  int fd =
      open("1m_data.file", O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("Open file %s failed, exiting...\n", "1m_data.file");
    exit(1);
  }
  for (i = 0; i < 1024; i++) {
    write(fd, data, 1024);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    0x2e7e(%rip),%rax
or     (%rax),%esi
mov    0x2e7d(%rip),%rax
or     (%rax),%esi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
mov    0x2e4b(%rip),%rax
or     (%rax),%edx
lea    0xe6a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    11cb <main+0x7b>
lea    0xe58(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    1204 <main+0xb4>
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d2 <main+0x82>
mov    -0x414(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x2e56(%rip),%rax
mov    0x2e87(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
mov    0x2e4b(%rip),%rax
mov    0x2e54(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe71(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d9 <main+0x89>
mov    %eax,%ebx
mov    $0x400,%ebp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    11b0 <main+0x60>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe2d(%rip),%rdi
lea    0xe19(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"1m_data.file\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [33 x i8] c"Open file %s failed, exiting...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
store i32 0, i32* %2
br label %20
20: ; preds = %27, %19
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 1024
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* %4
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%26 = call i32 @write(i32 %24, i8* %25, i32 1024)
br label %27
27: ; preds = %23
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %20
30: ; preds = %20
%31 = load i32, i32* %4
%32 = call i32 @close(i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"1m_data.file\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [33 x i8] c"Open file %s failed, exiting...\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_TRUNC
%5 = or i32 %4, %3
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0, %16
%17 = phi i32 [ %19, %16 ], [ 0, %0 ]
%18 = call i32 @write(i32 %11, i8* %2, i32 1024)
%19 = add nuw nsw i32 %17, 1
%20 = icmp eq i32 %19, 1024
br i1 %20, label %21, label %16
21: ; preds = %16
%22 = tail call i32 @close(i32 %11)
ret i32 0
}