#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage: %s outfile\n", argv[0]);
    return 1;
  }
  FILE *file = fopen(argv[1], "w");
  for (int i = 1;; i++) {
    fprintf(file, "#");
    if (i % 1024 == 0)
      printf("Wrote a total of %d bytes.\n", i);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1170 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe94(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c4 <main+0x94>
mov    -0x1c(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c9 <main+0x99>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <main+0x5f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1186 <main+0x56>
mov    0x8(%rsi),%rdi
lea    0xecf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    $0x1,%ebp
lea    0xebd(%rip),%r14
jmp    1163 <main+0x33>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    $0x23,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
test   $0x3ff,%ebp
jne    1160 <main+0x30>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1160 <main+0x30>
mov    (%rsi),%rsi
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Usage: %s outfile\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"#\00"
@.str.3 = [28 x i8] c"Wrote a total of %d bytes.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
ret i32 1
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
store i32 1, i32* %7
br label %20
20: ; preds = %30, %15
%21 = load i32*, i32** %6
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %7
%24 = srem i32 %23, 1024
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %20
br label %30
30: ; preds = %29
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %20
}

LLVM IR (-O2):
@.str = [19 x i8] c"Usage: %s outfile\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"Wrote a total of %d bytes.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5)
ret i32 1
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %18, %7
%12 = phi i32 [ 1, %7 ], [ %19, %18 ]
%13 = tail call i32 @fputc(i32 35, i32* %10)
%14 = and i32 %12, 1023
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %18
18: ; preds = %11, %16
%19 = add nuw nsw i32 %12, 1
br label %11
}