#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 size_t uint8_t;
typedef int uint32_t;
typedef char int8_t;

/* Variables and functions */
size_t F_ConvertAsciiToNumeric(char const);
int F_TransformHexIntelFileToBin(char *, int, char *, size_t, int, size_t);
int atoi(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
int main(int argc, char const **argv) {
  uint8_t VF_ArrayPos = 0;
  int8_t *S_HexFile = 0;
  int8_t *S_BinFile = 0;
  int8_t VP_argbPos = 0;
  uint32_t VP_MemoryInitAddress = 0;
  uint32_t VP_MemorySize = 256 * 1024;
  uint8_t VP_FillPathern = 0xFF;
  uint8_t VP_EndianessBits = 0;
  if (argc <= 1) {
    fprintf(stderr,
            "\n"
            "Usage: hex2bin.exe filename.hex filename.bin [OPTIONS] \n"
            "Example: hex2bin.exe myhex.hex mybin.bin /A:1FF /F:FF /S:256 \n"
            "Options:\n"
            "  /S [Size]  Size in kB of the .bin file, decimal value. Default "
            "value: 256\n"
            "  /F [Fill]  Fill pattern. Default value FF\n"
            "  /A [start Address] Starting Address of the memory, hexadecimal "
            "value. Default value 0\n"
            "  /L [Little Endian] If the data in the hex file is written in "
            "little endian you should include this parameter "
            "with the number of bits of each register. For example /L:16 "
            "(little endian with 16bit register). "
            "default parameter is big endian, in big endian the size of the "
            "register is not necessary. \n\n"
            "Return values: \n"
            "OK = 1 \n"
            "End of file record not found in .hex file = 0 \n"
            "File not found = -1 \n"
            "Checksum Error = -2 \n"
            "Incompatible File = -3 \n"
            "Memory Allocation = -4 \n"
            "Endianness Bits must be 8 multiple = -5 \n");
    return 0;
  }
  S_HexFile =
      (int8_t *)malloc((strlen(argv[0]) + strlen(argv[1])) * sizeof(int8_t));
  S_BinFile = (int8_t *)malloc((strlen(argv[0]) + strlen(argv[2]) + 20) *
                               sizeof(int8_t));
  strcpy((char *)S_HexFile, argv[0]);
  strcpy((char *)S_BinFile, argv[0]);
  VF_ArrayPos = strlen((const char *)S_HexFile);
  while (VF_ArrayPos > 0) {
    if (S_HexFile[VF_ArrayPos] == '\\') {
      break;
    }
    VF_ArrayPos--;
  }
  if (VF_ArrayPos != 0) {
    VF_ArrayPos++;
  }
  strcpy((char *)&S_HexFile[VF_ArrayPos], argv[1]);
  strcpy((char *)&S_BinFile[VF_ArrayPos], argv[2]);
  for (VP_argbPos = 3; VP_argbPos < argc; VP_argbPos++) {
    if (argv[VP_argbPos][1] == 'A' && argv[VP_argbPos][2] == ':') {
      for (VF_ArrayPos = 0; VF_ArrayPos < strlen(&argv[VP_argbPos][3]);
           VF_ArrayPos++) {
        VP_MemoryInitAddress =
            (VP_MemoryInitAddress << 4) +
            F_ConvertAsciiToNumeric(argv[VP_argbPos][VF_ArrayPos + 3]);
      }
    }
    if (argv[VP_argbPos][1] == 'S' && argv[VP_argbPos][2] == ':') {
      VP_MemorySize = atoi(&argv[VP_argbPos][3]) * 1024;
    }
    if (argv[VP_argbPos][1] == 'F' && argv[VP_argbPos][2] == ':') {
      VP_FillPathern = 0;
      for (VF_ArrayPos = 0; VF_ArrayPos < 2; VF_ArrayPos++) {
        VP_FillPathern =
            (VP_FillPathern << 4) +
            F_ConvertAsciiToNumeric(argv[VP_argbPos][VF_ArrayPos + 3]);
      }
    }
    if (argv[VP_argbPos][1] == 'L' && argv[VP_argbPos][2] == ':') {
      VP_EndianessBits = atoi(&argv[VP_argbPos][3]);
    }
  }
  printf("Result: %d", F_TransformHexIntelFileToBin(
                           S_HexFile, VP_MemorySize, S_BinFile, VP_FillPathern,
                           VP_MemoryInitAddress, VP_EndianessBits));
  free(S_HexFile);
  free(S_BinFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x40000,-0x34(%rbp)
movq   $0xff,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     120b <main+0x7b>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1573 <main+0x3e3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
add    $0x14,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    12de <main+0x14e>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    12cd <main+0x13d>
jmp    12de <main+0x14e>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    12a8 <main+0x118>
cmpq   $0x0,-0x18(%rbp)
je     12f5 <main+0x165>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <strcpy@plt>
movb   $0x3,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1530 <main+0x3a0>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x41,%eax
jne    13e4 <main+0x254>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
cmp    $0x3a,%eax
jne    13e4 <main+0x254>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x3,%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
cmp    %rcx,%rax
jae    13df <main+0x24f>
mov    -0x30(%rbp),%eax
shl    $0x4,%eax
cltq
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x18(%rbp),%rcx
movsbl 0x3(%rax,%rcx,1),%edi
call   1090 <F_ConvertAsciiToNumeric@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    136c <main+0x1dc>
jmp    13e4 <main+0x254>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x53,%eax
jne    1434 <main+0x2a4>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
cmp    $0x3a,%eax
jne    1434 <main+0x2a4>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x3,%rdi
call   10a0 <atoi@plt>
shl    $0xa,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x46,%eax
jne    14ce <main+0x33e>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
cmp    $0x3a,%eax
jne    14ce <main+0x33e>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x2,-0x18(%rbp)
jae    14c9 <main+0x339>
mov    -0x40(%rbp),%rax
shl    $0x4,%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x18(%rbp),%rcx
movsbl 0x3(%rax,%rcx,1),%edi
call   1090 <F_ConvertAsciiToNumeric@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1478 <main+0x2e8>
jmp    14ce <main+0x33e>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x4c,%eax
jne    151e <main+0x38e>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
cmp    $0x3a,%eax
jne    151e <main+0x38e>
mov    -0x10(%rbp),%rax
movsbq -0x29(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x3,%rdi
call   10a0 <atoi@plt>
cltq
mov    %rax,-0x48(%rbp)
jmp    1523 <main+0x393>
mov    -0x29(%rbp),%al
add    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    1323 <main+0x193>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%r8d
mov    -0x48(%rbp),%r9
call   10b0 <F_TransformHexIntelFileToBin@plt>
mov    %eax,%esi
lea    0xdf2(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x1,%edi
jg     11bd <main+0x2d>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1427 <main+0x297>
mov    %rsi,%r15
mov    %edi,0x14(%rsp)
mov    (%rsi),%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    0x8(%r15),%rdi
call   1050 <strlen@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    (%r15),%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    0x10(%r15),%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbx,1),%edi
add    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    (%r15),%rsi
mov    %rbx,0x28(%rsp)
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1252 <main+0xc2>
mov    %rax,%rbx
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
cmpb   $0x5c,-0x1(%r14,%rbx,1)
je     1254 <main+0xc4>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jne    1240 <main+0xb0>
xor    %ebx,%ebx
mov    %r14,0x30(%rsp)
add    %rbx,%r14
mov    0x8(%r15),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    0x28(%rsp),%rdi
add    %rbx,%rdi
mov    0x10(%r15),%rsi
call   1040 <strcpy@plt>
mov    0x14(%rsp),%r14d
cmp    $0x4,%r14d
jl     13ca <main+0x23a>
mov    $0x3,%bl
xor    %eax,%eax
mov    %rax,0x18(%rsp)
movl   $0x40000,0x10(%rsp)
mov    $0xff,%eax
mov    %rax,0x20(%rsp)
xor    %ebp,%ebp
jmp    12bf <main+0x12f>
nopw   0x0(%rax,%rax,1)
add    $0x1,%bl
movsbl %bl,%eax
cmp    %r14d,%eax
jge    13e3 <main+0x253>
movsbq %bl,%r12
mov    (%r15,%r12,8),%r13
mov    0x1(%r13),%al
cmp    $0x41,%al
jne    1331 <main+0x1a1>
cmpb   $0x3a,0x2(%r13)
jne    12b0 <main+0x120>
lea    0x3(%r13),%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     12b0 <main+0x120>
mov    %bl,0xf(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15,%r14
mov    %ebp,%r15d
shl    $0x4,%r15d
movsbl 0x3(%r13,%rbx,1),%edi
call   1090 <F_ConvertAsciiToNumeric@plt>
mov    %rax,%rbp
add    %r15d,%ebp
mov    %r14,%r15
add    $0x1,%rbx
mov    (%r14,%r12,8),%r13
lea    0x3(%r13),%rdi
call   1050 <strlen@plt>
cmp    %rax,%rbx
jb     12f0 <main+0x160>
mov    0x1(%r13),%al
mov    0x14(%rsp),%r14d
mov    0xf(%rsp),%bl
cmp    $0x46,%al
je     1360 <main+0x1d0>
cmp    $0x53,%al
jne    139f <main+0x20f>
cmpb   $0x3a,0x2(%r13)
jne    12b0 <main+0x120>
add    $0x3,%r13
mov    %r13,%rdi
call   10a0 <atoi@plt>
shl    $0xa,%eax
mov    %eax,0x10(%rsp)
jmp    12b0 <main+0x120>
nopl   0x0(%rax)
cmpb   $0x3a,0x2(%r13)
jne    12b0 <main+0x120>
movsbl 0x3(%r13),%edi
call   1090 <F_ConvertAsciiToNumeric@plt>
mov    %ebx,%r13d
mov    %rax,%rbx
shl    $0x4,%rbx
mov    (%r15,%r12,8),%rax
movsbl 0x4(%rax),%edi
call   1090 <F_ConvertAsciiToNumeric@plt>
add    %rbx,%rax
mov    %rax,0x20(%rsp)
mov    %r13d,%ebx
mov    (%r15,%r12,8),%r13
mov    0x1(%r13),%al
cmp    $0x4c,%al
jne    12b0 <main+0x120>
cmpb   $0x3a,0x2(%r13)
jne    12b0 <main+0x120>
add    $0x3,%r13
mov    %r13,%rdi
call   10a0 <atoi@plt>
cltq
mov    %rax,0x18(%rsp)
jmp    12b0 <main+0x120>
mov    $0xff,%eax
mov    %rax,0x20(%rsp)
movl   $0x40000,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    0x10(%rsp),%esi
mov    0x28(%rsp),%r14
mov    %r14,%rdx
mov    0x20(%rsp),%rcx
mov    %ebp,%r8d
mov    0x18(%rsp),%r9
call   10b0 <F_TransformHexIntelFileToBin@plt>
lea    0xf37(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [839 x i8] c"\0AUsage: hex2bin.exe filename.hex filename.bin [OPTIONS] \0AExample: hex2bin.exe myhex.hex mybin.bin /A:1FF /F:FF /S:256 \0AOptions:\0A /S [Size] Size in kB of the .bin file, decimal value. Default value: 256\0A /F [Fill] Fill pattern. Default value FF\0A /A [start Address] Starting Address of the memory, hexadecimal value. Default value 0\0A /L [Little Endian] If the data in the hex file is written in little endian you should include this parameter with the number of bits of each register. For example /L:16 (little endian with 16bit register). default parameter is big endian, in big endian the size of the register is not necessary. \0A\0AReturn values: \0AOK = 1 \0AEnd of file record not found in .hex file = 0 \0AFile not found = -1 \0AChecksum Error = -2 \0AIncompatible File = -3 \0AMemory Allocation = -4 \0AEndianness Bits must be 8 multiple = -5 \0A\00"
@.str.1 = [11 x i8] c"Result: %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8 0, i8* %9
store i32 0, i32* %10
store i32 262144, i32* %11
store i64 255, i64* %12
store i64 0, i64* %13
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([839 x i8], [839 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %267
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i64 @strlen(i8* %22)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strlen(i8* %26)
%28 = add i64 %23, %27
%29 = mul i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %7
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i64 @strlen(i8* %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i64 @strlen(i8* %39)
%41 = add i64 %36, %40
%42 = add i64 %41, 20
%43 = mul i64 %42, 1
%44 = trunc i64 %43 to i32
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %8
%47 = load i8*, i8** %7
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @strcpy(i8* %47, i8* %50)
%52 = load i8*, i8** %8
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @strcpy(i8* %52, i8* %55)
%57 = load i8*, i8** %7
%58 = call i64 @strlen(i8* %57)
store i64 %58, i64* %6
br label %59
59: ; preds = %70, %19
%60 = load i64, i64* %6
%61 = icmp ugt i64 %60, 0
br i1 %61, label %62, label %73
62: ; preds = %59
%63 = load i8*, i8** %7
%64 = load i64, i64* %6
%65 = getelementptr inbounds i8, i8* %63, i64 %64
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 92
br i1 %68, label %69, label %70
69: ; preds = %62
br label %73
70: ; preds = %62
%71 = load i64, i64* %6
%72 = add i64 %71, -1
store i64 %72, i64* %6
br label %59
73: ; preds = %69, %59
%74 = load i64, i64* %6
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i64, i64* %6
%78 = add i64 %77, 1
store i64 %78, i64* %6
br label %79
79: ; preds = %76, %73
%80 = load i8*, i8** %7
%81 = load i64, i64* %6
%82 = getelementptr inbounds i8, i8* %80, i64 %81
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = call i32 @strcpy(i8* %82, i8* %85)
%87 = load i8*, i8** %8
%88 = load i64, i64* %6
%89 = getelementptr inbounds i8, i8* %87, i64 %88
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 2
%92 = load i8*, i8** %91
%93 = call i32 @strcpy(i8* %89, i8* %92)
store i8 3, i8* %9
br label %94
94: ; preds = %251, %79
%95 = load i8, i8* %9
%96 = sext i8 %95 to i32
%97 = load i32, i32* %4
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %254
99: ; preds = %94
%100 = load i8**, i8*** %5
%101 = load i8, i8* %9
%102 = sext i8 %101 to i64
%103 = getelementptr inbounds i8*, i8** %100, i64 %102
%104 = load i8*, i8** %103
%105 = getelementptr inbounds i8, i8* %104, i64 1
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = icmp eq i32 %107, 65
br i1 %108, label %109, label %150
109: ; preds = %99
%110 = load i8**, i8*** %5
%111 = load i8, i8* %9
%112 = sext i8 %111 to i64
%113 = getelementptr inbounds i8*, i8** %110, i64 %112
%114 = load i8*, i8** %113
%115 = getelementptr inbounds i8, i8* %114, i64 2
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = icmp eq i32 %117, 58
br i1 %118, label %119, label %150
119: ; preds = %109
store i64 0, i64* %6
br label %120
120: ; preds = %146, %119
%121 = load i64, i64* %6
%122 = load i8**, i8*** %5
%123 = load i8, i8* %9
%124 = sext i8 %123 to i64
%125 = getelementptr inbounds i8*, i8** %122, i64 %124
%126 = load i8*, i8** %125
%127 = getelementptr inbounds i8, i8* %126, i64 3
%128 = call i64 @strlen(i8* %127)
%129 = icmp ult i64 %121, %128
br i1 %129, label %130, label %149
130: ; preds = %120
%131 = load i32, i32* %10
%132 = shl i32 %131, 4
%133 = sext i32 %132 to i64
%134 = load i8**, i8*** %5
%135 = load i8, i8* %9
%136 = sext i8 %135 to i64
%137 = getelementptr inbounds i8*, i8** %134, i64 %136
%138 = load i8*, i8** %137
%139 = load i64, i64* %6
%140 = add i64 %139, 3
%141 = getelementptr inbounds i8, i8* %138, i64 %140
%142 = load i8, i8* %141
%143 = call i64 @F_ConvertAsciiToNumeric(i8 signext %142)
%144 = add i64 %133, %143
%145 = trunc i64 %144 to i32
store i32 %145, i32* %10
br label %146
146: ; preds = %130
%147 = load i64, i64* %6
%148 = add i64 %147, 1
store i64 %148, i64* %6
br label %120
149: ; preds = %120
br label %150
150: ; preds = %149, %109, %99
%151 = load i8**, i8*** %5
%152 = load i8, i8* %9
%153 = sext i8 %152 to i64
%154 = getelementptr inbounds i8*, i8** %151, i64 %153
%155 = load i8*, i8** %154
%156 = getelementptr inbounds i8, i8* %155, i64 1
%157 = load i8, i8* %156
%158 = sext i8 %157 to i32
%159 = icmp eq i32 %158, 83
br i1 %159, label %160, label %179
160: ; preds = %150
%161 = load i8**, i8*** %5
%162 = load i8, i8* %9
%163 = sext i8 %162 to i64
%164 = getelementptr inbounds i8*, i8** %161, i64 %163
%165 = load i8*, i8** %164
%166 = getelementptr inbounds i8, i8* %165, i64 2
%167 = load i8, i8* %166
%168 = sext i8 %167 to i32
%169 = icmp eq i32 %168, 58
br i1 %169, label %170, label %179
170: ; preds = %160
%171 = load i8**, i8*** %5
%172 = load i8, i8* %9
%173 = sext i8 %172 to i64
%174 = getelementptr inbounds i8*, i8** %171, i64 %173
%175 = load i8*, i8** %174
%176 = getelementptr inbounds i8, i8* %175, i64 3
%177 = call i32 @atoi(i8* %176)
%178 = mul nsw i32 %177, 1024
store i32 %178, i32* %11
br label %179
179: ; preds = %170, %160, %150
%180 = load i8**, i8*** %5
%181 = load i8, i8* %9
%182 = sext i8 %181 to i64
%183 = getelementptr inbounds i8*, i8** %180, i64 %182
%184 = load i8*, i8** %183
%185 = getelementptr inbounds i8, i8* %184, i64 1
%186 = load i8, i8* %185
%187 = sext i8 %186 to i32
%188 = icmp eq i32 %187, 70
br i1 %188, label %189, label %221
189: ; preds = %179
%190 = load i8**, i8*** %5
%191 = load i8, i8* %9
%192 = sext i8 %191 to i64
%193 = getelementptr inbounds i8*, i8** %190, i64 %192
%194 = load i8*, i8** %193
%195 = getelementptr inbounds i8, i8* %194, i64 2
%196 = load i8, i8* %195
%197 = sext i8 %196 to i32
%198 = icmp eq i32 %197, 58
br i1 %198, label %199, label %221
199: ; preds = %189
store i64 0, i64* %12
store i64 0, i64* %6
br label %200
200: ; preds = %217, %199
%201 = load i64, i64* %6
%202 = icmp ult i64 %201, 2
br i1 %202, label %203, label %220
203: ; preds = %200
%204 = load i64, i64* %12
%205 = shl i64 %204, 4
%206 = load i8**, i8*** %5
%207 = load i8, i8* %9
%208 = sext i8 %207 to i64
%209 = getelementptr inbounds i8*, i8** %206, i64 %208
%210 = load i8*, i8** %209
%211 = load i64, i64* %6
%212 = add i64 %211, 3
%213 = getelementptr inbounds i8, i8* %210, i64 %212
%214 = load i8, i8* %213
%215 = call i64 @F_ConvertAsciiToNumeric(i8 signext %214)
%216 = add i64 %205, %215
store i64 %216, i64* %12
br label %217
217: ; preds = %203
%218 = load i64, i64* %6
%219 = add i64 %218, 1
store i64 %219, i64* %6
br label %200
220: ; preds = %200
br label %221
221: ; preds = %220, %189, %179
%222 = load i8**, i8*** %5
%223 = load i8, i8* %9
%224 = sext i8 %223 to i64
%225 = getelementptr inbounds i8*, i8** %222, i64 %224
%226 = load i8*, i8** %225
%227 = getelementptr inbounds i8, i8* %226, i64 1
%228 = load i8, i8* %227
%229 = sext i8 %228 to i32
%230 = icmp eq i32 %229, 76
br i1 %230, label %231, label %250
231: ; preds = %221
%232 = load i8**, i8*** %5
%233 = load i8, i8* %9
%234 = sext i8 %233 to i64
%235 = getelementptr inbounds i8*, i8** %232, i64 %234
%236 = load i8*, i8** %235
%237 = getelementptr inbounds i8, i8* %236, i64 2
%238 = load i8, i8* %237
%239 = sext i8 %238 to i32
%240 = icmp eq i32 %239, 58
br i1 %240, label %241, label %250
241: ; preds = %231
%242 = load i8**, i8*** %5
%243 = load i8, i8* %9
%244 = sext i8 %243 to i64
%245 = getelementptr inbounds i8*, i8** %242, i64 %244
%246 = load i8*, i8** %245
%247 = getelementptr inbounds i8, i8* %246, i64 3
%248 = call i32 @atoi(i8* %247)
%249 = sext i32 %248 to i64
store i64 %249, i64* %13
br label %250
250: ; preds = %241, %231, %221
br label %251
251: ; preds = %250
%252 = load i8, i8* %9
%253 = add i8 %252, 1
store i8 %253, i8* %9
br label %94
254: ; preds = %94
%255 = load i8*, i8** %7
%256 = load i32, i32* %11
%257 = load i8*, i8** %8
%258 = load i64, i64* %12
%259 = load i32, i32* %10
%260 = load i64, i64* %13
%261 = call i32 @F_TransformHexIntelFileToBin(i8* %255, i32 %256, i8* %257, i64 %258, i32 %259, i64 %260)
%262 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %261)
%263 = load i8*, i8** %7
%264 = call i32 @free(i8* %263)
%265 = load i8*, i8** %8
%266 = call i32 @free(i8* %265)
store i32 0, i32* %3
br label %267
267: ; preds = %254, %16
%268 = load i32, i32* %3
ret i32 %268
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [839 x i8] c"\0AUsage: hex2bin.exe filename.hex filename.bin [OPTIONS] \0AExample: hex2bin.exe myhex.hex mybin.bin /A:1FF /F:FF /S:256 \0AOptions:\0A /S [Size] Size in kB of the .bin file, decimal value. Default value: 256\0A /F [Fill] Fill pattern. Default value FF\0A /A [start Address] Starting Address of the memory, hexadecimal value. Default value 0\0A /L [Little Endian] If the data in the hex file is written in little endian you should include this parameter with the number of bits of each register. For example /L:16 (little endian with 16bit register). default parameter is big endian, in big endian the size of the register is not necessary. \0A\0AReturn values: \0AOK = 1 \0AEnd of file record not found in .hex file = 0 \0AFile not found = -1 \0AChecksum Error = -2 \0AIncompatible File = -3 \0AMemory Allocation = -4 \0AEndianness Bits must be 8 multiple = -5 \0A\00"
@.str.1 = [11 x i8] c"Result: %d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([839 x i8], [839 x i8]* @.str, i64 0, i64 0))
br label %150
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = add i64 %12, %9
%14 = trunc i64 %13 to i32
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = load i8*, i8** %1
%18 = tail call i64 @strlen(i8* dereferenceable(1) %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i64 @strlen(i8* dereferenceable(1) %20)
%22 = add i64 %21, %18
%23 = trunc i64 %22 to i32
%24 = add i32 %23, 20
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = load i8*, i8** %1
%28 = tail call i32 @strcpy(i8* %16, i8* %27)
%29 = load i8*, i8** %1
%30 = tail call i32 @strcpy(i8* %26, i8* %29)
%31 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%32 = icmp eq i64 %31, 0
br i1 %32, label %43, label %33
33: ; preds = %7, %38
%34 = phi i64 [ %39, %38 ], [ %31, %7 ]
%35 = getelementptr inbounds i8, i8* %16, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 92
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = add i64 %34, -1
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %33
41: ; preds = %33
%42 = add i64 %34, 1
br label %43
43: ; preds = %38, %7, %41
%44 = phi i64 [ %42, %41 ], [ 0, %7 ], [ 0, %38 ]
%45 = getelementptr inbounds i8, i8* %16, i64 %44
%46 = load i8*, i8** %10
%47 = tail call i32 @strcpy(i8* %45, i8* %46)
%48 = getelementptr inbounds i8, i8* %26, i64 %44
%49 = load i8*, i8** %19
%50 = tail call i32 @strcpy(i8* %48, i8* %49)
%51 = icmp sgt i32 %0, 3
br i1 %51, label %52, label %141
52: ; preds = %43, %133
%53 = phi i64 [ %137, %133 ], [ 0, %43 ]
%54 = phi i64 [ %134, %133 ], [ 255, %43 ]
%55 = phi i32 [ %135, %133 ], [ 262144, %43 ]
%56 = phi i32 [ %136, %133 ], [ 0, %43 ]
%57 = phi i8 [ %138, %133 ], [ 3, %43 ]
%58 = sext i8 %57 to i64
%59 = getelementptr inbounds i8*, i8** %1, i64 %58
%60 = load i8*, i8** %59
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = load i8, i8* %61
%63 = icmp eq i8 %62, 65
br i1 %63, label %64, label %91
64: ; preds = %52
%65 = getelementptr inbounds i8, i8* %60, i64 2
%66 = load i8, i8* %65
%67 = icmp eq i8 %66, 58
br i1 %67, label %68, label %133
68: ; preds = %64
%69 = getelementptr inbounds i8, i8* %60, i64 3
%70 = tail call i64 @strlen(i8* %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %133, label %72
72: ; preds = %68, %72
%73 = phi i8* [ %84, %72 ], [ %60, %68 ]
%74 = phi i32 [ %82, %72 ], [ %56, %68 ]
%75 = phi i64 [ %83, %72 ], [ 0, %68 ]
%76 = shl i32 %74, 4
%77 = add i64 %75, 3
%78 = getelementptr inbounds i8, i8* %73, i64 %77
%79 = load i8, i8* %78
%80 = tail call i64 @F_ConvertAsciiToNumeric(i8 signext %79)
%81 = trunc i64 %80 to i32
%82 = add i32 %76, %81
%83 = add nuw i64 %75, 1
%84 = load i8*, i8** %59
%85 = getelementptr inbounds i8, i8* %84, i64 3
%86 = tail call i64 @strlen(i8* %85)
%87 = icmp ult i64 %83, %86
br i1 %87, label %72, label %88
88: ; preds = %72
%89 = getelementptr inbounds i8, i8* %84, i64 1
%90 = load i8, i8* %89
br label %91
91: ; preds = %88, %52
%92 = phi i8 [ %62, %52 ], [ %90, %88 ]
%93 = phi i8* [ %60, %52 ], [ %84, %88 ]
%94 = phi i32 [ %56, %52 ], [ %82, %88 ]
switch i8 %92, label %120 [
i8 83, label %95
i8 70, label %103
]
95: ; preds = %91
%96 = getelementptr inbounds i8, i8* %93, i64 2
%97 = load i8, i8* %96
%98 = icmp eq i8 %97, 58
br i1 %98, label %99, label %133
99: ; preds = %95
%100 = getelementptr inbounds i8, i8* %93, i64 3
%101 = tail call i32 @atoi(i8* %100)
%102 = shl nsw i32 %101, 10
br label %133
103: ; preds = %91
%104 = getelementptr inbounds i8, i8* %93, i64 2
%105 = load i8, i8* %104
%106 = icmp eq i8 %105, 58
br i1 %106, label %107, label %133
107: ; preds = %103
%108 = getelementptr inbounds i8, i8* %93, i64 3
%109 = load i8, i8* %108
%110 = tail call i64 @F_ConvertAsciiToNumeric(i8 signext %109)
%111 = shl i64 %110, 4
%112 = load i8*, i8** %59
%113 = getelementptr inbounds i8, i8* %112, i64 4
%114 = load i8, i8* %113
%115 = tail call i64 @F_ConvertAsciiToNumeric(i8 signext %114)
%116 = add i64 %115, %111
%117 = load i8*, i8** %59
%118 = getelementptr inbounds i8, i8* %117, i64 1
%119 = load i8, i8* %118
br label %120
120: ; preds = %107, %91
%121 = phi i8 [ %92, %91 ], [ %119, %107 ]
%122 = phi i8* [ %93, %91 ], [ %117, %107 ]
%123 = phi i64 [ %54, %91 ], [ %116, %107 ]
%124 = icmp eq i8 %121, 76
br i1 %124, label %125, label %133
125: ; preds = %120
%126 = getelementptr inbounds i8, i8* %122, i64 2
%127 = load i8, i8* %126
%128 = icmp eq i8 %127, 58
br i1 %128, label %129, label %133
129: ; preds = %125
%130 = getelementptr inbounds i8, i8* %122, i64 3
%131 = tail call i32 @atoi(i8* %130)
%132 = sext i32 %131 to i64
br label %133
133: ; preds = %68, %64, %99, %95, %103, %120, %125, %129
%134 = phi i64 [ %123, %129 ], [ %123, %125 ], [ %123, %120 ], [ %54, %103 ], [ %54, %95 ], [ %54, %99 ], [ %54, %64 ], [ %54, %68 ]
%135 = phi i32 [ %55, %129 ], [ %55, %125 ], [ %55, %120 ], [ %55, %103 ], [ %55, %95 ], [ %102, %99 ], [ %55, %64 ], [ %55, %68 ]
%136 = phi i32 [ %94, %129 ], [ %94, %125 ], [ %94, %120 ], [ %94, %103 ], [ %94, %95 ], [ %94, %99 ], [ %56, %64 ], [ %56, %68 ]
%137 = phi i64 [ %132, %129 ], [ %53, %125 ], [ %53, %120 ], [ %53, %103 ], [ %53, %95 ], [ %53, %99 ], [ %53, %64 ], [ %53, %68 ]
%138 = add i8 %57, 1
%139 = sext i8 %138 to i32
%140 = icmp slt i32 %139, %0
br i1 %140, label %52, label %141
141: ; preds = %133, %43
%142 = phi i32 [ 0, %43 ], [ %136, %133 ]
%143 = phi i32 [ 262144, %43 ], [ %135, %133 ]
%144 = phi i64 [ 255, %43 ], [ %134, %133 ]
%145 = phi i64 [ 0, %43 ], [ %137, %133 ]
%146 = tail call i32 @F_TransformHexIntelFileToBin(i8* %16, i32 %143, i8* %26, i64 %144, i32 %142, i64 %145)
%147 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %146)
%148 = tail call i32 @free(i8* %16)
%149 = tail call i32 @free(i8* %26)
br label %150
150: ; preds = %141, %4
ret i32 0
}