#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int main() {
  int i, j, max = 256;
  FILE *ofile = fopen("2.txt", "a");
  for (i = 0; i < max; ++i)
    for (j = 0; j <= i; ++j) {
      fprintf(ofile, "%d", i);
    }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x100,-0x10(%rbp)
lea    0xec3(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11a7 <main+0x87>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1194 <main+0x74>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1167 <main+0x47>
jmp    1199 <main+0x79>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1154 <main+0x34>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xed1(%rip),%rdi
lea    0xed0(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r12
xor    %ebp,%ebp
mov    $0x1,%r15d
lea    0xebb(%rip),%r14
nopl   (%rax)
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <fprintf@plt>
add    $0xffffffff,%ebx
jne    1160 <main+0x40>
add    $0x1,%ebp
add    $0x1,%r15d
cmp    $0x100,%ebp
jne    1150 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"2.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32 256, i32* %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
store i32 0, i32* %2
br label %7
7: ; preds = %24, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %27
11: ; preds = %7
store i32 0, i32* %3
br label %12
12: ; preds = %20, %11
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32*, i32** %5
%18 = load i32, i32* %2
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %12
23: ; preds = %12
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %7
27: ; preds = %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [6 x i8] c"2.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %0, %10
%3 = phi i32 [ 1, %0 ], [ %12, %10 ]
%4 = phi i32 [ 0, %0 ], [ %11, %10 ]
br label %5
5: ; preds = %2, %5
%6 = phi i32 [ 0, %2 ], [ %8, %5 ]
%7 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i32 %8, %3
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = add nuw nsw i32 %4, 1
%12 = add nuw nsw i32 %3, 1
%13 = icmp eq i32 %11, 256
br i1 %13, label %14, label %2
14: ; preds = %10
ret i32 0
}