#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 uint8_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ readBMPdumpBMP(char *);
int /*<<< orphan*/ readBMPdumpCOLOR(int, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("\n");
    printf("Usage : ./bmp2array <opt num> <bmp file name>\n");
    printf("        <opt num>           <action>\n");
    printf("            1               generate bmp array\n");
    printf("            2               generate color array\n");
    printf("            3               generate color file\n\n");
    return -1;
  }
  printf("\n\n{\n");
  uint8_t opt = atoi(argv[1]);
  if (opt == 1) {
    readBMPdumpBMP(argv[2]);
  } else if (opt == 2) {
    readBMPdumpCOLOR(0, argv[2]);
  } else if (opt == 3) {
    readBMPdumpCOLOR(1, argv[2]);
  }
  printf("\n}\n\n");
  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    11b4 <main+0x74>
lea    0xf80(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
call   1030 <printf@plt>
lea    0xf14(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <main+0x103>
lea    0xf2e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11ec <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <readBMPdumpBMP@plt>
jmp    1230 <main+0xf0>
cmpl   $0x2,-0x14(%rbp)
jne    120a <main+0xca>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
xor    %edi,%edi
call   1050 <readBMPdumpCOLOR@plt>
jmp    122b <main+0xeb>
cmpl   $0x3,-0x14(%rbp)
jne    1226 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x1,%edi
call   1050 <readBMPdumpCOLOR@plt>
jmp    122b <main+0xeb>
jmp    1230 <main+0xf0>
lea    0xeb7(%rip),%rdi
call   1030 <printf@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
cmp    $0x2,%edi
jg     11a1 <main+0x51>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
lea    0xf1c(%rip),%r14
jmp    11f4 <main+0xa4>
mov    %rsi,%rbx
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
xor    %ebp,%ebp
lea    0xe42(%rip),%r14
cmp    $0x3,%eax
je     11dc <main+0x8c>
cmp    $0x2,%eax
je     11e7 <main+0x97>
cmp    $0x1,%eax
jne    11f4 <main+0xa4>
mov    0x10(%rbx),%rdi
call   1050 <readBMPdumpBMP@plt>
jmp    11f4 <main+0xa4>
mov    0x10(%rbx),%rsi
mov    $0x1,%edi
jmp    11ef <main+0x9f>
mov    0x10(%rbx),%rsi
xor    %ebp,%ebp
xor    %edi,%edi
call   1060 <readBMPdumpCOLOR@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [47 x i8] c"Usage : ./bmp2array <opt num> <bmp file name>\0A\00"
@.str.2 = [38 x i8] c" <opt num> <action>\0A\00"
@.str.3 = [48 x i8] c" 1 generate bmp array\0A\00"
@.str.4 = [50 x i8] c" 2 generate color array\0A\00"
@.str.5 = [50 x i8] c" 3 generate color file\0A\0A\00"
@.str.6 = [5 x i8] c"\0A\0A{\0A\00"
@.str.7 = [5 x i8] c"\0A}\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @readBMPdumpBMP(i8* %27)
br label %47
29: ; preds = %16
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @readBMPdumpCOLOR(i32 0, i8* %35)
br label %46
37: ; preds = %29
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, 3
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @readBMPdumpCOLOR(i32 1, i8* %43)
br label %45
45: ; preds = %40, %37
br label %46
46: ; preds = %45, %32
br label %47
47: ; preds = %46, %24
%48 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %49
49: ; preds = %47, %9
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@str = [4 x i8] c"\0A\0A{\00"
@str.8 = [4 x i8] c"\0A}\0A\00"
@str.9 = [46 x i8] c"Usage : ./bmp2array <opt num> <bmp file name>\00"
@str.10 = [37 x i8] c" <opt num> <action>\00"
@str.11 = [47 x i8] c" 1 generate bmp array\00"
@str.12 = [49 x i8] c" 2 generate color array\00"
@str.13 = [49 x i8] c" 3 generate color file\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = tail call i32 @putchar(i32 10)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.9, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.11, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.12, i64 0, i64 0))
br label %27
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
switch i32 %14, label %27 [
i32 1, label %15
i32 2, label %19
i32 3, label %23
]
15: ; preds = %10
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @readBMPdumpBMP(i8* %17)
br label %27
19: ; preds = %10
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @readBMPdumpCOLOR(i32 0, i8* %21)
br label %27
23: ; preds = %10
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @readBMPdumpCOLOR(i32 1, i8* %25)
br label %27
27: ; preds = %15, %23, %19, %10, %4
%28 = phi i8* [ getelementptr inbounds ([49 x i8], [49 x i8]* @str.13, i64 0, i64 0), %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0), %10 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0), %19 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0), %23 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0), %15 ]
%29 = phi i32 [ -1, %4 ], [ 0, %10 ], [ 0, %19 ], [ 0, %23 ], [ 0, %15 ]
%30 = tail call i32 @puts(i8* dereferenceable(1) %28)
ret i32 %29
}