#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*/ signature;
typedef int /*<<< orphan*/ publicKey;

/* 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 main(int argc, char **argv) {
  unsigned char *inputScript;
  unsigned char signature[100];
  unsigned char publicKey[100];
  int signatureLength;
  int publicKeyLength;
  int offset = 0;
  if (argc < 3) {
    fprintf(stderr, "Usage : %s [signature + hashtype] [public key]\n",
            argv[0]);
    return 0;
  }
  signatureLength = hexToBin(argv[1], signature, sizeof(signature));
  if (signatureLength <= 0) {
    fprintf(stderr, "Invalid signature\n");
    return 0;
  }
  publicKeyLength = hexToBin(argv[2], publicKey, sizeof(publicKey));
  if (publicKeyLength <= 0) {
    fprintf(stderr, "Invalid public key\n");
    return 0;
  }
  inputScript = (unsigned char *)malloc(signatureLength + publicKeyLength + 2);
  if (inputScript == NULL) {
    fprintf(stderr, "Failed to allocate input script\n");
    return 0;
  }
  inputScript[offset++] = signatureLength;
  memcpy(inputScript + offset, signature, signatureLength);
  offset += signatureLength;
  inputScript[offset++] = publicKeyLength;
  memcpy(inputScript + offset, publicKey, publicKeyLength);
  offset += publicKeyLength;
  printf("Input script : ");
  displayBinary(inputScript, offset);
  free(inputScript);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xfc(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c7 <main+0x57>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137a <main+0x20a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1090 <hexToBin@plt>
mov    %eax,-0xf4(%rbp)
cmpl   $0x0,-0xf4(%rbp)
jg     1213 <main+0xa3>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137a <main+0x20a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0xf0(%rbp),%rsi
mov    $0x64,%edx
call   1090 <hexToBin@plt>
mov    %eax,-0xf8(%rbp)
cmpl   $0x0,-0xf8(%rbp)
jg     1262 <main+0xf2>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137a <main+0x20a>
mov    -0xf4(%rbp),%edi
add    -0xf8(%rbp),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12a8 <main+0x138>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137a <main+0x20a>
mov    -0xf4(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0xfc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xfc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
movslq -0xfc(%rbp),%rax
add    %rax,%rdi
lea    -0x80(%rbp),%rsi
mov    -0xf4(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0xf4(%rbp),%eax
add    -0xfc(%rbp),%eax
mov    %eax,-0xfc(%rbp)
mov    -0xf8(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0xfc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xfc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
movslq -0xfc(%rbp),%rax
add    %rax,%rdi
lea    -0xf0(%rbp),%rsi
mov    -0xf8(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0xf8(%rbp),%eax
add    -0xfc(%rbp),%eax
mov    %eax,-0xfc(%rbp)
lea    0xd22(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xfc(%rbp),%esi
call   1070 <displayBinary@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe0,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     11a8 <main+0x38>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe66(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    128b <main+0x11b>
mov    0x8(%rbx),%rdi
lea    0x70(%rsp),%rsi
mov    $0x64,%edx
call   1090 <hexToBin@plt>
test   %eax,%eax
jle    124e <main+0xde>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
mov    %rsp,%rsi
mov    $0x64,%edx
call   1090 <hexToBin@plt>
test   %eax,%eax
jle    1260 <main+0xf0>
mov    %eax,%r15d
lea    (%r15,%rbp,1),%r14d
add    $0x2,%r14d
mov    %r14d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1272 <main+0x102>
mov    %rax,%rbx
lea    0x2(%rbp),%r12d
mov    %bpl,(%rax)
lea    0x1(%rax),%rdi
lea    0x70(%rsp),%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
mov    %ebp,%eax
mov    %r15b,0x1(%rax,%rbx,1)
mov    %r12d,%edi
add    %rbx,%rdi
mov    %rsp,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <displayBinary@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
jmp    128b <main+0x11b>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
jmp    1282 <main+0x112>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
jmp    1282 <main+0x112>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"Usage : %s [signature + hashtype] [public key]\0A\00"
@.str.1 = [19 x i8] c"Invalid signature\0A\00"
@.str.2 = [20 x i8] c"Invalid public key\0A\00"
@.str.3 = [33 x i8] c"Failed to allocate input script\0A\00"
@.str.4 = [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 [100 x i8]
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 0, i32* %3
br label %95
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%25 = call i32 @hexToBin(i8* %23, i8* %24, i32 100)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %95
31: ; preds = %20
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%36 = call i32 @hexToBin(i8* %34, i8* %35, i32 100)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp sle i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %95
42: ; preds = %31
%43 = load i32, i32* %9
%44 = load i32, i32* %10
%45 = add nsw i32 %43, %44
%46 = add nsw i32 %45, 2
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** %6
%49 = load i8*, i8** %6
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %42
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %95
54: ; preds = %42
%55 = load i32, i32* %9
%56 = trunc i32 %55 to i8
%57 = load i8*, i8** %6
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
store i8 %56, i8* %61
%62 = load i8*, i8** %6
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%67 = load i32, i32* %9
%68 = call i32 @memcpy(i8* %65, i8* %66, i32 %67)
%69 = load i32, i32* %9
%70 = load i32, i32* %11
%71 = add nsw i32 %70, %69
store i32 %71, i32* %11
%72 = load i32, i32* %10
%73 = trunc i32 %72 to i8
%74 = load i8*, i8** %6
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
%77 = sext i32 %75 to i64
%78 = getelementptr inbounds i8, i8* %74, i64 %77
store i8 %73, i8* %78
%79 = load i8*, i8** %6
%80 = load i32, i32* %11
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%84 = load i32, i32* %10
%85 = call i32 @memcpy(i8* %82, i8* %83, i32 %84)
%86 = load i32, i32* %10
%87 = load i32, i32* %11
%88 = add nsw i32 %87, %86
store i32 %88, i32* %11
%89 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%90 = load i8*, i8** %6
%91 = load i32, i32* %11
%92 = call i32 @displayBinary(i8* %90, i32 %91)
%93 = load i8*, i8** %6
%94 = call i32 @free(i8* %93)
store i32 1, i32* %3
br label %95
95: ; preds = %54, %51, %39, %28, %14
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [48 x i8] c"Usage : %s [signature + hashtype] [public key]\0A\00"
@.str.1 = [19 x i8] c"Invalid signature\0A\00"
@.str.2 = [20 x i8] c"Invalid public key\0A\00"
@.str.3 = [33 x i8] c"Failed to allocate input script\0A\00"
@.str.4 = [16 x i8] c"Input script : \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%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 ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %51
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @hexToBin(i8* %14, i8* %5, i32 100)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %51
20: ; preds = %12
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @hexToBin(i8* %22, i8* %6, i32 100)
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %51
28: ; preds = %20
%29 = add nuw i32 %15, 2
%30 = add i32 %29, %23
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
%33 = icmp eq i64 %31, 0
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %51
37: ; preds = %28
%38 = trunc i32 %15 to i8
store i8 %38, i8* %32
%39 = getelementptr inbounds i8, i8* %32, i64 1
%40 = call i32 @memcpy(i8* %39, i8* %5, i32 %15)
%41 = add nuw nsw i32 %15, 1
%42 = trunc i32 %23 to i8
%43 = zext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %32, i64 %43
store i8 %42, i8* %44
%45 = zext i32 %29 to i64
%46 = getelementptr inbounds i8, i8* %32, i64 %45
%47 = call i32 @memcpy(i8* %46, i8* %6, i32 %23)
%48 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @displayBinary(i8* %32, i32 %30)
%50 = call i32 @free(i8* %32)
br label %51
51: ; preds = %37, %34, %25, %17, %8
%52 = phi i32 [ 0, %8 ], [ 0, %17 ], [ 0, %25 ], [ 0, %34 ], [ 1, %37 ]
ret i32 %52
}