#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
unsigned char *readFiletoBuffer(size_t *, char *);
int /*<<< orphan*/ writeBuffertoFile(unsigned char *, size_t, char *);
int main(int argc, char *argv[]) {
  unsigned char *bufferh, *bufferl, *buffero;
  unsigned char s;
  size_t sizeh, sizel, sizeo, i;
  if (argc < 3) {
    printf("Usage:%s <In-File-H> <In-File-L> <Out-File>\n", argv[0]);
    printf("This tool can help you to merge hi-lo to one binary file\n");
    exit(0);
  }
  bufferh = readFiletoBuffer(&sizeh, argv[1]);
  bufferl = readFiletoBuffer(&sizel, argv[2]);
  if (sizeh != sizel) {
    printf("File length isn't equal! aborting!\n");
    exit(0);
  }
  printf("Input File size: H %d bytes, L %d bytes\n", sizeh, sizel);
  sizeo = sizeh + sizel;
  buffero = malloc(sizeo);
  for (i = 0; i <= sizel; i += 2) {
    buffero[2 * i + 3] = bufferl[i];
    buffero[2 * i + 2] = bufferl[i + 1];
    buffero[2 * i + 1] = bufferh[i];
    buffero[2 * i + 0] = bufferh[i + 1];
  }
  writeBuffertoFile(buffero, sizeo, argv[3]);
  printf("Completed write:%s\n", argv[3]);
  free(bufferh);
  free(bufferl);
  free(buffero);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11aa <main+0x4a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x38(%rbp),%rdi
call   1040 <readFiletoBuffer@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x40(%rbp),%rdi
call   1040 <readFiletoBuffer@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     11f7 <main+0x97>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x40(%rbp),%rax
ja     12ba <main+0x15a>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x50(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,0x3(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    0x1(%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x50(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,0x2(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x50(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    0x1(%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x50(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x50(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x50(%rbp)
jmp    122e <main+0xce>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
call   1060 <writeBuffertoFile@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    126d <main+0xfd>
mov    0x8(%rbx),%rsi
lea    0x8(%rsp),%rdi
call   1050 <readFiletoBuffer@plt>
mov    %rax,%r15
mov    %rbx,0x10(%rsp)
mov    0x10(%rbx),%rsi
mov    %rsp,%rdi
call   1050 <readFiletoBuffer@plt>
mov    0x8(%rsp),%rdx
cmp    (%rsp),%rdx
jne    1287 <main+0x117>
mov    %rax,%r12
lea    0xe68(%rip),%rdi
xor    %ebp,%ebp
mov    %rdx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rsp),%r14
mov    0x8(%rsp),%r13
add    %r14,%r13
mov    %r13,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbp,1),%eax
mov    %al,0x3(%rbx,%rbp,2)
movzbl 0x1(%r12,%rbp,1),%eax
mov    %al,0x2(%rbx,%rbp,2)
movzbl (%r15,%rbp,1),%eax
mov    %al,0x1(%rbx,%rbp,2)
movzbl 0x1(%r15,%rbp,1),%eax
mov    %al,(%rbx,%rbp,2)
add    $0x2,%rbp
cmp    %r14,%rbp
jbe    11f0 <main+0x80>
mov    0x10(%rsp),%rbp
mov    0x18(%rbp),%rdx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <writeBuffertoFile@plt>
mov    0x18(%rbp),%rsi
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xd89(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe08(%rip),%rdi
jmp    128e <main+0x11e>
lea    0xddc(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Usage:%s <In-File-H> <In-File-L> <Out-File>\0A\00"
@.str.1 = [58 x i8] c"This tool can help you to merge hi-lo to one binary file\0A\00"
@.str.2 = [36 x i8] c"File length isn't equal! aborting!\0A\00"
@.str.3 = [41 x i8] c"Input File size: H %d bytes, L %d bytes\0A\00"
@.str.4 = [20 x i8] c"Completed write:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i8* @readFiletoBuffer(i64* %10, i8* %26)
store i8* %27, i8** %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i8* @readFiletoBuffer(i64* %11, i8* %30)
store i8* %31, i8** %7
%32 = load i64, i64* %10
%33 = load i64, i64* %11
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %23
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %23
%39 = load i64, i64* %10
%40 = load i64, i64* %11
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i64 %39, i64 %40)
%42 = load i64, i64* %10
%43 = load i64, i64* %11
%44 = add i64 %42, %43
store i64 %44, i64* %12
%45 = load i64, i64* %12
%46 = call i8* @malloc(i64 %45)
store i8* %46, i8** %8
store i64 0, i64* %13
br label %47
47: ; preds = %90, %38
%48 = load i64, i64* %13
%49 = load i64, i64* %11
%50 = icmp ule i64 %48, %49
br i1 %50, label %51, label %93
51: ; preds = %47
%52 = load i8*, i8** %7
%53 = load i64, i64* %13
%54 = getelementptr inbounds i8, i8* %52, i64 %53
%55 = load i8, i8* %54
%56 = load i8*, i8** %8
%57 = load i64, i64* %13
%58 = mul i64 2, %57
%59 = add i64 %58, 3
%60 = getelementptr inbounds i8, i8* %56, i64 %59
store i8 %55, i8* %60
%61 = load i8*, i8** %7
%62 = load i64, i64* %13
%63 = add i64 %62, 1
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = load i8*, i8** %8
%67 = load i64, i64* %13
%68 = mul i64 2, %67
%69 = add i64 %68, 2
%70 = getelementptr inbounds i8, i8* %66, i64 %69
store i8 %65, i8* %70
%71 = load i8*, i8** %6
%72 = load i64, i64* %13
%73 = getelementptr inbounds i8, i8* %71, i64 %72
%74 = load i8, i8* %73
%75 = load i8*, i8** %8
%76 = load i64, i64* %13
%77 = mul i64 2, %76
%78 = add i64 %77, 1
%79 = getelementptr inbounds i8, i8* %75, i64 %78
store i8 %74, i8* %79
%80 = load i8*, i8** %6
%81 = load i64, i64* %13
%82 = add i64 %81, 1
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i8, i8* %83
%85 = load i8*, i8** %8
%86 = load i64, i64* %13
%87 = mul i64 2, %86
%88 = add i64 %87, 0
%89 = getelementptr inbounds i8, i8* %85, i64 %88
store i8 %84, i8* %89
br label %90
90: ; preds = %51
%91 = load i64, i64* %13
%92 = add i64 %91, 2
store i64 %92, i64* %13
br label %47
93: ; preds = %47
%94 = load i8*, i8** %8
%95 = load i64, i64* %12
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 3
%98 = load i8*, i8** %97
%99 = call i32 @writeBuffertoFile(i8* %94, i64 %95, i8* %98)
%100 = load i8**, i8*** %5
%101 = getelementptr inbounds i8*, i8** %100, i64 3
%102 = load i8*, i8** %101
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %102)
%104 = load i8*, i8** %6
%105 = call i32 @free(i8* %104)
%106 = load i8*, i8** %7
%107 = call i32 @free(i8* %106)
%108 = load i8*, i8** %8
%109 = call i32 @free(i8* %108)
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
@.str = [45 x i8] c"Usage:%s <In-File-H> <In-File-L> <Out-File>\0A\00"
@.str.3 = [41 x i8] c"Input File size: H %d bytes, L %d bytes\0A\00"
@.str.4 = [20 x i8] c"Completed write:%s\0A\00"
@str = [35 x i8] c"File length isn't equal! aborting!\00"
@str.5 = [57 x i8] c"This tool can help you to merge hi-lo to one binary file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.5, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i8* @readFiletoBuffer(i64* %3, i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i8* @readFiletoBuffer(i64* %4, i8* %18)
%20 = load i64, i64* %3
%21 = load i64, i64* %4
%22 = icmp eq i64 %20, %21
br i1 %22, label %26, label %23
23: ; preds = %13
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i64 %20, i64 %20)
%28 = load i64, i64* %3
%29 = load i64, i64* %4
%30 = add i64 %29, %28
%31 = call i8* @malloc(i64 %30)
br label %32
32: ; preds = %26, %32
%33 = phi i64 [ 0, %26 ], [ %51, %32 ]
%34 = getelementptr inbounds i8, i8* %19, i64 %33
%35 = load i8, i8* %34
%36 = shl i64 %33, 1
%37 = or i64 %36, 3
%38 = getelementptr inbounds i8, i8* %31, i64 %37
store i8 %35, i8* %38
%39 = or i64 %33, 1
%40 = getelementptr inbounds i8, i8* %19, i64 %39
%41 = load i8, i8* %40
%42 = or i64 %36, 2
%43 = getelementptr inbounds i8, i8* %31, i64 %42
store i8 %41, i8* %43
%44 = getelementptr inbounds i8, i8* %16, i64 %33
%45 = load i8, i8* %44
%46 = or i64 %36, 1
%47 = getelementptr inbounds i8, i8* %31, i64 %46
store i8 %45, i8* %47
%48 = getelementptr inbounds i8, i8* %16, i64 %39
%49 = load i8, i8* %48
%50 = getelementptr inbounds i8, i8* %31, i64 %36
store i8 %49, i8* %50
%51 = add nuw i64 %33, 2
%52 = icmp ugt i64 %51, %29
br i1 %52, label %53, label %32
53: ; preds = %32
%54 = getelementptr inbounds i8*, i8** %1, i64 3
%55 = load i8*, i8** %54
%56 = call i32 @writeBuffertoFile(i8* %31, i64 %30, i8* %55)
%57 = load i8*, i8** %54
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = call i32 @free(i8* %16)
%60 = call i32 @free(i8* %19)
%61 = call i32 @free(i8* %31)
ret i32 0
}