#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__ addHexDigit(int *, int /*<<< orphan*/);
int decHexString(unsigned char *hex, char *hexString, int len) {
  int val;
  while (len-- > 0) {
    val = 0;
    if (addHexDigit(&val, *hexString++) < 0 ||
        addHexDigit(&val, *hexString++) < 0)
      return -1;
    *hex++ = (unsigned char)val;
  }
  return 0;
}


x86 assembly (clang, -O0):
<decHexString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11af <decHexString+0x9f>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <addHexDigit@plt>
cmp    $0x0,%rax
jl     1188 <decHexString+0x78>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <addHexDigit@plt>
cmp    $0x0,%rax
jge    1194 <decHexString+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <decHexString+0xa6>
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1123 <decHexString+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decHexString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1182 <decHexString+0x72>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
add    $0x1,%ebx
xor    %ebp,%ebp
lea    0x4(%rsp),%r12
mov    $0xffffffff,%r13d
nopw   0x0(%rax,%rax,1)
movl   $0x0,0x4(%rsp)
movsbl (%r14,%rbp,2),%esi
mov    %r12,%rdi
call   1030 <addHexDigit@plt>
test   %rax,%rax
js     1185 <decHexString+0x75>
movsbl 0x1(%r14,%rbp,2),%esi
mov    %r12,%rdi
call   1030 <addHexDigit@plt>
test   %rax,%rax
js     1185 <decHexString+0x75>
movzbl 0x4(%rsp),%eax
mov    %al,(%r15,%rbp,1)
add    $0xffffffff,%ebx
add    $0x1,%rbp
cmp    $0x1,%ebx
ja     1140 <decHexString+0x30>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decHexString(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
br label %9
9: ; preds = %28, %3
%10 = load i32, i32* %7
%11 = add nsw i32 %10, -1
store i32 %11, i32* %7
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %33
13: ; preds = %9
store i32 0, i32* %8
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %6
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = call i64 @addHexDigit(i32* %8, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %6
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
%25 = call i64 @addHexDigit(i32* %8, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20, %13
store i32 -1, i32* %4
br label %34
28: ; preds = %20
%29 = load i32, i32* %8
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
store i8 %30, i8* %31
br label %9
33: ; preds = %9
store i32 0, i32* %4
br label %34
34: ; preds = %33, %27
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @decHexString(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %28
7: ; preds = %3, %22
%8 = phi i32 [ %11, %22 ], [ %2, %3 ]
%9 = phi i8* [ %23, %22 ], [ %1, %3 ]
%10 = phi i8* [ %26, %22 ], [ %0, %3 ]
%11 = add nsw i32 %8, -1
store i32 0, i32* %4
%12 = load i8, i8* %9
%13 = sext i8 %12 to i32
%14 = call i64 @addHexDigit(i32* %4, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %7
%17 = getelementptr inbounds i8, i8* %9, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i64 @addHexDigit(i32* %4, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = getelementptr inbounds i8, i8* %9, i64 2
%24 = load i32, i32* %4
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %25, i8* %10
%27 = icmp ugt i32 %8, 1
br i1 %27, label %7, label %28
28: ; preds = %16, %7, %22, %3
%29 = phi i32 [ 0, %3 ], [ 0, %22 ], [ -1, %7 ], [ -1, %16 ]
ret i32 %29
}