#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*/ MakeBMP(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int main(int ac, char **av) {
  FILE *ifp;
  FILE *ofp;
  if (ac < 3) {
    fprintf(stderr, "Usage: makebmp <infile> <outfile>\n");
    exit(1);
  }
  ifp = fopen(av[1], "rb");
  if (!ifp) {
    fprintf(stderr, "Can't open file: %s\n", av[1]);
    exit(1);
  }
  ofp = fopen(av[2], "wb");
  if (!ofp) {
    fprintf(stderr, "Can't create file: %s\n", av[2]);
    exit(1);
  }
  if (!MakeBMP(ifp, ofp)) {
    fprintf(stderr, "Conversion failed: %s\n", av[2]);
    fclose(ofp);
    unlink(av[2]);
    exit(1);
  }
  fclose(ifp);
  fclose(ofp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ed <main+0x8d>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1239 <main+0xd9>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <MakeBMP@plt>
cmp    $0x0,%eax
jne    128e <main+0x12e>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jle    11c4 <main+0x64>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xeab(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e5 <main+0x85>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xeab(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fb <main+0x9b>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <MakeBMP@plt>
test   %eax,%eax
je     1220 <main+0xc0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe2d(%rip),%rsi
jmp    120f <main+0xaf>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
lea    0xe2f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
lea    0xe21(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x10(%r14),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: makebmp <infile> <outfile>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"Can't open file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [23 x i8] c"Can't create file: %s\0A\00"
@.str.5 = [23 x i8] c"Conversion failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %28, label %21
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %14
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
br i1 %34, label %42, label %35
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %28
%43 = load i32*, i32** %6
%44 = load i32*, i32** %7
%45 = call i32 @MakeBMP(i32* %43, i32* %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %60, label %47
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @unlink(i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %42
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: makebmp <infile> <outfile>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"Can't open file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [23 x i8] c"Can't create file: %s\0A\00"
@.str.5 = [23 x i8] c"Conversion failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %8
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %19
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = tail call i32 @MakeBMP(i32* %11, i32* %21)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %19
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = tail call i32 @fclose(i32* %21)
%36 = load i8*, i8** %19
%37 = tail call i32 @unlink(i8* %36)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %28
%40 = tail call i32 @fclose(i32* %11)
%41 = tail call i32 @fclose(i32* %21)
ret i32 0
}