#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 */
scalar_t__ errno;
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int strtol(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned char *parse_args(int argc, const char **argv) {
  unsigned char *result = NULL;
  if (9 == argc) {
    result = malloc(sizeof(unsigned char) * 8);
    for (int i = 1; i < 9; i++) {
      errno = 0;
      int success = strtol(argv[i], NULL, 0);
      if (errno != 0) {
        printf("Unable to process arg %d, %s\n", i, argv[i]);
        free(result);
        result = NULL;
        break;
      } else {
        result[i - 1] = (unsigned char)success;
      }
    }
  } else {
    printf("Usage: unpack {b0 ... b7}\n");
    printf("Where b0 through b7 are unsigned bytes in hex format");
  }
  return result;
}


x86 assembly (clang, -O0):
<parse_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x9,%eax
cmp    -0x4(%rbp),%eax
jne    121d <parse_args+0xdd>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x9,-0x1c(%rbp)
jge    1218 <parse_args+0xd8>
mov    0x2e55(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e2d(%rip),%rax
cmpq   $0x0,(%rax)
je     11f0 <parse_args+0xb0>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    1218 <parse_args+0xd8>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    120a <parse_args+0xca>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <parse_args+0x3a>
jmp    1239 <parse_args+0xf9>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_args>:
push   %r15
push   %r14
push   %rbx
cmp    $0x9,%edi
jne    12b1 <parse_args+0x161>
mov    %rsi,%r14
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x2e6b(%rip),%r15
movq   $0x0,(%r15)
mov    0x8(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x1,%esi
cmpq   $0x0,(%r15)
jne    1291 <parse_args+0x141>
mov    %al,(%rbx)
movq   $0x0,(%r15)
mov    0x10(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x2,%esi
cmpq   $0x0,(%r15)
jne    1291 <parse_args+0x141>
mov    %al,0x1(%rbx)
movq   $0x0,(%r15)
mov    0x18(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x3,%esi
cmpq   $0x0,(%r15)
jne    1291 <parse_args+0x141>
mov    %al,0x2(%rbx)
movq   $0x0,(%r15)
mov    0x20(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x4,%esi
cmpq   $0x0,(%r15)
jne    1291 <parse_args+0x141>
mov    %al,0x3(%rbx)
movq   $0x0,(%r15)
mov    0x28(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x5,%esi
cmpq   $0x0,(%r15)
jne    1291 <parse_args+0x141>
mov    %al,0x4(%rbx)
movq   $0x0,(%r15)
mov    0x30(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x6,%esi
cmpq   $0x0,(%r15)
jne    1291 <parse_args+0x141>
mov    %al,0x5(%rbx)
movq   $0x0,(%r15)
mov    0x38(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x7,%esi
cmpq   $0x0,(%r15)
jne    1291 <parse_args+0x141>
mov    %al,0x6(%rbx)
movq   $0x0,(%r15)
mov    0x40(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    $0x8,%esi
cmpq   $0x0,(%r15)
je     12d6 <parse_args+0x186>
mov    %esi,%eax
mov    (%r14,%rax,8),%rdx
lea    0xd62(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    12cd <parse_args+0x17d>
lea    0xd9b(%rip),%rdi
call   1040 <puts@plt>
lea    0xd5a(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %al,0x7(%rbx)
jmp    12cd <parse_args+0x17d>

LLVM IR (-O0):
@errno = global i64 0
@.str = [30 x i8] c"Unable to process arg %d, %s\0A\00"
@.str.1 = [27 x i8] c"Usage: unpack {b0 ... b7}\0A\00"
@.str.2 = [53 x i8] c"Where b0 through b7 are unsigned bytes in hex format\00"
define i8* @parse_args(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* null, i8** %5
%8 = load i32, i32* %3
%9 = icmp eq i32 9, %8
br i1 %9, label %10, label %47
10: ; preds = %2
%11 = call i8* @malloc(i32 8)
store i8* %11, i8** %5
store i32 1, i32* %6
br label %12
12: ; preds = %43, %10
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 9
br i1 %14, label %15, label %46
15: ; preds = %12
store i64 0, i64* @errno
%16 = load i8**, i8*** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @strtol(i8* %20, i32* null, i32 0)
store i32 %21, i32* %7
%22 = load i64, i64* @errno
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %15
%25 = load i32, i32* %6
%26 = load i8**, i8*** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %25, i8* %30)
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
store i8* null, i8** %5
br label %46
34: ; preds = %15
%35 = load i32, i32* %7
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
br label %42
42: ; preds = %34
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %12
46: ; preds = %24, %12
br label %50
47: ; preds = %2
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %47, %46
%51 = load i8*, i8** %5
ret i8* %51
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [30 x i8] c"Unable to process arg %d, %s\0A\00"
@.str.2 = [53 x i8] c"Where b0 through b7 are unsigned bytes in hex format\00"
@str = [26 x i8] c"Usage: unpack {b0 ... b7}\00"
define noalias i8* @parse_args(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 9
br i1 %3, label %4, label %76
4: ; preds = %2
%5 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
store i64 0, i64* @errno
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @strtol(i8* nocapture %7, i32* null, i32 0)
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %65, %57, %49, %41, %33, %25, %18, %4
%12 = phi i32 [ 1, %4 ], [ 2, %18 ], [ 3, %25 ], [ 4, %33 ], [ 5, %41 ], [ 6, %49 ], [ 7, %57 ], [ 8, %65 ]
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %15)
%17 = tail call i32 @free(i8* %5)
br label %79
18: ; preds = %4
%19 = trunc i32 %8 to i8
store i8 %19, i8* %5
store i64 0, i64* @errno
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @strtol(i8* nocapture %21, i32* null, i32 0)
%23 = load i64, i64* @errno
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %11
25: ; preds = %18
%26 = trunc i32 %22 to i8
%27 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %26, i8* %27
store i64 0, i64* @errno
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = tail call i32 @strtol(i8* nocapture %29, i32* null, i32 0)
%31 = load i64, i64* @errno
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %11
33: ; preds = %25
%34 = trunc i32 %30 to i8
%35 = getelementptr inbounds i8, i8* %5, i64 2
store i8 %34, i8* %35
store i64 0, i64* @errno
%36 = getelementptr inbounds i8*, i8** %1, i64 4
%37 = load i8*, i8** %36
%38 = tail call i32 @strtol(i8* nocapture %37, i32* null, i32 0)
%39 = load i64, i64* @errno
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %11
41: ; preds = %33
%42 = trunc i32 %38 to i8
%43 = getelementptr inbounds i8, i8* %5, i64 3
store i8 %42, i8* %43
store i64 0, i64* @errno
%44 = getelementptr inbounds i8*, i8** %1, i64 5
%45 = load i8*, i8** %44
%46 = tail call i32 @strtol(i8* nocapture %45, i32* null, i32 0)
%47 = load i64, i64* @errno
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %11
49: ; preds = %41
%50 = trunc i32 %46 to i8
%51 = getelementptr inbounds i8, i8* %5, i64 4
store i8 %50, i8* %51
store i64 0, i64* @errno
%52 = getelementptr inbounds i8*, i8** %1, i64 6
%53 = load i8*, i8** %52
%54 = tail call i32 @strtol(i8* nocapture %53, i32* null, i32 0)
%55 = load i64, i64* @errno
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %11
57: ; preds = %49
%58 = trunc i32 %54 to i8
%59 = getelementptr inbounds i8, i8* %5, i64 5
store i8 %58, i8* %59
store i64 0, i64* @errno
%60 = getelementptr inbounds i8*, i8** %1, i64 7
%61 = load i8*, i8** %60
%62 = tail call i32 @strtol(i8* nocapture %61, i32* null, i32 0)
%63 = load i64, i64* @errno
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %11
65: ; preds = %57
%66 = trunc i32 %62 to i8
%67 = getelementptr inbounds i8, i8* %5, i64 6
store i8 %66, i8* %67
store i64 0, i64* @errno
%68 = getelementptr inbounds i8*, i8** %1, i64 8
%69 = load i8*, i8** %68
%70 = tail call i32 @strtol(i8* nocapture %69, i32* null, i32 0)
%71 = load i64, i64* @errno
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %11
73: ; preds = %65
%74 = trunc i32 %70 to i8
%75 = getelementptr inbounds i8, i8* %5, i64 7
store i8 %74, i8* %75
br label %79
76: ; preds = %2
%77 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %79
79: ; preds = %73, %11, %76
%80 = phi i8* [ null, %76 ], [ null, %11 ], [ %5, %73 ]
ret i8* %80
}