#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ convertCase(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fread(char *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
char *getName(char *);
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
int /*<<< orphan*/ *stderr;
scalar_t__ strlen(char const *);
int main(int argc, char *argv[]) {
  FILE *file;
  char *buffer;
  unsigned long fileLen;
  int i;
  long words;
  int bytes;
  unsigned long index;
  const char *output_dir;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <input>.so (output_dir)\n", argv[0]);
    return -1;
  }
  if (argc < 3) {
    output_dir = "";
  } else {
    output_dir = argv[2];
  }
  file = fopen(argv[1], "rb");
  if (!file) {
    fprintf(stderr, "Unable to open input file %s", argv[1]);
    return -1;
  }
  char *aa_name = getName(argv[1]);
  if (!aa_name) {
    fprintf(stderr, "Memory error!");
    fclose(file);
    return -1;
  }
  fseek(file, 0, SEEK_END);
  fileLen = ftell(file);
  fseek(file, 0, SEEK_SET);
  buffer = (char *)malloc(fileLen + 1);
  if (!buffer) {
    fprintf(stderr, "Memory error!");
    free(aa_name);
    fclose(file);
    return -1;
  }
  fread(buffer, fileLen, 1, file);
  fclose(file);
  char output_filename[strlen(output_dir) + 1 + strlen(aa_name) + 3];
  sprintf(output_filename, "%s/%s.h", output_dir, aa_name);
  file = fopen(output_filename, "w");
  if (!file) {
    fprintf(stderr, "Unable to create output file %s", output_filename);
    free(aa_name);
    free(buffer);
    return -1;
  }
  fprintf(file,
          "/**\n * Murac software framework\n * \n * Header file for '%s'\n * "
          "Author: Brandon Hamilton <brandon.hamilton@gmail.com>\n */\n\n",
          aa_name);
  convertCase(aa_name);
  fprintf(file, "#ifndef %s_H\n#define %s_H\n\n", aa_name, aa_name);
  fprintf(file, "#define EXECUTE_%s int _lib_length = %d;\\\n", aa_name,
          fileLen);
  fprintf(file, "  asm volatile(\"mov r1,%[value]\" : : "
                "[value]\"r\"(_lib_length) : \"r1\"); \\\n");
  fprintf(file, "  asm volatile(\".align 4\\n\\t\" \\\n");
  fprintf(file, "    \".word 0xE12FFF41\\n\\t\" \\\n");
  words = fileLen / 4;
  bytes = fileLen % 4;
  index = 0;
  for (i = 0; i < words; i++) {
    fprintf(file, "  \".word 0x%x\\n\\t\" \\\n",
            *(unsigned int *)&buffer[index]);
    index += 4;
  }
  unsigned int last_word = 0;
  for (i = 0; i < bytes; i++) {
    last_word |= (buffer[index++]) << 24 - (i * 8);
  }
  fprintf(file, "  \".word 0x%x\\n\\t\" \\\n", last_word);
  fprintf(file, "  );");
  fprintf(file, "\n#endif // %s_H\n", aa_name);
  fclose(file);
  free(aa_name);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    120e <main+0x4e>
mov    0x2dee(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15de <main+0x41e>
cmpl   $0x3,-0x8(%rbp)
jge    1228 <main+0x68>
lea    0xed6(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1234 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde0(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1283 <main+0xc3>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15de <main+0x41e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <getName@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    12cc <main+0x10c>
mov    0x2d32(%rip),%rax
mov    (%rax),%rdi
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15de <main+0x41e>
mov    -0x18(%rbp),%rdi
mov    0x2d11(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2cd8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1353 <main+0x193>
mov    0x2cb4(%rip),%rax
mov    (%rax),%rdi
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15de <main+0x41e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x58(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x80(%rbp),%rcx
mov    %rax,%rdx
lea    0x4(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x60(%rbp)
lea    0x13(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x78(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%rcx
lea    0xc8d(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x78(%rbp),%rdi
lea    0xc85(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1429 <main+0x269>
mov    -0x78(%rbp),%rdx
mov    0x2be5(%rip),%rax
mov    (%rax),%rdi
lea    0xc5e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15d7 <main+0x417>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xc43(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   10b0 <convertCase@plt>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x58(%rbp),%rcx
lea    0xc9b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xc9d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xcb6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xcfc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
and    $0x3,%rax
mov    %eax,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    151d <main+0x35d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,1),%edx
lea    0xcc9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14d8 <main+0x318>
movl   $0x0,-0x70(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1571 <main+0x3b1>
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x48(%rbp)
movsbl (%rax,%rcx,1),%eax
mov    -0x2c(%rbp),%edx
shl    $0x3,%edx
mov    $0x18,%ecx
sub    %edx,%ecx
shl    %cl,%eax
or     -0x70(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    152b <main+0x36b>
mov    -0x18(%rbp),%rdi
mov    -0x70(%rbp),%edx
lea    0xc46(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xc4a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xc39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1202 <main+0x32>
mov    0x2de8(%rip),%rax
mov    (%rax),%rdi
mov    (%rbx),%rdx
lea    0xe03(%rip),%rsi
jmp    13c1 <main+0x1f1>
cmp    $0x2,%edi
jne    1210 <main+0x40>
lea    0xee7(%rip),%r12
jmp    1214 <main+0x44>
mov    0x10(%rbx),%r12
mov    0x8(%rbx),%rdi
lea    0xe04(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     13ac <main+0x1dc>
mov    %rax,%r13
mov    0x8(%rbx),%rdi
call   10c0 <getName@plt>
test   %rax,%rax
je     13d2 <main+0x202>
mov    %rax,%r14
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r13,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbx
mov    0x2d66(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
lea    0x1(%rbx),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     13f4 <main+0x224>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rsp,-0x40(%rbp)
add    %r13,%rax
add    $0x13,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
lea    0xd79(%rip),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
call   10e0 <sprintf@plt>
lea    0xd6c(%rip),%rsi
mov    %r13,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     142e <main+0x25e>
mov    %rax,%r12
lea    0xd73(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   10b0 <convertCase@plt>
lea    0xdd2(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdd7(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdeb(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe23(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10f0 <fwrite@plt>
lea    0xe2b(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10f0 <fwrite@plt>
mov    %ebx,%eax
and    $0x3,%eax
cmp    $0x4,%rbx
mov    %r14,-0x38(%rbp)
mov    %eax,-0x2c(%rbp)
jae    1463 <main+0x293>
xor    %r14d,%r14d
jmp    149b <main+0x2cb>
mov    0x2c25(%rip),%rax
mov    (%rax),%rdi
mov    0x8(%rbx),%rdx
lea    0xc65(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1533 <main+0x363>
mov    0x2bff(%rip),%rax
mov    (%rax),%rcx
lea    0xc60(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
call   10f0 <fwrite@plt>
jmp    141c <main+0x24c>
mov    0x2bdd(%rip),%rax
mov    (%rax),%rcx
lea    0xc3e(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
call   10f0 <fwrite@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%ebx
jmp    1533 <main+0x363>
mov    0x2ba3(%rip),%rax
mov    (%rax),%rdi
lea    0xc1c(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%ebx
jmp    152f <main+0x35f>
shr    $0x2,%rbx
lea    0xd57(%rip),%r13
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%r14,1),%edx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x4,%r14
add    $0xffffffffffffffff,%rbx
jne    1480 <main+0x2b0>
mov    -0x2c(%rbp),%ecx
test   %ecx,%ecx
mov    $0x0,%edx
je     14d3 <main+0x303>
movzbl (%r15,%r14,1),%edx
shl    $0x18,%edx
cmp    $0x1,%ecx
je     14d3 <main+0x303>
movsbl 0x1(%r14,%r15,1),%eax
shl    $0x10,%eax
or     %edx,%eax
cmp    $0x2,%ecx
jne    14c8 <main+0x2f8>
mov    %eax,%edx
jmp    14d3 <main+0x303>
movsbl 0x2(%r14,%r15,1),%edx
shl    $0x8,%edx
or     %eax,%edx
lea    0xceb(%rip),%rsi
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xcee(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10f0 <fwrite@plt>
lea    0xcda(%rip),%rsi
mov    %r12,%rdi
mov    -0x38(%rbp),%r14
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32* null
@.str = [35 x i8] c"Usage: %s <input>.so (output_dir)\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [29 x i8] c"Unable to open input file %s\00"
@.str.4 = [14 x i8] c"Memory error!\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [8 x i8] c"%s/%s.h\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [32 x i8] c"Unable to create output file %s\00"
@.str.8 = [123 x i8] c"/**\0A * Murac software framework\0A * \0A * Header file for '%s'\0A * Author: Brandon Hamilton <brandon.hamilton@gmail.com>\0A */\0A\0A\00"
@.str.9 = [28 x i8] c"#ifndef %s_H\0A#define %s_H\0A\0A\00"
@.str.10 = [43 x i8] c"#define EXECUTE_%s int _lib_length = %d;\\\0A\00"
@.str.11 = [73 x i8] c" asm volatile(\22mov r1,%[value]\22 : : [value]\22r\22(_lib_length) : \22r1\22); \\\0A\00"
@.str.12 = [33 x i8] c" asm volatile(\22.align 4\\n\\t\22 \\\0A\00"
@.str.13 = [30 x i8] c" \22.word 0xE12FFF41\\n\\t\22 \\\0A\00"
@.str.14 = [22 x i8] c" \22.word 0x%x\\n\\t\22 \\\0A\00"
@.str.15 = [5 x i8] c" );\00"
@.str.16 = [17 x i8] c"\0A#endif // %s_H\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i32*, i32** @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 -1, i32* %3
br label %192
27: ; preds = %2
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 3
br i1 %29, label %30, label %31
30: ; preds = %27
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %13
br label %35
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
store i8* %34, i8** %13
br label %35
35: ; preds = %31, %30
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %48, label %42
42: ; preds = %35
%43 = load i32*, i32** @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %46)
store i32 -1, i32* %3
br label %192
48: ; preds = %35
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i8* @getName(i8* %51)
store i8* %52, i8** %14
%53 = load i8*, i8** %14
%54 = icmp ne i8* %53, null
br i1 %54, label %60, label %55
55: ; preds = %48
%56 = load i32*, i32** @stderr
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
store i32 -1, i32* %3
br label %192
60: ; preds = %48
%61 = load i32*, i32** %6
%62 = load i32, i32* @SEEK_END
%63 = call i32 @fseek(i32* %61, i32 0, i32 %62)
%64 = load i32*, i32** %6
%65 = call i64 @ftell(i32* %64)
store i64 %65, i64* %8
%66 = load i32*, i32** %6
%67 = load i32, i32* @SEEK_SET
%68 = call i32 @fseek(i32* %66, i32 0, i32 %67)
%69 = load i64, i64* %8
%70 = add i64 %69, 1
%71 = call i64 @malloc(i64 %70)
%72 = inttoptr i64 %71 to i8*
store i8* %72, i8** %7
%73 = load i8*, i8** %7
%74 = icmp ne i8* %73, null
br i1 %74, label %82, label %75
75: ; preds = %60
%76 = load i32*, i32** @stderr
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%78 = load i8*, i8** %14
%79 = call i32 @free(i8* %78)
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
store i32 -1, i32* %3
br label %192
82: ; preds = %60
%83 = load i8*, i8** %7
%84 = load i64, i64* %8
%85 = load i32*, i32** %6
%86 = call i32 @fread(i8* %83, i64 %84, i32 1, i32* %85)
%87 = load i32*, i32** %6
%88 = call i32 @fclose(i32* %87)
%89 = load i8*, i8** %13
%90 = call i64 @strlen(i8* %89)
%91 = add nsw i64 %90, 1
%92 = load i8*, i8** %14
%93 = call i64 @strlen(i8* %92)
%94 = add nsw i64 %91, %93
%95 = add nsw i64 %94, 3
%96 = call i8* @llvm.stacksave()
store i8* %96, i8** %15
%97 = alloca i8, i64 %95
store i64 %95, i64* %16
%98 = load i8*, i8** %13
%99 = load i8*, i8** %14
%100 = call i32 @sprintf(i8* %97, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %98, i8* %99)
%101 = call i32* @fopen(i8* %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %101, i32** %6
%102 = load i32*, i32** %6
%103 = icmp ne i32* %102, null
br i1 %103, label %111, label %104
104: ; preds = %82
%105 = load i32*, i32** @stderr
%106 = call i32 (i32*, i8*, ...) @fprintf(i32* %105, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %97)
%107 = load i8*, i8** %14
%108 = call i32 @free(i8* %107)
%109 = load i8*, i8** %7
%110 = call i32 @free(i8* %109)
store i32 -1, i32* %3
store i32 1, i32* %17
br label %190
111: ; preds = %82
%112 = load i32*, i32** %6
%113 = load i8*, i8** %14
%114 = call i32 (i32*, i8*, ...) @fprintf(i32* %112, i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str.8, i64 0, i64 0), i8* %113)
%115 = load i8*, i8** %14
%116 = call i32 @convertCase(i8* %115)
%117 = load i32*, i32** %6
%118 = load i8*, i8** %14
%119 = load i8*, i8** %14
%120 = call i32 (i32*, i8*, ...) @fprintf(i32* %117, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* %118, i8* %119)
%121 = load i32*, i32** %6
%122 = load i8*, i8** %14
%123 = load i64, i64* %8
%124 = call i32 (i32*, i8*, ...) @fprintf(i32* %121, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0), i8* %122, i64 %123)
%125 = load i32*, i32** %6
%126 = call i32 (i32*, i8*, ...) @fprintf(i32* %125, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.11, i64 0, i64 0))
%127 = load i32*, i32** %6
%128 = call i32 (i32*, i8*, ...) @fprintf(i32* %127, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0))
%129 = load i32*, i32** %6
%130 = call i32 (i32*, i8*, ...) @fprintf(i32* %129, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0))
%131 = load i64, i64* %8
%132 = udiv i64 %131, 4
store i64 %132, i64* %10
%133 = load i64, i64* %8
%134 = urem i64 %133, 4
%135 = trunc i64 %134 to i32
store i32 %135, i32* %11
store i64 0, i64* %12
store i32 0, i32* %9
br label %136
136: ; preds = %151, %111
%137 = load i32, i32* %9
%138 = sext i32 %137 to i64
%139 = load i64, i64* %10
%140 = icmp slt i64 %138, %139
br i1 %140, label %141, label %154
141: ; preds = %136
%142 = load i32*, i32** %6
%143 = load i8*, i8** %7
%144 = load i64, i64* %12
%145 = getelementptr inbounds i8, i8* %143, i64 %144
%146 = bitcast i8* %145 to i32*
%147 = load i32, i32* %146
%148 = call i32 (i32*, i8*, ...) @fprintf(i32* %142, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %147)
%149 = load i64, i64* %12
%150 = add i64 %149, 4
store i64 %150, i64* %12
br label %151
151: ; preds = %141
%152 = load i32, i32* %9
%153 = add nsw i32 %152, 1
store i32 %153, i32* %9
br label %136
154: ; preds = %136
store i32 0, i32* %18
store i32 0, i32* %9
br label %155
155: ; preds = %172, %154
%156 = load i32, i32* %9
%157 = load i32, i32* %11
%158 = icmp slt i32 %156, %157
br i1 %158, label %159, label %175
159: ; preds = %155
%160 = load i8*, i8** %7
%161 = load i64, i64* %12
%162 = add i64 %161, 1
store i64 %162, i64* %12
%163 = getelementptr inbounds i8, i8* %160, i64 %161
%164 = load i8, i8* %163
%165 = sext i8 %164 to i32
%166 = load i32, i32* %9
%167 = mul nsw i32 %166, 8
%168 = sub nsw i32 24, %167
%169 = shl i32 %165, %168
%170 = load i32, i32* %18
%171 = or i32 %170, %169
store i32 %171, i32* %18
br label %172
172: ; preds = %159
%173 = load i32, i32* %9
%174 = add nsw i32 %173, 1
store i32 %174, i32* %9
br label %155
175: ; preds = %155
%176 = load i32*, i32** %6
%177 = load i32, i32* %18
%178 = call i32 (i32*, i8*, ...) @fprintf(i32* %176, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %177)
%179 = load i32*, i32** %6
%180 = call i32 (i32*, i8*, ...) @fprintf(i32* %179, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%181 = load i32*, i32** %6
%182 = load i8*, i8** %14
%183 = call i32 (i32*, i8*, ...) @fprintf(i32* %181, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), i8* %182)
%184 = load i32*, i32** %6
%185 = call i32 @fclose(i32* %184)
%186 = load i8*, i8** %14
%187 = call i32 @free(i8* %186)
%188 = load i8*, i8** %7
%189 = call i32 @free(i8* %188)
store i32 0, i32* %3
store i32 1, i32* %17
br label %190
190: ; preds = %175, %104
%191 = load i8*, i8** %15
br label %192
192: ; preds = %190, %75, %55, %42, %21
%193 = load i32, i32* %3
ret i32 %193
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [35 x i8] c"Usage: %s <input>.so (output_dir)\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [29 x i8] c"Unable to open input file %s\00"
@.str.4 = [14 x i8] c"Memory error!\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [8 x i8] c"%s/%s.h\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [32 x i8] c"Unable to create output file %s\00"
@.str.8 = [123 x i8] c"/**\0A * Murac software framework\0A * \0A * Header file for '%s'\0A * Author: Brandon Hamilton <brandon.hamilton@gmail.com>\0A */\0A\0A\00"
@.str.9 = [28 x i8] c"#ifndef %s_H\0A#define %s_H\0A\0A\00"
@.str.10 = [43 x i8] c"#define EXECUTE_%s int _lib_length = %d;\\\0A\00"
@.str.11 = [73 x i8] c" asm volatile(\22mov r1,%[value]\22 : : [value]\22r\22(_lib_length) : \22r1\22); \\\0A\00"
@.str.12 = [33 x i8] c" asm volatile(\22.align 4\\n\\t\22 \\\0A\00"
@.str.13 = [30 x i8] c" \22.word 0xE12FFF41\\n\\t\22 \\\0A\00"
@.str.14 = [22 x i8] c" \22.word 0x%x\\n\\t\22 \\\0A\00"
@.str.15 = [5 x i8] c" );\00"
@.str.16 = [17 x i8] c"\0A#endif // %s_H\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %120
8: ; preds = %2
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
br label %13
13: ; preds = %8, %10
%14 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %8 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32*, i32** @stderr
%21 = load i8*, i8** %15
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %120
23: ; preds = %13
%24 = load i8*, i8** %15
%25 = tail call i8* @getName(i8* %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32*, i32** @stderr
%29 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i64 13, i64 1, i32* %28)
%30 = tail call i32 @fclose(i32* %17)
br label %120
31: ; preds = %23
%32 = load i32, i32* @SEEK_END
%33 = tail call i32 @fseek(i32* %17, i32 0, i32 %32)
%34 = tail call i64 @ftell(i32* %17)
%35 = load i32, i32* @SEEK_SET
%36 = tail call i32 @fseek(i32* %17, i32 0, i32 %35)
%37 = add i64 %34, 1
%38 = tail call i64 @malloc(i64 %37)
%39 = inttoptr i64 %38 to i8*
%40 = icmp eq i64 %38, 0
br i1 %40, label %41, label %46
41: ; preds = %31
%42 = load i32*, i32** @stderr
%43 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i64 13, i64 1, i32* %42)
%44 = tail call i32 @free(i8* %25)
%45 = tail call i32 @fclose(i32* %17)
br label %120
46: ; preds = %31
%47 = tail call i32 @fread(i8* %39, i64 %34, i32 1, i32* %17)
%48 = tail call i32 @fclose(i32* %17)
%49 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%50 = tail call i64 @strlen(i8* %25)
%51 = add i64 %49, 4
%52 = add i64 %51, %50
%53 = tail call i8* @llvm.stacksave()
%54 = alloca i8, i64 %52
%55 = call i32 @sprintf(i8* %54, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %14, i8* %25)
%56 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %63
58: ; preds = %46
%59 = load i32*, i32** @stderr
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%61 = call i32 @free(i8* %25)
%62 = call i32 @free(i8* %39)
br label %118
63: ; preds = %46
%64 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str.8, i64 0, i64 0), i8* %25)
%65 = tail call i32 @convertCase(i8* %25)
%66 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* %25, i8* %25)
%67 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0), i8* %25, i64 %34)
%68 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.11, i64 0, i64 0))
%69 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0), i64 32, i64 1, i32* %56)
%70 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0), i64 29, i64 1, i32* %56)
%71 = trunc i64 %34 to i32
%72 = and i32 %71, 3
%73 = icmp ult i64 %34, 4
br i1 %73, label %76, label %74
74: ; preds = %63
%75 = lshr i64 %34, 2
br label %79
76: ; preds = %79, %63
%77 = phi i64 [ 0, %63 ], [ %86, %79 ]
%78 = icmp eq i32 %72, 0
br i1 %78, label %110, label %89
79: ; preds = %74, %79
%80 = phi i64 [ 0, %74 ], [ %87, %79 ]
%81 = phi i64 [ 0, %74 ], [ %86, %79 ]
%82 = getelementptr inbounds i8, i8* %39, i64 %81
%83 = bitcast i8* %82 to i32*
%84 = load i32, i32* %83
%85 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %84)
%86 = add nuw i64 %81, 4
%87 = add nuw nsw i64 %80, 1
%88 = icmp eq i64 %87, %75
br i1 %88, label %76, label %79
89: ; preds = %76
%90 = getelementptr inbounds i8, i8* %39, i64 %77
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = shl nuw i32 %92, 24
%94 = icmp eq i32 %72, 1
br i1 %94, label %110, label %95
95: ; preds = %89
%96 = add nsw i64 %77, 1
%97 = getelementptr inbounds i8, i8* %39, i64 %96
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = shl nsw i32 %99, 16
%101 = or i32 %100, %93
%102 = icmp eq i32 %72, 2
br i1 %102, label %110, label %103
103: ; preds = %95
%104 = add nsw i64 %77, 2
%105 = getelementptr inbounds i8, i8* %39, i64 %104
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = shl nsw i32 %107, 8
%109 = or i32 %108, %101
br label %110
110: ; preds = %89, %95, %103, %76
%111 = phi i32 [ 0, %76 ], [ %93, %89 ], [ %101, %95 ], [ %109, %103 ]
%112 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %111)
%113 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), i64 4, i64 1, i32* %56)
%114 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), i8* %25)
%115 = tail call i32 @fclose(i32* %56)
%116 = tail call i32 @free(i8* %25)
%117 = tail call i32 @free(i8* %39)
br label %118
118: ; preds = %110, %58
%119 = phi i32 [ 0, %110 ], [ -1, %58 ]
br label %120
120: ; preds = %27, %41, %118, %19, %4
%121 = phi i32 [ -1, %4 ], [ -1, %19 ], [ %119, %118 ], [ -1, %41 ], [ -1, %27 ]
ret i32 %121
}