#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 hexStringToArray(char *, int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int main(int nbarg, char *argv[]) {
  unsigned char out[1024];
  int out_bytes, i;
  if (nbarg != 2) {
    printf("Missing parameter\n");
    return 1;
  }
  for (i = 0; i < 1024; ++i)
    out[i] = 0;
  out_bytes = hexStringToArray(argv[1], strlen(argv[1]), out, 1024);
  if (out_bytes == -1) {
    printf("Invalid\n");
    return 2;
  } else {
    printf("Valid (len: %d): ", out_bytes);
  }
  for (i = 0; i < out_bytes; ++i) {
    if (i != 0)
      printf(":");
    printf("%d", out[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     116d <main+0x3d>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1290 <main+0x160>
movl   $0x0,-0x418(%rbp)
cmpl   $0x400,-0x418(%rbp)
jge    11aa <main+0x7a>
movslq -0x418(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    1177 <main+0x47>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x420(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x420(%rbp),%rdi
mov    %eax,%esi
lea    -0x410(%rbp),%rdx
mov    $0x400,%ecx
call   1050 <hexStringToArray@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    120d <main+0xdd>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1290 <main+0x160>
mov    -0x414(%rbp),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0x414(%rbp),%eax
jge    1289 <main+0x159>
cmpl   $0x0,-0x418(%rbp)
je     1258 <main+0x128>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x418(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%esi
ff
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    122b <main+0xfb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jne    1213 <main+0xb3>
mov    %rsi,%rbp
mov    %rsp,%r14
xor    %ebx,%ebx
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x8(%rbp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    $0x400,%ecx
call   1080 <hexStringToArray@plt>
cmp    $0xffffffff,%eax
je     1226 <main+0xc6>
mov    %eax,%ebp
lea    0xe47(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
jle    1237 <main+0xd7>
movzbl (%rsp),%esi
lea    0xe41(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x1,%ebp
je     1237 <main+0xd7>
mov    %ebp,%r15d
mov    $0x1,%ebp
lea    0xe24(%rip),%r14
xor    %ebx,%ebx
mov    $0x3a,%edi
call   1030 <putchar@plt>
movzbl (%rsp,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11f0 <main+0x90>
jmp    1237 <main+0xd7>
lea    0xe03(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    1237 <main+0xd7>
lea    0xde8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Missing parameter\0A\00"
@.str.1 = [9 x i8] c"Invalid\0A\00"
@.str.2 = [18 x i8] c"Valid (len: %d): \00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %62
13: ; preds = %2
store i32 0, i32* %8
br label %14
14: ; preds = %21, %13
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 1024
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %17
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %14
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i32 @hexStringToArray(i8* %27, i32 %31, i8* %32, i32 1024)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %62
38: ; preds = %24
%39 = load i32, i32* %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38
store i32 0, i32* %8
br label %42
42: ; preds = %58, %41
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %61
46: ; preds = %42
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %51
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %42
61: ; preds = %42
store i32 0, i32* %3
br label %62
62: ; preds = %61, %36, %11
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str.2 = [18 x i8] c"Valid (len: %d): \00"
@.str.4 = [3 x i8] c"%d\00"
@str = [8 x i8] c"Invalid\00"
@str.5 = [18 x i8] c"Missing parameter\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = call i32 @hexStringToArray(i8* %9, i32 %10, i8* %4, i32 1024)
%12 = icmp eq i32 %11, -1
br i1 %12, label %15, label %17
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
br label %35
15: ; preds = %6
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %35
17: ; preds = %6
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%19 = icmp sgt i32 %11, 0
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = zext i32 %11 to i64
%22 = load i8, i8* %4
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = icmp eq i32 %11, 1
br i1 %25, label %35, label %26
26: ; preds = %20, %26
%27 = phi i64 [ %33, %26 ], [ 1, %20 ]
%28 = call i32 @putchar(i32 58)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %27
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %27, 1
%34 = icmp eq i64 %33, %21
br i1 %34, label %35, label %26
35: ; preds = %26, %20, %17, %15, %13
%36 = phi i32 [ 1, %13 ], [ 2, %15 ], [ 0, %17 ], [ 0, %20 ], [ 0, %26 ]
ret i32 %36
}