#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*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main() {
  FILE *inptr = fopen("fakebmp.txt", "r");
  if (inptr == NULL) {
    fprintf(stderr, "Error 1002: Could not open file!\n");
    return 1002;
  }
  FILE *outptr = fopen("out_fakebmp.txt", "w");
  if (outptr == NULL) {
    fprintf(stderr, "Error 1003: Could not write to file!\n");
    return 1003;
  }
  char *triple = malloc(sizeof(char) * 3);
  fread(triple, sizeof(char), 1, inptr);
  fwrite(triple, sizeof(char), 1, outptr);
  fread(triple, sizeof(char), 1, inptr);
  fwrite(triple, sizeof(char), 1, outptr);
  fread(triple, sizeof(char), 1, inptr);
  fwrite(triple, sizeof(char), 1, outptr);
  free(triple);
  fclose(inptr);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe92(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d2 <main+0x52>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x3ea,-0x4(%rbp)
jmp    12c0 <main+0x140>
lea    0xe4b(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1215 <main+0x95>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x3eb,-0x4(%rbp)
jmp    12c0 <main+0x140>
mov    $0x3,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd6e(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe9c(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     124e <main+0xce>
mov    %rax,%r15
lea    0xe79(%rip),%rdi
lea    0xe82(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     126a <main+0xea>
mov    %rax,%r14
mov    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
jmp    1284 <main+0x104>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x3ea,%eax
jmp    1284 <main+0x104>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x3eb,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"fakebmp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Error 1002: Could not open file!\0A\00"
@.str.3 = [16 x i8] c"out_fakebmp.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [38 x i8] c"Error 1003: Could not write to file!\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 1002, i32* %1
br label %43
11: ; preds = %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
store i32 1003, i32* %1
br label %43
18: ; preds = %11
%19 = call i8* @malloc(i32 3)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = load i32*, i32** %2
%22 = call i32 @fread(i8* %20, i32 1, i32 1, i32* %21)
%23 = load i8*, i8** %4
%24 = load i32*, i32** %3
%25 = call i32 @fwrite(i8* %23, i32 1, i32 1, i32* %24)
%26 = load i8*, i8** %4
%27 = load i32*, i32** %2
%28 = call i32 @fread(i8* %26, i32 1, i32 1, i32* %27)
%29 = load i8*, i8** %4
%30 = load i32*, i32** %3
%31 = call i32 @fwrite(i8* %29, i32 1, i32 1, i32* %30)
%32 = load i8*, i8** %4
%33 = load i32*, i32** %2
%34 = call i32 @fread(i8* %32, i32 1, i32 1, i32* %33)
%35 = load i8*, i8** %4
%36 = load i32*, i32** %3
%37 = call i32 @fwrite(i8* %35, i32 1, i32 1, i32* %36)
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
%40 = load i32*, i32** %2
%41 = call i32 @fclose(i32* %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %43
43: ; preds = %18, %15, %8
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [12 x i8] c"fakebmp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Error 1002: Could not open file!\0A\00"
@.str.3 = [16 x i8] c"out_fakebmp.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [38 x i8] c"Error 1003: Could not write to file!\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %29
6: ; preds = %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
br label %29
12: ; preds = %6
%13 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
%14 = tail call i32 @fread(i8* %13, i32 1, i32 1, i32* %1)
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
%17 = tail call i32 @fputc(i32 %16, i32* %7)
%18 = tail call i32 @fread(i8* %13, i32 1, i32 1, i32* %1)
%19 = load i8, i8* %13
%20 = sext i8 %19 to i32
%21 = tail call i32 @fputc(i32 %20, i32* %7)
%22 = tail call i32 @fread(i8* %13, i32 1, i32 1, i32* %1)
%23 = load i8, i8* %13
%24 = sext i8 %23 to i32
%25 = tail call i32 @fputc(i32 %24, i32* %7)
%26 = tail call i32 @free(i8* %13)
%27 = tail call i32 @fclose(i32* %1)
%28 = tail call i32 @putchar(i32 10)
br label %29
29: ; preds = %9, %12, %3
%30 = phi i32 [ 1002, %3 ], [ 1003, %9 ], [ 0, %12 ]
ret i32 %30
}