#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 uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int main(void) {
  uint16_t tile = 256;
  int i, j;
  FILE *out;
  if ((out = fopen("tilemap", "wb")) == NULL) {
    perror("Could not open output file 'tilemap'");
    return 1;
  }
  for (i = 0; i < 7; i++) {
    for (j = 0; j < 32; j++) {
      fwrite(&tile, 2, 1, out);
      tile++;
    }
  }
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x100,-0x8(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118f <main+0x4f>
lea    0xe8d(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <main+0xc2>
movl   $0x0,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jge    11f2 <main+0xb2>
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    11df <main+0x9f>
mov    -0x18(%rbp),%rcx
lea    -0x8(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a7 <main+0x67>
jmp    11e4 <main+0xa4>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1196 <main+0x56>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x100,0xc(%rsp)
lea    0xea9(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     12d2 <main+0x192>
mov    %rax,%rbx
mov    $0x20,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%ebp
jne    1180 <main+0x40>
mov    $0x20,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%ebp
jne    11b0 <main+0x70>
mov    $0x20,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%ebp
jne    11e0 <main+0xa0>
mov    $0x20,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%ebp
jne    1210 <main+0xd0>
mov    $0x20,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%ebp
jne    1240 <main+0x100>
mov    $0x20,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%ebp
jne    1270 <main+0x130>
mov    $0x20,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%ebp
jne    12a0 <main+0x160>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd32(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    12c9 <main+0x189>

LLVM IR (-O0):
@.str = [8 x i8] c"tilemap\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [37 x i8] c"Could not open output file 'tilemap'\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* %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %33
10: ; preds = %0
store i32 0, i32* %3
br label %11
11: ; preds = %27, %10
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 7
br i1 %13, label %14, label %30
14: ; preds = %11
store i32 0, i32* %4
br label %15
15: ; preds = %23, %14
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 32
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32*, i32** %5
%20 = call i32 @fwrite(i32* %2, i32 2, i32 1, i32* %19)
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %23
23: ; preds = %18
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %15
26: ; preds = %15
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %11
30: ; preds = %11
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %1
br label %33
33: ; preds = %30, %8
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [8 x i8] c"tilemap\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [37 x i8] c"Could not open output file 'tilemap'\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 256, i32* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %58
7: ; preds = %0, %7
%8 = phi i32 [ %12, %7 ], [ 0, %0 ]
%9 = call i32 @fwrite(i32* %1, i32 2, i32 1, i32* %3)
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
%12 = add nuw nsw i32 %8, 1
%13 = icmp eq i32 %12, 32
br i1 %13, label %14, label %7
14: ; preds = %7, %14
%15 = phi i32 [ %19, %14 ], [ 0, %7 ]
%16 = call i32 @fwrite(i32* %1, i32 2, i32 1, i32* %3)
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %1
%19 = add nuw nsw i32 %15, 1
%20 = icmp eq i32 %19, 32
br i1 %20, label %21, label %14
21: ; preds = %14, %21
%22 = phi i32 [ %26, %21 ], [ 0, %14 ]
%23 = call i32 @fwrite(i32* %1, i32 2, i32 1, i32* %3)
%24 = load i32, i32* %1
%25 = add nsw i32 %24, 1
store i32 %25, i32* %1
%26 = add nuw nsw i32 %22, 1
%27 = icmp eq i32 %26, 32
br i1 %27, label %28, label %21
28: ; preds = %21, %28
%29 = phi i32 [ %33, %28 ], [ 0, %21 ]
%30 = call i32 @fwrite(i32* %1, i32 2, i32 1, i32* %3)
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 1
store i32 %32, i32* %1
%33 = add nuw nsw i32 %29, 1
%34 = icmp eq i32 %33, 32
br i1 %34, label %35, label %28
35: ; preds = %28, %35
%36 = phi i32 [ %40, %35 ], [ 0, %28 ]
%37 = call i32 @fwrite(i32* %1, i32 2, i32 1, i32* %3)
%38 = load i32, i32* %1
%39 = add nsw i32 %38, 1
store i32 %39, i32* %1
%40 = add nuw nsw i32 %36, 1
%41 = icmp eq i32 %40, 32
br i1 %41, label %42, label %35
42: ; preds = %35, %42
%43 = phi i32 [ %47, %42 ], [ 0, %35 ]
%44 = call i32 @fwrite(i32* %1, i32 2, i32 1, i32* %3)
%45 = load i32, i32* %1
%46 = add nsw i32 %45, 1
store i32 %46, i32* %1
%47 = add nuw nsw i32 %43, 1
%48 = icmp eq i32 %47, 32
br i1 %48, label %49, label %42
49: ; preds = %42, %49
%50 = phi i32 [ %54, %49 ], [ 0, %42 ]
%51 = call i32 @fwrite(i32* %1, i32 2, i32 1, i32* %3)
%52 = load i32, i32* %1
%53 = add nsw i32 %52, 1
store i32 %53, i32* %1
%54 = add nuw nsw i32 %50, 1
%55 = icmp eq i32 %54, 32
br i1 %55, label %56, label %49
56: ; preds = %49
%57 = tail call i32 @fclose(i32* %3)
br label %58
58: ; preds = %56, %5
%59 = phi i32 [ 1, %5 ], [ 0, %56 ]
ret i32 %59
}