#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*/ fputc(int, int /*<<< orphan*/ *);
int main(void) {
  int i;
  FILE *f;
  f = fopen("test.bin", "wb");
  fputc(0, f);
  for (i = 1; i < 256; i++) {
    fputc(i, f);
    fputc(i, f);
    fputc(i, f);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    11a7 <main+0x77>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1168 <main+0x38>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %rax,%rsi
call   1040 <fputc@plt>
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    1160 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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