#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*/ displayBinary(unsigned char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int hexToBin(char *, unsigned char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char **argv) {
  unsigned char *redeemScript;
  unsigned char *inputScript;
  unsigned char signature[100 * 15];
  int signatureLength[15];
  int offset = 0;
  int m;
  int i;
  int inputScriptSize = 0;
  int extraPushSize = 0;
  int redeemScriptSize;
  if (argc < 3) {
    fprintf(stderr, "Usage : %s [redeemScript] M*[signature + hashtype]\n",
            argv[0]);
    return 0;
  }
  redeemScriptSize = strlen(argv[1]) / 2;
  redeemScript = (unsigned char *)malloc(redeemScriptSize);
  if (redeemScript == NULL) {
    fprintf(stderr, "Failed to allocate redeem script\n");
    return 0;
  }
  redeemScriptSize = hexToBin(argv[1], redeemScript, redeemScriptSize);
  if (redeemScriptSize <= 0) {
    fprintf(stderr, "Invalid redeem script\n");
    free(redeemScript);
    return 0;
  }
  m = redeemScript[0] - 0x50;
  if (argc != (2 + m)) {
    fprintf(stderr, "Invalid number of arguments\n");
    free(redeemScript);
    return 0;
  }
  for (i = 0; i < m; i++) {
    signatureLength[i] = hexToBin(argv[2 + i], &signature[100 * i], 100);
    if (signatureLength[i] <= 0) {
      fprintf(stderr, "Invalid signature %d\n", (i + 1));
      free(redeemScript);
      return 0;
    }
    inputScriptSize += signatureLength[i] + 1;
  }
  if (redeemScriptSize >= 0x4c) {
    if (redeemScriptSize > 255) {
      extraPushSize = 2;
    } else {
      extraPushSize = 1;
    }
  }
  inputScript = (unsigned char *)malloc(1 + inputScriptSize + redeemScriptSize +
                                        extraPushSize);
  if (inputScript == NULL) {
    fprintf(stderr, "Failed to allocate input script\n");
    free(redeemScript);
    return 0;
  }
  inputScript[offset++] = 0x00;
  for (i = 0; i < m; i++) {
    inputScript[offset++] = signatureLength[i];
    memcpy(inputScript + offset, &signature[100 * i], signatureLength[i]);
    offset += signatureLength[i];
  }
  if (extraPushSize == 0) {
    inputScript[offset++] = redeemScriptSize;
  }
  if (extraPushSize == 1) {
    inputScript[offset++] = 0x4c;
    inputScript[offset++] = redeemScriptSize;
  } else if (extraPushSize == 2) {
    inputScript[offset++] = 0x4d;
    inputScript[offset++] = (redeemScriptSize & 0xff);
    inputScript[offset++] = ((redeemScriptSize >> 8) & 0xff);
  }
  memcpy(inputScript + offset, redeemScript, redeemScriptSize);
  free(redeemScript);
  offset += redeemScriptSize;
  printf("Input script : ");
  displayBinary(inputScript, offset);
  free(inputScript);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x644(%rbp)
movl   $0x0,-0x650(%rbp)
movl   $0x0,-0x654(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11eb <main+0x6b>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    167b <main+0x4fb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x658(%rbp)
mov    -0x658(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1243 <main+0xc3>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    167b <main+0x4fb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x658(%rbp),%edx
call   10a0 <hexToBin@plt>
mov    %eax,-0x658(%rbp)
cmpl   $0x0,-0x658(%rbp)
jg     1299 <main+0x119>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    167b <main+0x4fb>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
sub    $0x50,%eax
mov    %eax,-0x648(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x648(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
je     12e9 <main+0x169>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    167b <main+0x4fb>
movl   $0x0,-0x64c(%rbp)
mov    -0x64c(%rbp),%eax
cmp    -0x648(%rbp),%eax
jge    13c1 <main+0x241>
mov    -0x10(%rbp),%rax
mov    -0x64c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
imul   $0x64,-0x64c(%rbp),%eax
cltq
lea    -0x600(%rbp),%rsi
add    %rax,%rsi
mov    $0x64,%edx
call   10a0 <hexToBin@plt>
mov    %eax,%ecx
movslq -0x64c(%rbp),%rax
mov    %ecx,-0x640(%rbp,%rax,4)
movslq -0x64c(%rbp),%rax
cmpl   $0x0,-0x640(%rbp,%rax,4)
jg     1390 <main+0x210>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
mov    -0x64c(%rbp),%edx
add    $0x1,%edx
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    167b <main+0x4fb>
movslq -0x64c(%rbp),%rax
mov    -0x640(%rbp,%rax,4),%eax
add    $0x1,%eax
add    -0x650(%rbp),%eax
mov    %eax,-0x650(%rbp)
mov    -0x64c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64c(%rbp)
jmp    12f3 <main+0x173>
cmpl   $0x4c,-0x658(%rbp)
jl     13fc <main+0x27c>
cmpl   $0xff,-0x658(%rbp)
jle    13ed <main+0x26d>
movl   $0x2,-0x654(%rbp)
jmp    13f7 <main+0x277>
movl   $0x1,-0x654(%rbp)
jmp    13fc <main+0x27c>
mov    -0x650(%rbp),%edi
add    $0x1,%edi
add    -0x658(%rbp),%edi
add    -0x654(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1451 <main+0x2d1>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xc6b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    167b <main+0x4fb>
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x644(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x64c(%rbp)
mov    -0x64c(%rbp),%eax
cmp    -0x648(%rbp),%eax
jge    1516 <main+0x396>
movslq -0x64c(%rbp),%rax
mov    -0x640(%rbp,%rax,4),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x644(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
movslq -0x644(%rbp),%rax
add    %rax,%rdi
imul   $0x64,-0x64c(%rbp),%eax
cltq
lea    -0x600(%rbp),%rsi
add    %rax,%rsi
movslq -0x64c(%rbp),%rax
mov    -0x640(%rbp,%rax,4),%edx
call   1070 <memcpy@plt>
movslq -0x64c(%rbp),%rax
mov    -0x640(%rbp,%rax,4),%eax
add    -0x644(%rbp),%eax
mov    %eax,-0x644(%rbp)
mov    -0x64c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64c(%rbp)
jmp    1477 <main+0x2f7>
cmpl   $0x0,-0x654(%rbp)
jne    1546 <main+0x3c6>
mov    -0x658(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x644(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x1,-0x654(%rbp)
jne    1597 <main+0x417>
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x644(%rbp)
movslq %ecx,%rcx
movb   $0x4c,(%rax,%rcx,1)
mov    -0x658(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x644(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1618 <main+0x498>
cmpl   $0x2,-0x654(%rbp)
jne    1613 <main+0x493>
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x644(%rbp)
movslq %ecx,%rcx
movb   $0x4d,(%rax,%rcx,1)
mov    -0x658(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x644(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x658(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x644(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x644(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1618 <main+0x498>
mov    -0x20(%rbp),%rdi
movslq -0x644(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x658(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x658(%rbp),%eax
add    -0x644(%rbp),%eax
mov    %eax,-0x644(%rbp)
lea    0xa6a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x644(%rbp),%esi
call   1080 <displayBinary@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x648,%rsp
mov    %rsi,%r12
cmp    $0x2,%edi
jg     11bc <main+0x3c>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe53(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13aa <main+0x22a>
mov    %edi,%ebx
mov    0x8(%r12),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     135a <main+0x1da>
mov    %rax,%r15
mov    0x8(%r12),%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   10a0 <hexToBin@plt>
test   %eax,%eax
jle    1376 <main+0x1f6>
mov    %eax,%ebp
movzbl (%r15),%r14d
lea    -0x4e(%r14),%eax
cmp    %ebx,%eax
jne    1388 <main+0x208>
mov    %r14d,%ebx
add    $0xffffffb0,%ebx
mov    $0x1,%eax
mov    $0x1,%r13d
cmp    $0x51,%r14b
mov    %ebp,0xc(%rsp)
jb     1288 <main+0x108>
mov    %r14,0x10(%rsp)
mov    %ebx,0x8(%rsp)
mov    %ebx,%r14d
xor    %ebp,%ebp
lea    0x60(%rsp),%rbx
xor    %r13d,%r13d
xchg   %ax,%ax
mov    0x10(%r12,%rbp,8),%rdi
mov    %rbx,%rsi
mov    $0x64,%edx
call   10a0 <hexToBin@plt>
mov    %eax,0x20(%rsp,%rbp,4)
test   %eax,%eax
jle    13d1 <main+0x251>
add    %eax,%r13d
add    $0x1,%r13d
add    $0x1,%rbp
add    $0x64,%rbx
cmp    %rbp,%r14
jne    1240 <main+0xc0>
add    $0x1,%r13d
mov    0xc(%rsp),%ebp
mov    0x10(%rsp),%r14
mov    0x8(%rsp),%ebx
mov    $0x1,%eax
cmp    $0x100,%ebp
setb   0x10(%rsp)
sbb    $0xffffffff,%eax
xor    %r12d,%r12d
cmp    $0x4c,%ebp
setge  0x8(%rsp)
cmovl  %r12d,%eax
add    %ebp,%r13d
add    %eax,%r13d
mov    %r13d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     13bf <main+0x23f>
mov    %rax,%r13
mov    %r15,0x18(%rsp)
movb   $0x0,(%rax)
mov    $0x1,%eax
cmp    $0x51,%r14b
jb     1324 <main+0x1a4>
mov    %ebx,%r14d
mov    $0x1,%eax
lea    0x60(%rsp),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp,%rbx,4),%r12d
movslq %eax,%r15
mov    %r12b,0x0(%r13,%r15,1)
lea    (%r15,%r13,1),%rdi
add    $0x1,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1070 <memcpy@plt>
lea    (%r15,%r12,1),%eax
add    $0x1,%eax
add    $0x1,%rbx
add    $0x64,%rbp
cmp    %rbx,%r14
jne    12f0 <main+0x170>
mov    0xc(%rsp),%ebp
cmp    $0x4b,%ebp
jle    13f2 <main+0x272>
mov    0x8(%rsp),%cl
and    0x10(%rsp),%cl
mov    0x18(%rsp),%r14
je     1402 <main+0x282>
lea    0x1(%rax),%ecx
movslq %eax,%rdx
movb   $0x4c,0x0(%r13,%rdx,1)
add    $0x2,%eax
mov    %ebp,%edx
jmp    1422 <main+0x2a2>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13aa <main+0x22a>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0xcd0(%rip),%rsi
jmp    1398 <main+0x218>
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
lea    0xcd5(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x648,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
jmp    139b <main+0x21b>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
add    $0x1,%ebp
lea    0xca6(%rip),%rsi
xor    %r12d,%r12d
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13a2 <main+0x222>
movslq %eax,%rcx
add    $0x1,%eax
mov    %bpl,0x0(%r13,%rcx,1)
mov    0x18(%rsp),%r14
cmp    $0x100,%ebp
jl     142a <main+0x2aa>
cltq
movb   $0x4d,0x0(%r13,%rax,1)
lea    0x2(%rax),%ecx
mov    %bpl,0x1(%r13,%rax,1)
mov    %ebp,%edx
shr    $0x8,%edx
add    $0x3,%eax
movslq %ecx,%rcx
mov    %dl,0x0(%r13,%rcx,1)
movslq %eax,%rbx
mov    %r13,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    %ebp,%ebx
lea    0xc73(%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,%r12d
jmp    13aa <main+0x22a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"Usage : %s [redeemScript] M*[signature + hashtype]\0A\00"
@.str.1 = [34 x i8] c"Failed to allocate redeem script\0A\00"
@.str.2 = [23 x i8] c"Invalid redeem script\0A\00"
@.str.3 = [29 x i8] c"Invalid number of arguments\0A\00"
@.str.4 = [22 x i8] c"Invalid signature %d\0A\00"
@.str.5 = [33 x i8] c"Failed to allocate input script\0A\00"
@.str.6 = [16 x i8] c"Input script : \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 [1500 x i8]
%9 = alloca [15 x i32]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %13
store i32 0, i32* %14
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 0, i32* %3
br label %251
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
%29 = sdiv i32 %28, 2
store i32 %29, i32* %15
%30 = load i32, i32* %15
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %251
38: ; preds = %24
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i8*, i8** %6
%43 = load i32, i32* %15
%44 = call i32 @hexToBin(i8* %41, i8* %42, i32 %43)
store i32 %44, i32* %15
%45 = load i32, i32* %15
%46 = icmp sle i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %38
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%50 = load i8*, i8** %6
%51 = call i32 @free(i8* %50)
store i32 0, i32* %3
br label %251
52: ; preds = %38
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 0
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = sub nsw i32 %56, 80
store i32 %57, i32* %11
%58 = load i32, i32* %4
%59 = load i32, i32* %11
%60 = add nsw i32 2, %59
%61 = icmp ne i32 %58, %60
br i1 %61, label %62, label %67
62: ; preds = %52
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%65 = load i8*, i8** %6
%66 = call i32 @free(i8* %65)
store i32 0, i32* %3
br label %251
67: ; preds = %52
store i32 0, i32* %12
br label %68
68: ; preds = %107, %67
%69 = load i32, i32* %12
%70 = load i32, i32* %11
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %110
72: ; preds = %68
%73 = load i8**, i8*** %5
%74 = load i32, i32* %12
%75 = add nsw i32 2, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %73, i64 %76
%78 = load i8*, i8** %77
%79 = load i32, i32* %12
%80 = mul nsw i32 100, %79
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [1500 x i8], [1500 x i8]* %8, i64 0, i64 %81
%83 = call i32 @hexToBin(i8* %78, i8* %82, i32 100)
%84 = load i32, i32* %12
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [15 x i32], [15 x i32]* %9, i64 0, i64 %85
store i32 %83, i32* %86
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [15 x i32], [15 x i32]* %9, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = icmp sle i32 %90, 0
br i1 %91, label %92, label %99
92: ; preds = %72
%93 = load i32, i32* @stderr
%94 = load i32, i32* %12
%95 = add nsw i32 %94, 1
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %95)
%97 = load i8*, i8** %6
%98 = call i32 @free(i8* %97)
store i32 0, i32* %3
br label %251
99: ; preds = %72
%100 = load i32, i32* %12
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [15 x i32], [15 x i32]* %9, i64 0, i64 %101
%103 = load i32, i32* %102
%104 = add nsw i32 %103, 1
%105 = load i32, i32* %13
%106 = add nsw i32 %105, %104
store i32 %106, i32* %13
br label %107
107: ; preds = %99
%108 = load i32, i32* %12
%109 = add nsw i32 %108, 1
store i32 %109, i32* %12
br label %68
110: ; preds = %68
%111 = load i32, i32* %15
%112 = icmp sge i32 %111, 76
br i1 %112, label %113, label %119
113: ; preds = %110
%114 = load i32, i32* %15
%115 = icmp sgt i32 %114, 255
br i1 %115, label %116, label %117
116: ; preds = %113
store i32 2, i32* %14
br label %118
117: ; preds = %113
store i32 1, i32* %14
br label %118
118: ; preds = %117, %116
br label %119
119: ; preds = %118, %110
%120 = load i32, i32* %13
%121 = add nsw i32 1, %120
%122 = load i32, i32* %15
%123 = add nsw i32 %121, %122
%124 = load i32, i32* %14
%125 = add nsw i32 %123, %124
%126 = call i64 @malloc(i32 %125)
%127 = inttoptr i64 %126 to i8*
store i8* %127, i8** %7
%128 = load i8*, i8** %7
%129 = icmp eq i8* %128, null
br i1 %129, label %130, label %135
130: ; preds = %119
%131 = load i32, i32* @stderr
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%133 = load i8*, i8** %6
%134 = call i32 @free(i8* %133)
store i32 0, i32* %3
br label %251
135: ; preds = %119
%136 = load i8*, i8** %7
%137 = load i32, i32* %10
%138 = add nsw i32 %137, 1
store i32 %138, i32* %10
%139 = sext i32 %137 to i64
%140 = getelementptr inbounds i8, i8* %136, i64 %139
store i8 0, i8* %140
store i32 0, i32* %12
br label %141
141: ; preds = %175, %135
%142 = load i32, i32* %12
%143 = load i32, i32* %11
%144 = icmp slt i32 %142, %143
br i1 %144, label %145, label %178
145: ; preds = %141
%146 = load i32, i32* %12
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [15 x i32], [15 x i32]* %9, i64 0, i64 %147
%149 = load i32, i32* %148
%150 = trunc i32 %149 to i8
%151 = load i8*, i8** %7
%152 = load i32, i32* %10
%153 = add nsw i32 %152, 1
store i32 %153, i32* %10
%154 = sext i32 %152 to i64
%155 = getelementptr inbounds i8, i8* %151, i64 %154
store i8 %150, i8* %155
%156 = load i8*, i8** %7
%157 = load i32, i32* %10
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %156, i64 %158
%160 = load i32, i32* %12
%161 = mul nsw i32 100, %160
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds [1500 x i8], [1500 x i8]* %8, i64 0, i64 %162
%164 = load i32, i32* %12
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds [15 x i32], [15 x i32]* %9, i64 0, i64 %165
%167 = load i32, i32* %166
%168 = call i32 @memcpy(i8* %159, i8* %163, i32 %167)
%169 = load i32, i32* %12
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [15 x i32], [15 x i32]* %9, i64 0, i64 %170
%172 = load i32, i32* %171
%173 = load i32, i32* %10
%174 = add nsw i32 %173, %172
store i32 %174, i32* %10
br label %175
175: ; preds = %145
%176 = load i32, i32* %12
%177 = add nsw i32 %176, 1
store i32 %177, i32* %12
br label %141
178: ; preds = %141
%179 = load i32, i32* %14
%180 = icmp eq i32 %179, 0
br i1 %180, label %181, label %189
181: ; preds = %178
%182 = load i32, i32* %15
%183 = trunc i32 %182 to i8
%184 = load i8*, i8** %7
%185 = load i32, i32* %10
%186 = add nsw i32 %185, 1
store i32 %186, i32* %10
%187 = sext i32 %185 to i64
%188 = getelementptr inbounds i8, i8* %184, i64 %187
store i8 %183, i8* %188
br label %189
189: ; preds = %181, %178
%190 = load i32, i32* %14
%191 = icmp eq i32 %190, 1
br i1 %191, label %192, label %205
192: ; preds = %189
%193 = load i8*, i8** %7
%194 = load i32, i32* %10
%195 = add nsw i32 %194, 1
store i32 %195, i32* %10
%196 = sext i32 %194 to i64
%197 = getelementptr inbounds i8, i8* %193, i64 %196
store i8 76, i8* %197
%198 = load i32, i32* %15
%199 = trunc i32 %198 to i8
%200 = load i8*, i8** %7
%201 = load i32, i32* %10
%202 = add nsw i32 %201, 1
store i32 %202, i32* %10
%203 = sext i32 %201 to i64
%204 = getelementptr inbounds i8, i8* %200, i64 %203
store i8 %199, i8* %204
br label %232
205: ; preds = %189
%206 = load i32, i32* %14
%207 = icmp eq i32 %206, 2
br i1 %207, label %208, label %231
208: ; preds = %205
%209 = load i8*, i8** %7
%210 = load i32, i32* %10
%211 = add nsw i32 %210, 1
store i32 %211, i32* %10
%212 = sext i32 %210 to i64
%213 = getelementptr inbounds i8, i8* %209, i64 %212
store i8 77, i8* %213
%214 = load i32, i32* %15
%215 = and i32 %214, 255
%216 = trunc i32 %215 to i8
%217 = load i8*, i8** %7
%218 = load i32, i32* %10
%219 = add nsw i32 %218, 1
store i32 %219, i32* %10
%220 = sext i32 %218 to i64
%221 = getelementptr inbounds i8, i8* %217, i64 %220
store i8 %216, i8* %221
%222 = load i32, i32* %15
%223 = ashr i32 %222, 8
%224 = and i32 %223, 255
%225 = trunc i32 %224 to i8
%226 = load i8*, i8** %7
%227 = load i32, i32* %10
%228 = add nsw i32 %227, 1
store i32 %228, i32* %10
%229 = sext i32 %227 to i64
%230 = getelementptr inbounds i8, i8* %226, i64 %229
store i8 %225, i8* %230
br label %231
231: ; preds = %208, %205
br label %232
232: ; preds = %231, %192
%233 = load i8*, i8** %7
%234 = load i32, i32* %10
%235 = sext i32 %234 to i64
%236 = getelementptr inbounds i8, i8* %233, i64 %235
%237 = load i8*, i8** %6
%238 = load i32, i32* %15
%239 = call i32 @memcpy(i8* %236, i8* %237, i32 %238)
%240 = load i8*, i8** %6
%241 = call i32 @free(i8* %240)
%242 = load i32, i32* %15
%243 = load i32, i32* %10
%244 = add nsw i32 %243, %242
store i32 %244, i32* %10
%245 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%246 = load i8*, i8** %7
%247 = load i32, i32* %10
%248 = call i32 @displayBinary(i8* %246, i32 %247)
%249 = load i8*, i8** %7
%250 = call i32 @free(i8* %249)
store i32 1, i32* %3
br label %251
251: ; preds = %232, %130, %92, %62, %47, %35, %18
%252 = load i32, i32* %3
ret i32 %252
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"Usage : %s [redeemScript] M*[signature + hashtype]\0A\00"
@.str.1 = [34 x i8] c"Failed to allocate redeem script\0A\00"
@.str.2 = [23 x i8] c"Invalid redeem script\0A\00"
@.str.3 = [29 x i8] c"Invalid number of arguments\0A\00"
@.str.4 = [22 x i8] c"Invalid signature %d\0A\00"
@.str.5 = [33 x i8] c"Failed to allocate input script\0A\00"
@.str.6 = [16 x i8] c"Input script : \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1500 x i8]
%4 = alloca [15 x i32]
%5 = getelementptr inbounds [1500 x i8], [1500 x i8]* %3, i64 0, i64 0
%6 = bitcast [15 x i32]* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %149
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = sdiv i32 %15, 2
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %149
23: ; preds = %12
%24 = load i8*, i8** %13
%25 = tail call i32 @hexToBin(i8* %24, i8* %18, i32 %16)
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @free(i8* %18)
br label %149
31: ; preds = %23
%32 = load i8, i8* %18
%33 = zext i8 %32 to i32
%34 = add nsw i32 %33, -80
%35 = add nsw i32 %33, -78
%36 = icmp eq i32 %35, %0
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = icmp ugt i8 %32, 80
br i1 %38, label %39, label %69
39: ; preds = %37
%40 = zext i32 %34 to i64
br label %45
41: ; preds = %31
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%44 = tail call i32 @free(i8* %18)
br label %149
45: ; preds = %39, %62
%46 = phi i64 [ 0, %39 ], [ %65, %62 ]
%47 = phi i32 [ 0, %39 ], [ %64, %62 ]
%48 = add nuw nsw i64 %46, 2
%49 = getelementptr inbounds i8*, i8** %1, i64 %48
%50 = load i8*, i8** %49
%51 = mul nuw nsw i64 %46, 100
%52 = getelementptr inbounds [1500 x i8], [1500 x i8]* %3, i64 0, i64 %51
%53 = call i32 @hexToBin(i8* %50, i8* %52, i32 100)
%54 = getelementptr inbounds [15 x i32], [15 x i32]* %4, i64 0, i64 %46
store i32 %53, i32* %54
%55 = icmp slt i32 %53, 1
br i1 %55, label %56, label %62
56: ; preds = %45
%57 = trunc i64 %46 to i32
%58 = load i32, i32* @stderr
%59 = add nuw nsw i32 %57, 1
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %59)
%61 = call i32 @free(i8* %18)
br label %149
62: ; preds = %45
%63 = add i32 %47, 1
%64 = add i32 %63, %53
%65 = add nuw nsw i64 %46, 1
%66 = icmp eq i64 %65, %40
br i1 %66, label %67, label %45
67: ; preds = %62
%68 = add i32 %64, 1
br label %69
69: ; preds = %67, %37
%70 = phi i32 [ 1, %37 ], [ %68, %67 ]
%71 = icmp sgt i32 %25, 75
%72 = icmp ugt i32 %25, 255
%73 = xor i1 %72, true
%74 = select i1 %72, i32 2, i32 1
%75 = and i1 %71, %73
%76 = icmp sgt i32 %25, 255
%77 = select i1 %71, i32 %74, i32 0
%78 = add nsw i32 %70, %25
%79 = add nsw i32 %78, %77
%80 = call i64 @malloc(i32 %79)
%81 = inttoptr i64 %80 to i8*
%82 = icmp eq i64 %80, 0
br i1 %82, label %83, label %87
83: ; preds = %69
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%86 = call i32 @free(i8* %18)
br label %149
87: ; preds = %69
store i8 0, i8* %81
br i1 %38, label %88, label %107
88: ; preds = %87
%89 = zext i32 %34 to i64
br label %90
90: ; preds = %88, %90
%91 = phi i64 [ 0, %88 ], [ %105, %90 ]
%92 = phi i32 [ 1, %88 ], [ %104, %90 ]
%93 = getelementptr inbounds [15 x i32], [15 x i32]* %4, i64 0, i64 %91
%94 = load i32, i32* %93
%95 = trunc i32 %94 to i8
%96 = add nsw i32 %92, 1
%97 = sext i32 %92 to i64
%98 = getelementptr inbounds i8, i8* %81, i64 %97
store i8 %95, i8* %98
%99 = sext i32 %96 to i64
%100 = getelementptr inbounds i8, i8* %81, i64 %99
%101 = mul nuw nsw i64 %91, 100
%102 = getelementptr inbounds [1500 x i8], [1500 x i8]* %3, i64 0, i64 %101
%103 = call i32 @memcpy(i8* %100, i8* %102, i32 %94)
%104 = add nsw i32 %94, %96
%105 = add nuw nsw i64 %91, 1
%106 = icmp eq i64 %105, %89
br i1 %106, label %107, label %90
107: ; preds = %90, %87
%108 = phi i32 [ 1, %87 ], [ %104, %90 ]
br i1 %71, label %114, label %109
109: ; preds = %107
%110 = trunc i32 %25 to i8
%111 = add nsw i32 %108, 1
%112 = sext i32 %108 to i64
%113 = getelementptr inbounds i8, i8* %81, i64 %112
store i8 %110, i8* %113
br label %120
114: ; preds = %107
br i1 %75, label %115, label %120
115: ; preds = %114
%116 = add nsw i32 %108, 1
%117 = sext i32 %108 to i64
%118 = getelementptr inbounds i8, i8* %81, i64 %117
store i8 76, i8* %118
%119 = add nsw i32 %108, 2
br label %132
120: ; preds = %109, %114
%121 = phi i32 [ %111, %109 ], [ %108, %114 ]
br i1 %76, label %122, label %139
122: ; preds = %120
%123 = add nsw i32 %121, 1
%124 = sext i32 %121 to i64
%125 = getelementptr inbounds i8, i8* %81, i64 %124
store i8 77, i8* %125
%126 = trunc i32 %25 to i8
%127 = add nsw i32 %121, 2
%128 = sext i32 %123 to i64
%129 = getelementptr inbounds i8, i8* %81, i64 %128
store i8 %126, i8* %129
%130 = lshr i32 %25, 8
%131 = add nsw i32 %121, 3
br label %132
132: ; preds = %115, %122
%133 = phi i32 [ %127, %122 ], [ %116, %115 ]
%134 = phi i32 [ %130, %122 ], [ %25, %115 ]
%135 = phi i32 [ %131, %122 ], [ %119, %115 ]
%136 = trunc i32 %134 to i8
%137 = sext i32 %133 to i64
%138 = getelementptr inbounds i8, i8* %81, i64 %137
store i8 %136, i8* %138
br label %139
139: ; preds = %132, %120
%140 = phi i32 [ %121, %120 ], [ %135, %132 ]
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds i8, i8* %81, i64 %141
%143 = call i32 @memcpy(i8* %142, i8* %18, i32 %25)
%144 = call i32 @free(i8* %18)
%145 = add nsw i32 %140, %25
%146 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%147 = call i32 @displayBinary(i8* %81, i32 %145)
%148 = call i32 @free(i8* %81)
br label %149
149: ; preds = %139, %83, %56, %41, %27, %20, %8
%150 = phi i32 [ 0, %8 ], [ 0, %20 ], [ 0, %27 ], [ 0, %41 ], [ 0, %56 ], [ 0, %83 ], [ 1, %139 ]
ret i32 %150
}