#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*/ WritePic(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char tolower(char);
int main(int argc, char **argv) {
  int i;
  char name[256];
  FILE *st;
  int pf;
  if (argc < 2) {
    printf("Usage: BMP2C [/p] name1.bmp...\n");
    printf("name may contain wildcards\n");
    printf("/p will insert patch style offsets, else 0\n");
    exit(1);
  }
  st = fopen("cdata.c", "w");
  if (st) {
    pf = 0;
    if (argv[1][0] == '-' || argv[1][0] == '/' && tolower(argv[1][1]) == 'p')
      pf = 1;
    for (i = 1 + pf; i < argc; i++) {
      strcpy(name, argv[i]);
      WritePic(name, st, pf);
    }
  } else
    fprintf(stderr, "Cannot open CDATA.C for output\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x51>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xea0(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     129e <main+0x12e>
movl   $0x0,-0x12c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1238 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1242 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%edi
call   1070 <tolower@plt>
movsbl %al,%eax
cmp    $0x70,%eax
jne    1242 <main+0xd2>
movl   $0x1,-0x12c(%rbp)
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1299 <main+0x129>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    -0x12c(%rbp),%edx
call   1040 <WritePic@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124e <main+0xde>
jmp    12b3 <main+0x143>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
cmp    $0x1,%edi
jle    122e <main+0xbe>
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xe69(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1205 <main+0x95>
mov    %rax,%r12
mov    0x8(%r14),%rax
mov    (%rax),%cl
cmp    $0x2d,%cl
je     11cb <main+0x5b>
xor    %r13d,%r13d
cmp    $0x2f,%cl
jne    11d1 <main+0x61>
movsbl 0x1(%rax),%edi
call   1070 <tolower@plt>
cmp    $0x70,%al
jne    11d1 <main+0x61>
mov    $0x1,%r13d
lea    0x1(%r13),%ebp
cmp    %r15d,%ebp
jae    121a <main+0xaa>
mov    %r15d,%r15d
mov    %rsp,%rbx
mov    (%r14,%rbp,8),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1050 <WritePic@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11e0 <main+0x70>
jmp    121a <main+0xaa>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf5(%rip),%rdi
call   1040 <puts@plt>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: BMP2C [/p] name1.bmp...\0A\00"
@.str.1 = [28 x i8] c"name may contain wildcards\0A\00"
@.str.2 = [44 x i8] c"/p will insert patch style offsets, else 0\0A\00"
@.str.3 = [8 x i8] c"cdata.c\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [32 x i8] c"Cannot open CDATA.C for output\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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* %18, i32** %8
%19 = load i32*, i32** %8
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %70
21: ; preds = %17
store i32 0, i32* %9
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 45
br i1 %28, label %46, label %29
29: ; preds = %21
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %47
37: ; preds = %29
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = call signext i8 @tolower(i8 signext %42)
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 112
br i1 %45, label %46, label %47
46: ; preds = %37, %21
store i32 1, i32* %9
br label %47
47: ; preds = %46, %37, %29
%48 = load i32, i32* %9
%49 = add nsw i32 1, %48
store i32 %49, i32* %6
br label %50
50: ; preds = %66, %47
%51 = load i32, i32* %6
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %69
54: ; preds = %50
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%56 = load i8**, i8*** %5
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @strcpy(i8* %55, i8* %60)
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%63 = load i32*, i32** %8
%64 = load i32, i32* %9
%65 = call i32 @WritePic(i8* %62, i32* %63, i32 %64)
br label %66
66: ; preds = %54
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %50
69: ; preds = %50
br label %73
70: ; preds = %17
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %73
73: ; preds = %70, %69
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [8 x i8] c"cdata.c\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [32 x i8] c"Cannot open CDATA.C for output\0A\00"
@str = [31 x i8] c"Usage: BMP2C [/p] name1.bmp...\00"
@str.6 = [27 x i8] c"name may contain wildcards\00"
@str.7 = [43 x i8] c"/p will insert patch style offsets, else 0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.7, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %40, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
switch i8 %17, label %24 [
i8 45, label %23
i8 47, label %18
]
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %16, i64 1
%20 = load i8, i8* %19
%21 = tail call signext i8 @tolower(i8 signext %20)
%22 = icmp eq i8 %21, 112
br i1 %22, label %23, label %24
23: ; preds = %14, %18
br label %24
24: ; preds = %14, %23, %18
%25 = phi i32 [ 1, %23 ], [ 0, %18 ], [ 0, %14 ]
%26 = add nuw nsw i32 %25, 1
%27 = icmp ult i32 %26, %0
br i1 %27, label %28, label %43
28: ; preds = %24
%29 = add nuw nsw i32 %25, 1
%30 = zext i32 %29 to i64
%31 = zext i32 %0 to i64
br label %32
32: ; preds = %28, %32
%33 = phi i64 [ %30, %28 ], [ %38, %32 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @strcpy(i8* %4, i8* %35)
%37 = call i32 @WritePic(i8* %4, i32* %12, i32 %25)
%38 = add nuw nsw i64 %33, 1
%39 = icmp eq i64 %38, %31
br i1 %39, label %43, label %32
40: ; preds = %11
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %32, %24, %40
ret i32 0
}