#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 a;
  FILE *f;
  f = fopen("testfile.1", "wb");
  if (f) {
    for (a = 0; a < 512; a++) {
      fputc(a & 0xff, f);
    }
    fclose(f);
  }
  f = fopen("testfile.2", "wb");
  if (f) {
    for (a = 0; a < 512; a++) {
      fputc(((a >> 8) & 0xff) * 64 + 64, 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    0xebe(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119e <main+0x6e>
movl   $0x0,-0x8(%rbp)
cmpl   $0x200,-0x8(%rbp)
jge    1195 <main+0x65>
mov    -0x8(%rbp),%edi
and    $0xff,%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>
lea    0xe69(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1206 <main+0xd6>
movl   $0x0,-0x8(%rbp)
cmpl   $0x200,-0x8(%rbp)
jge    11fd <main+0xcd>
mov    -0x8(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
shl    $0x6,%edi
add    $0x40,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c7 <main+0x97>
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    0xeca(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     116f <main+0x3f>
mov    %rax,%rbx
xor    %ebp,%ebp
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%ebp
cmp    $0x200,%ebp
jne    1150 <main+0x20>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe98(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b9 <main+0x89>
mov    %rax,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
shr    $0x2,%edi
and    $0x3fc0,%edi
add    $0x40,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%ebp
cmp    $0x200,%ebp
jne    1190 <main+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"testfile.1\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [11 x i8] c"testfile.2\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 ([11 x i8], [11 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 = icmp ne i32* %5, null
br i1 %6, label %7, label %22
7: ; preds = %0
store i32 0, i32* %2
br label %8
8: ; preds = %16, %7
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 512
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32, i32* %2
%13 = and i32 %12, 255
%14 = load i32*, i32** %3
%15 = call i32 @fputc(i32 %13, i32* %14)
br label %16
16: ; preds = %11
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %8
19: ; preds = %8
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %19, %0
%23 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %3
%24 = load i32*, i32** %3
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %44
26: ; preds = %22
store i32 0, i32* %2
br label %27
27: ; preds = %38, %26
%28 = load i32, i32* %2
%29 = icmp slt i32 %28, 512
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = load i32, i32* %2
%32 = ashr i32 %31, 8
%33 = and i32 %32, 255
%34 = mul nsw i32 %33, 64
%35 = add nsw i32 %34, 64
%36 = load i32*, i32** %3
%37 = call i32 @fputc(i32 %35, i32* %36)
br label %38
38: ; preds = %30
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %27
41: ; preds = %27
%42 = load i32*, i32** %3
%43 = call i32 @fclose(i32* %42)
br label %44
44: ; preds = %41, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"testfile.1\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [11 x i8] c"testfile.2\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %11, label %3
3: ; preds = %0, %3
%4 = phi i32 [ %7, %3 ], [ 0, %0 ]
%5 = and i32 %4, 255
%6 = tail call i32 @fputc(i32 %5, i32* %1)
%7 = add nuw nsw i32 %4, 1
%8 = icmp eq i32 %7, 512
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = tail call i32 @fclose(i32* %1)
br label %11
11: ; preds = %9, %0
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %24, label %14
14: ; preds = %11, %14
%15 = phi i32 [ %20, %14 ], [ 0, %11 ]
%16 = lshr i32 %15, 2
%17 = and i32 %16, 16320
%18 = add nuw nsw i32 %17, 64
%19 = tail call i32 @fputc(i32 %18, i32* %12)
%20 = add nuw nsw i32 %15, 1
%21 = icmp eq i32 %20, 512
br i1 %21, label %22, label %14
22: ; preds = %14
%23 = tail call i32 @fclose(i32* %12)
br label %24
24: ; preds = %22, %11
ret i32 0
}