#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *fp;
  char buf[819200];
  printf("BUFSIZ = %d\n", BUFSIZ);
  fp = fopen("test_2.txt", "wb");
  if (fp == NULL) {
    printf("fopen error!\n");
    return -1;
  }
  printf("fwrite start\n");
  memset(buf, 'A', 819200);
  fwrite(buf, 819200, 1, fp);
  printf("fwrite end\n");
  fclose(fp);
  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>
lea    0xe8d(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b5 <main+0x65>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <main+0xc1>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc8010(%rbp),%rdi
mov    $0x41,%esi
mov    $0xc8000,%edx
call   1050 <memset@plt>
lea    -0xc8010(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xc8000,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@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    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11eb <main+0x8b>
mov    %rax,%rbx
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x41,%esi
mov    $0xc8000,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    $0xc8000,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11fc <main+0x9c>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%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"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [14 x i8] c"fopen error!\0A\00"
@.str.4 = [14 x i8] c"fwrite start\0A\00"
@.str.5 = [12 x i8] c"fwrite 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 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %21
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%13 = getelementptr inbounds [819200 x i8], [819200 x i8]* %3, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i8 signext 65, i32 819200)
%15 = getelementptr inbounds [819200 x i8], [819200 x i8]* %3, i64 0, i64 0
%16 = load i32*, i32** %2
%17 = call i32 @fwrite(i8* %15, i32 819200, i32 1, i32* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
store i32 0, i32* %1
br label %21
21: ; preds = %11, %9
%22 = load i32, i32* %1
ret i32 %22
}

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"
@.str.2 = [3 x i8] c"wb\00"
@str = [13 x i8] c"fwrite start\00"
@str.6 = [11 x i8] c"fwrite end\00"
@str.7 = [13 x i8] c"fopen 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 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %15
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%11 = call i32 @memset(i8* %2, i8 signext 65, i32 819200)
%12 = call i32 @fwrite(i8* %2, i32 819200, i32 1, i32* %5)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
%14 = call i32 @fclose(i32* %5)
br label %15
15: ; preds = %9, %7
%16 = phi i32 [ -1, %7 ], [ 0, %9 ]
ret i32 %16
}