#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int fwrite(char *, size_t, int, int /*<<< orphan*/);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
size_t strtol(char *, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  char *p, *q, *r, *s;
  size_t req_sz;
  errno = 0;
  req_sz = 900000;
  if (argc > 1)
    req_sz = strtol(argv[1], 0, 10);
  if (errno != 0) {
    perror("strtol");
    return EXIT_FAILURE;
  }
  p = q = r = s = malloc(req_sz + 1);
  if (p == 0) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  r = q + req_sz;
  *q++ = 'a';
  while (q < r) {
    if (*p++ == 'a')
      *q++ = 'b';
    *q++ = 'a';
  }
  if (fwrite(s, req_sz, 1, stdout) != 1) {
    perror("fwrite");
    return EXIT_FAILURE;
  }
  free(s);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
movq   $0x0,(%rax)
movq   $0xdbba0,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11ae <main+0x4e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x38(%rbp)
mov    0x2e2b(%rip),%rax
cmpq   $0x0,(%rax)
je     11dc <main+0x7c>
lea    0xe3a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e4 <main+0x184>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121e <main+0xbe>
lea    0xdfc(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x61,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    128e <main+0x12e>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x61,%eax
jne    1277 <main+0x117>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x62,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x61,(%rax)
jmp    123c <main+0xdc>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2d33(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
je     12cf <main+0x16f>
lea    0xd55(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e4 <main+0x184>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e74(%rip),%rbx
movq   $0x0,(%rbx)
mov    $0xdbba0,%r14d
cmp    $0x2,%edi
jl     119b <main+0x3b>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpq   $0x0,(%rbx)
jne    124a <main+0xea>
mov    %rax,%r14
lea    0x1(%r14),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     125f <main+0xff>
mov    %rax,%r15
movb   $0x61,(%rax)
cmp    $0x2,%r14
jl     120c <main+0xac>
lea    (%r15,%r14,1),%rax
mov    %r15,%rcx
add    $0x1,%rcx
mov    $0x61,%bl
mov    %rcx,%rsi
mov    %r15,%rdx
cmp    $0x61,%bl
jne    11f0 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x2,%rdx
movb   $0x62,(%rsi)
jmp    11f3 <main+0x93>
nopl   0x0(%rax)
mov    %rsi,%rdx
movb   $0x61,(%rdx)
lea    0x1(%rdx),%rsi
cmp    %rax,%rsi
jae    120c <main+0xac>
mov    (%rcx),%bl
add    $0x1,%rcx
cmp    $0x61,%bl
jne    11f0 <main+0x90>
jmp    11e0 <main+0x80>
mov    0x2dbd(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
jne    1241 <main+0xe1>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdc6(%rip),%rdi
jmp    1251 <main+0xf1>
lea    0xdaf(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d7b(%rip),%rax
jmp    1239 <main+0xd9>
lea    0xda1(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [7 x i8] c"strtol\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"malloc\00"
@stdout = global i32 0
@.str.2 = [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 i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = 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* %10
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strtol(i8* %16, i32 0, i32 10)
store i64 %17, i64* %10
br label %18
18: ; preds = %13, %2
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
store i32 %23, i32* %3
br label %69
24: ; preds = %18
%25 = load i64, i64* %10
%26 = add i64 %25, 1
%27 = call i8* @malloc(i64 %26)
store i8* %27, i8** %9
store i8* %27, i8** %8
store i8* %27, i8** %7
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %24
%35 = load i8*, i8** %7
%36 = load i64, i64* %10
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %8
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %7
store i8 97, i8* %38
br label %40
40: ; preds = %53, %34
%41 = load i8*, i8** %7
%42 = load i8*, i8** %8
%43 = icmp ult i8* %41, %42
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %6
%47 = load i8, i8* %45
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 97
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = load i8*, i8** %7
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %7
store i8 98, i8* %51
br label %53
53: ; preds = %50, %44
%54 = load i8*, i8** %7
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %7
store i8 97, i8* %54
br label %40
56: ; preds = %40
%57 = load i8*, i8** %9
%58 = load i64, i64* %10
%59 = load i32, i32* @stdout
%60 = call i32 @fwrite(i8* %57, i64 %58, i32 1, i32 %59)
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %65
62: ; preds = %56
%63 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
store i32 %64, i32* %3
br label %69
65: ; preds = %56
%66 = load i8*, i8** %9
%67 = call i32 @free(i8* %66)
%68 = load i32, i32* @EXIT_SUCCESS
store i32 %68, i32* %3
br label %69
69: ; preds = %65, %62, %21
%70 = load i32, i32* %3
ret i32 %70
}

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