#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_FAILURE;
int EXIT_SUCCESS;
scalar_t__ errno;
int fwrite(char *, size_t, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
size_t strtol(char *, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  size_t req_sz;
  char buf[4096];
  errno = 0;
  req_sz = 900000;
  if (argc > 1)
    req_sz = strtol(argv[1], 0, 10);
  if (errno != 0) {
    perror("strtol");
    return EXIT_FAILURE;
  }
  memset(buf, 255, 4096);
  while (req_sz > 0) {
    size_t step = req_sz;
    if (step > 4096)
      step = 4096;
    req_sz -= step;
    if (fwrite(buf, step, 1, stdout) != 1) {
      perror("fwrite");
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e80(%rip),%rax
movq   $0x0,(%rax)
movq   $0xdbba0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1191 <main+0x51>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e48(%rip),%rax
cmpq   $0x0,(%rax)
je     11bf <main+0x7f>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <main+0x131>
lea    -0x1020(%rbp),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
jbe    1265 <main+0x125>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1028(%rbp)
cmpq   $0x1000,-0x1028(%rbp)
jbe    1207 <main+0xc7>
movq   $0x1000,-0x1028(%rbp)
mov    -0x1028(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
mov    0x2da2(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     1260 <main+0x120>
lea    0xdbd(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <main+0x131>
jmp    11d5 <main+0x95>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    0x2e8b(%rip),%r14
movq   $0x0,(%r14)
mov    $0xdbba0,%ebx
cmp    $0x2,%edi
jl     117f <main+0x3f>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpq   $0x0,(%r14)
jne    11e7 <main+0xa7>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
mov    0x2e2d(%rip),%r15
mov    0x2e2e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %rbx,%rbx
je     11fa <main+0xba>
cmp    $0x1000,%rbx
mov    $0x1000,%esi
cmovb  %rbx,%rsi
sub    %rsi,%rbx
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     11b0 <main+0x70>
lea    0xe22(%rip),%rdi
jmp    11ee <main+0xae>
lea    0xe12(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dde(%rip),%r15
mov    (%r15),%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [7 x i8] c"strtol\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [7 x i8] c"fwrite\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [4096 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* @errno
store i64 900000, i64* %6
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strtol(i8* %14, i32 0, i32 10)
store i64 %15, i64* %6
br label %16
16: ; preds = %11, %2
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %48
22: ; preds = %16
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 255, i32 4096)
br label %25
25: ; preds = %45, %22
%26 = load i64, i64* %6
%27 = icmp ugt i64 %26, 0
br i1 %27, label %28, label %46
28: ; preds = %25
%29 = load i64, i64* %6
store i64 %29, i64* %8
%30 = load i64, i64* %8
%31 = icmp ugt i64 %30, 4096
br i1 %31, label %32, label %33
32: ; preds = %28
store i64 4096, i64* %8
br label %33
33: ; preds = %32, %28
%34 = load i64, i64* %8
%35 = load i64, i64* %6
%36 = sub i64 %35, %34
store i64 %36, i64* %6
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%38 = load i64, i64* %8
%39 = load i32, i32* @stdout
%40 = call i32 @fwrite(i8* %37, i64 %38, i32 1, i32 %39)
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %33
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %48
45: ; preds = %33
br label %25
46: ; preds = %25
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %3
br label %48
48: ; preds = %46, %42, %19
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [7 x i8] c"strtol\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [7 x i8] c"fwrite\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
store i64 0, i64* @errno
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strtol(i8* %8, i32 0, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %29
14: ; preds = %2, %6
%15 = phi i64 [ %9, %6 ], [ 900000, %2 ]
%16 = call i32 @memset(i8* %4, i32 255, i32 4096)
br label %17
17: ; preds = %20, %14
%18 = phi i64 [ %15, %14 ], [ %23, %20 ]
%19 = icmp eq i64 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = icmp ult i64 %18, 4096
%22 = select i1 %21, i64 %18, i64 4096
%23 = sub i64 %18, %22
%24 = load i32, i32* @stdout
%25 = call i32 @fwrite(i8* %4, i64 %22, i32 1, i32 %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %17, label %27
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %17, %27, %12
%30 = phi i32* [ @EXIT_FAILURE, %12 ], [ @EXIT_FAILURE, %27 ], [ @EXIT_SUCCESS, %17 ]
%31 = load i32, i32* %30
ret i32 %31
}