#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 BUFSIZ;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, char, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd;
  char buf[819200];
  printf("BUFSIZ = %d\n", BUFSIZ);
  fd = open("test_2.txt", O_WRONLY);
  if (fd == -1) {
    printf("open error!\n");
    return -1;
  }
  printf("write start\n");
  memset(buf, 'A', 819200);
  write(fd, buf, 819200);
  printf("write end\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc8010,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b5 <main+0x65>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <main+0xba>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc8010(%rbp),%rdi
mov    $0x41,%esi
mov    $0xc8000,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0xc8010(%rbp),%rsi
mov    $0xc8000,%edx
call   1030 <write@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc8010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xc8000,%rsp
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11e5 <main+0x85>
mov    %eax,%ebp
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x41,%esi
mov    $0xc8000,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc8000,%edx
call   1040 <write@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    11f6 <main+0x96>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0xc8000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"BUFSIZ = %d\0A\00"
@BUFSIZ = global i32 0
@.str.1 = [11 x i8] c"test_2.txt\00"
@O_WRONLY = global i32 0
@.str.2 = [13 x i8] c"open error!\0A\00"
@.str.3 = [13 x i8] c"write start\0A\00"
@.str.4 = [11 x i8] c"write end\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [819200 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @BUFSIZ
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %22
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds [819200 x i8], [819200 x i8]* %3, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 65, i32 819200)
%16 = load i32, i32* %2
%17 = getelementptr inbounds [819200 x i8], [819200 x i8]* %3, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 819200)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
store i32 0, i32* %1
br label %22
22: ; preds = %12, %10
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [13 x i8] c"BUFSIZ = %d\0A\00"
@BUFSIZ = global i32 0
@.str.1 = [11 x i8] c"test_2.txt\00"
@O_WRONLY = global i32 0
@str = [12 x i8] c"write start\00"
@str.5 = [10 x i8] c"write end\00"
@str.6 = [12 x i8] c"open error!\00"
define i32 @main() {
%1 = alloca [819200 x i8]
%2 = getelementptr inbounds [819200 x i8], [819200 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @BUFSIZ
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %16
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%12 = call i32 @memset(i8* %2, i8 signext 65, i32 819200)
%13 = call i32 @write(i32 %6, i8* %2, i32 819200)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0))
%15 = call i32 @close(i32 %6)
br label %16
16: ; preds = %10, %8
%17 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %17
}