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

/* Variables and functions */
int /*<<< orphan*/ displayBinary(unsigned char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ getVarintSize(int);
int hexToBin(char *, unsigned char *, int);
unsigned char *malloc(int);
scalar_t__ parseStringAmount(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ writeHexAmount(int /*<<< orphan*/, unsigned char *);
int /*<<< orphan*/ writeVarint(int, unsigned char *, int);
int main(int argc, char **argv) {
  int result;
  int i;
  int size = 1;
  int offset = 0;
  unsigned char *buffer;
  if (argc < 3) {
    fprintf(stderr, "Usage : %s ([amount (in BTC string)] [output script])*N\n",
            argv[0]);
    return 0;
  }
  if (((argc - 1) % 2) != 0) {
    fprintf(stderr, "Invalid number of parameters\n");
    return 0;
  }
  for (i = 1; i < argc; i += 2) {
    int64_t amount;
    int scriptSize;
    if (parseStringAmount(argv[i], &amount) < 0) {
      fprintf(stderr, "Invalid amount %d\n", ((i / 2) + 1));
      return 0;
    }
    if ((strlen(argv[i + 1]) % 2) != 0) {
      fprintf(stderr, "Invalid output script %d\n", ((i / 2) + 1));
      return 0;
    }
    scriptSize = strlen(argv[i + 1]) / 2;
    size += 8 + getVarintSize(scriptSize) + scriptSize;
  }
  buffer = malloc(size);
  if (buffer == NULL) {
    fprintf(stderr, "Couldn't allocate output buffer\n");
    return 0;
  }
  buffer[offset++] = (argc / 2);
  for (i = 1; i < argc; i += 2) {
    int64_t amount;
    int scriptSize;
    parseStringAmount(argv[i], &amount);
    writeHexAmount(amount, buffer + offset);
    offset += 8;
    scriptSize = strlen(argv[i + 1]) / 2;
    writeVarint(scriptSize, (buffer + offset), (size - offset));
    offset += getVarintSize(scriptSize);
    result = hexToBin(argv[i + 1], (buffer + offset), scriptSize);
    if (result == 0) {
      free(buffer);
      fprintf(stderr, "Invalid output script %d\n", ((i / 2) + 1));
      return 0;
    }
    offset += scriptSize;
  }
  printf("Output script : ");
  displayBinary(buffer, size);
  free(buffer);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1208 <main+0x58>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x33b>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1242 <main+0x92>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x33b>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1350 <main+0x1a0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x2c(%rbp),%rsi
call   10a0 <parseStringAmount@plt>
cmp    $0x0,%rax
jge    12a7 <main+0xf7>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
add    $0x1,%edx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x33b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1301 <main+0x151>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
add    $0x1,%edx
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x33b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10b0 <getVarintSize@plt>
mov    %rax,%rcx
add    $0x8,%rcx
movslq -0x30(%rbp),%rax
add    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1249 <main+0x99>
mov    -0x1c(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    138a <main+0x1da>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x33b>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14c3 <main+0x313>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x34(%rbp),%rsi
call   10a0 <parseStringAmount@plt>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
call   10c0 <writeHexAmount@plt>
mov    -0x20(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
sub    -0x20(%rbp),%edx
call   1060 <writeVarint@plt>
mov    -0x38(%rbp),%edi
call   10b0 <getVarintSize@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x38(%rbp),%edx
call   10d0 <hexToBin@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    14ac <main+0x2fc>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b60(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
add    $0x1,%edx
lea    0xbd1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x33b>
mov    -0x38(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    13b3 <main+0x203>
lea    0xbdb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <displayBinary@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jg     11e7 <main+0x37>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe27(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13ac <main+0x1fc>
test   $0x1,%dil
jne    120b <main+0x5b>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13ac <main+0x1fc>
mov    %edi,0xc(%rsp)
mov    %edi,%r13d
mov    $0x1,%r12d
mov    $0x1,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%r12,8),%rdi
lea    0x24(%rsp),%rsi
call   10a0 <parseStringAmount@plt>
test   %rax,%rax
js     1388 <main+0x1d8>
mov    0x8(%r14,%r12,8),%rdi
call   1040 <strlen@plt>
test   $0x1,%al
jne    1391 <main+0x1e1>
mov    0x8(%r14,%r12,8),%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
shr    $0x1f,%r15d
add    %eax,%r15d
sar    %r15d
mov    %r15d,%edi
call   10b0 <getVarintSize@plt>
add    %r15d,%ebx
add    %eax,%ebx
add    $0x8,%ebx
add    $0x2,%r12
add    $0x1,%ebp
cmp    %r13,%r12
jb     1230 <main+0x80>
mov    %ebx,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     13bd <main+0x20d>
mov    %rax,%r13
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
shr    %eax
mov    %al,0x0(%r13)
movslq %ecx,%rax
mov    %rax,0x18(%rsp)
mov    $0x1,%r12d
mov    $0x1,%eax
mov    $0x1,%r15d
nopl   0x0(%rax)
mov    %eax,0x10(%rsp)
mov    (%r14,%r12,8),%rdi
lea    0x14(%rsp),%rsi
call   10a0 <parseStringAmount@plt>
mov    0x14(%rsp),%edi
movslq %r15d,%r15
lea    (%r15,%r13,1),%rsi
call   10c0 <writeHexAmount@plt>
lea    0x8(%r15),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%r14,%r12,8),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    (%r15,%r13,1),%rsi
add    $0x8,%rsi
mov    %ebx,%edx
sub    0xc(%rsp),%edx
mov    %ebp,%edi
call   1060 <writeVarint@plt>
mov    %ebp,%edi
call   10b0 <getVarintSize@plt>
add    %eax,%r15d
add    $0x8,%r15d
mov    0x8(%r14,%r12,8),%rdi
movslq %r15d,%rsi
add    %r13,%rsi
mov    %ebp,%edx
call   10d0 <hexToBin@plt>
test   %eax,%eax
je     13d2 <main+0x222>
add    %ebp,%r15d
add    $0x2,%r12
mov    0x10(%rsp),%eax
add    $0x1,%eax
cmp    0x18(%rsp),%r12
jl     12d0 <main+0x120>
lea    0xd3b(%rip),%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1080 <displayBinary@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
jmp    13ac <main+0x1fc>
lea    0xcc8(%rip),%rsi
jmp    1398 <main+0x1e8>
lea    0xcd2(%rip),%rsi
mov    0x2c41(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
lea    0xcb7(%rip),%rsi
jmp    11fd <main+0x4d>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
lea    0xc80(%rip),%rsi
xor    %ebx,%ebx
mov    0x10(%rsp),%edx
jmp    13a5 <main+0x1f5>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"Usage : %s ([amount (in BTC string)] [output script])*N\0A\00"
@.str.1 = [30 x i8] c"Invalid number of parameters\0A\00"
@.str.2 = [19 x i8] c"Invalid amount %d\0A\00"
@.str.3 = [26 x i8] c"Invalid output script %d\0A\00"
@.str.4 = [33 x i8] c"Couldn't allocate output buffer\0A\00"
@.str.5 = [17 x i8] c"Output script : \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
store i32 0, i32* %9
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %3
br label %183
23: ; preds = %2
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = srem i32 %25, 2
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %183
31: ; preds = %23
store i32 1, i32* %7
br label %32
32: ; preds = %85, %31
%33 = load i32, i32* %7
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %88
36: ; preds = %32
%37 = load i8**, i8*** %5
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i64 @parseStringAmount(i8* %41, i32* %11)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = load i32, i32* %7
%47 = sdiv i32 %46, 2
%48 = add nsw i32 %47, 1
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %48)
store i32 0, i32* %3
br label %183
50: ; preds = %36
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %51, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @strlen(i8* %56)
%58 = srem i32 %57, 2
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %50
%61 = load i32, i32* @stderr
%62 = load i32, i32* %7
%63 = sdiv i32 %62, 2
%64 = add nsw i32 %63, 1
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %64)
store i32 0, i32* %3
br label %183
66: ; preds = %50
%67 = load i8**, i8*** %5
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %67, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @strlen(i8* %72)
%74 = sdiv i32 %73, 2
store i32 %74, i32* %12
%75 = load i32, i32* %12
%76 = call i64 @getVarintSize(i32 %75)
%77 = add nsw i64 8, %76
%78 = load i32, i32* %12
%79 = sext i32 %78 to i64
%80 = add nsw i64 %77, %79
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = add nsw i64 %82, %80
%84 = trunc i64 %83 to i32
store i32 %84, i32* %8
br label %85
85: ; preds = %66
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 2
store i32 %87, i32* %7
br label %32
88: ; preds = %32
%89 = load i32, i32* %8
%90 = call i8* @malloc(i32 %89)
store i8* %90, i8** %10
%91 = load i8*, i8** %10
%92 = icmp eq i8* %91, null
br i1 %92, label %93, label %96
93: ; preds = %88
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %183
96: ; preds = %88
%97 = load i32, i32* %4
%98 = sdiv i32 %97, 2
%99 = trunc i32 %98 to i8
%100 = load i8*, i8** %10
%101 = load i32, i32* %9
%102 = add nsw i32 %101, 1
store i32 %102, i32* %9
%103 = sext i32 %101 to i64
%104 = getelementptr inbounds i8, i8* %100, i64 %103
store i8 %99, i8* %104
store i32 1, i32* %7
br label %105
105: ; preds = %173, %96
%106 = load i32, i32* %7
%107 = load i32, i32* %4
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %176
109: ; preds = %105
%110 = load i8**, i8*** %5
%111 = load i32, i32* %7
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8*, i8** %110, i64 %112
%114 = load i8*, i8** %113
%115 = call i64 @parseStringAmount(i8* %114, i32* %13)
%116 = load i32, i32* %13
%117 = load i8*, i8** %10
%118 = load i32, i32* %9
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8, i8* %117, i64 %119
%121 = call i32 @writeHexAmount(i32 %116, i8* %120)
%122 = load i32, i32* %9
%123 = add nsw i32 %122, 8
store i32 %123, i32* %9
%124 = load i8**, i8*** %5
%125 = load i32, i32* %7
%126 = add nsw i32 %125, 1
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8*, i8** %124, i64 %127
%129 = load i8*, i8** %128
%130 = call i32 @strlen(i8* %129)
%131 = sdiv i32 %130, 2
store i32 %131, i32* %14
%132 = load i32, i32* %14
%133 = load i8*, i8** %10
%134 = load i32, i32* %9
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8, i8* %133, i64 %135
%137 = load i32, i32* %8
%138 = load i32, i32* %9
%139 = sub nsw i32 %137, %138
%140 = call i32 @writeVarint(i32 %132, i8* %136, i32 %139)
%141 = load i32, i32* %14
%142 = call i64 @getVarintSize(i32 %141)
%143 = load i32, i32* %9
%144 = sext i32 %143 to i64
%145 = add nsw i64 %144, %142
%146 = trunc i64 %145 to i32
store i32 %146, i32* %9
%147 = load i8**, i8*** %5
%148 = load i32, i32* %7
%149 = add nsw i32 %148, 1
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8*, i8** %147, i64 %150
%152 = load i8*, i8** %151
%153 = load i8*, i8** %10
%154 = load i32, i32* %9
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i8, i8* %153, i64 %155
%157 = load i32, i32* %14
%158 = call i32 @hexToBin(i8* %152, i8* %156, i32 %157)
store i32 %158, i32* %6
%159 = load i32, i32* %6
%160 = icmp eq i32 %159, 0
br i1 %160, label %161, label %169
161: ; preds = %109
%162 = load i8*, i8** %10
%163 = call i32 @free(i8* %162)
%164 = load i32, i32* @stderr
%165 = load i32, i32* %7
%166 = sdiv i32 %165, 2
%167 = add nsw i32 %166, 1
%168 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %167)
store i32 0, i32* %3
br label %183
169: ; preds = %109
%170 = load i32, i32* %14
%171 = load i32, i32* %9
%172 = add nsw i32 %171, %170
store i32 %172, i32* %9
br label %173
173: ; preds = %169
%174 = load i32, i32* %7
%175 = add nsw i32 %174, 2
store i32 %175, i32* %7
br label %105
176: ; preds = %105
%177 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%178 = load i8*, i8** %10
%179 = load i32, i32* %8
%180 = call i32 @displayBinary(i8* %178, i32 %179)
%181 = load i8*, i8** %10
%182 = call i32 @free(i8* %181)
store i32 1, i32* %3
br label %183
183: ; preds = %176, %161, %93, %60, %44, %28, %17
%184 = load i32, i32* %3
ret i32 %184
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"Usage : %s ([amount (in BTC string)] [output script])*N\0A\00"
@.str.1 = [30 x i8] c"Invalid number of parameters\0A\00"
@.str.2 = [19 x i8] c"Invalid amount %d\0A\00"
@.str.3 = [26 x i8] c"Invalid output script %d\0A\00"
@.str.4 = [33 x i8] c"Couldn't allocate output buffer\0A\00"
@.str.5 = [17 x i8] c"Output script : \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %105
10: ; preds = %2
%11 = and i32 %0, 1
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = bitcast i32* %3 to i8*
%15 = zext i32 %0 to i64
br label %19
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %105
19: ; preds = %13, %40
%20 = phi i64 [ 1, %13 ], [ %49, %40 ]
%21 = phi i32 [ 1, %13 ], [ %48, %40 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %20
%23 = load i8*, i8** %22
%24 = call i64 @parseStringAmount(i8* %23, i32* %3)
%25 = icmp slt i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %19
%27 = add nuw nsw i64 %20, 1
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* %29)
%31 = and i32 %30, 1
%32 = icmp eq i32 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %26, %19
%34 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %19 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %26 ]
%35 = trunc i64 %20 to i32
%36 = load i32, i32* @stderr
%37 = lshr i32 %35, 1
%38 = add nuw nsw i32 %37, 1
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* %34, i32 %38)
br label %105
40: ; preds = %26
%41 = load i8*, i8** %28
%42 = call i32 @strlen(i8* %41)
%43 = sdiv i32 %42, 2
%44 = call i64 @getVarintSize(i32 %43)
%45 = trunc i64 %44 to i32
%46 = add i32 %21, 8
%47 = add i32 %46, %43
%48 = add i32 %47, %45
%49 = add nuw nsw i64 %20, 2
%50 = icmp ult i64 %49, %15
br i1 %50, label %19, label %51
51: ; preds = %40
%52 = call i8* @malloc(i32 %48)
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %105
57: ; preds = %51
%58 = sdiv i32 %0, 2
%59 = trunc i32 %58 to i8
store i8 %59, i8* %52
%60 = bitcast i32* %4 to i8*
%61 = sext i32 %0 to i64
br label %62
62: ; preds = %57, %97
%63 = phi i64 [ 1, %57 ], [ %99, %97 ]
%64 = phi i32 [ 1, %57 ], [ %98, %97 ]
%65 = getelementptr inbounds i8*, i8** %1, i64 %63
%66 = load i8*, i8** %65
%67 = call i64 @parseStringAmount(i8* %66, i32* %4)
%68 = load i32, i32* %4
%69 = sext i32 %64 to i64
%70 = getelementptr inbounds i8, i8* %52, i64 %69
%71 = call i32 @writeHexAmount(i32 %68, i8* %70)
%72 = add nsw i32 %64, 8
%73 = add nuw nsw i64 %63, 1
%74 = getelementptr inbounds i8*, i8** %1, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 @strlen(i8* %75)
%77 = sdiv i32 %76, 2
%78 = sext i32 %72 to i64
%79 = getelementptr inbounds i8, i8* %52, i64 %78
%80 = sub nsw i32 %48, %72
%81 = call i32 @writeVarint(i32 %77, i8* %79, i32 %80)
%82 = call i64 @getVarintSize(i32 %77)
%83 = trunc i64 %82 to i32
%84 = add i32 %72, %83
%85 = load i8*, i8** %74
%86 = sext i32 %84 to i64
%87 = getelementptr inbounds i8, i8* %52, i64 %86
%88 = call i32 @hexToBin(i8* %85, i8* %87, i32 %77)
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %97
90: ; preds = %62
%91 = trunc i64 %63 to i32
%92 = call i32 @free(i8* %52)
%93 = load i32, i32* @stderr
%94 = lshr i32 %91, 1
%95 = add nuw nsw i32 %94, 1
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %95)
br label %105
97: ; preds = %62
%98 = add nsw i32 %84, %77
%99 = add nuw nsw i64 %63, 2
%100 = icmp slt i64 %99, %61
br i1 %100, label %62, label %101
101: ; preds = %97
%102 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%103 = call i32 @displayBinary(i8* %52, i32 %48)
%104 = call i32 @free(i8* %52)
br label %105
105: ; preds = %90, %33, %101, %54, %16, %6
%106 = phi i32 [ 0, %6 ], [ 0, %16 ], [ 0, %54 ], [ 1, %101 ], [ 0, %33 ], [ 0, %90 ]
ret i32 %106
}