#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*/ assert(int);
int decode_digit(char const);
int decode_hex(const char *inbuf, size_t inlen, unsigned char *outbuf) {
  assert(inlen % 2 == 0);
  size_t outlen = inlen / 2;
  for (size_t i = 0; i < outlen; ++i) {
    outbuf[i] =
        16 * decode_digit(inbuf[i * 2]) + decode_digit(inbuf[i * 2 + 1]);
  }
  return outlen;
}


x86 assembly (clang, -O0):
<decode_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11c5 <decode_hex+0xa5>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <decode_digit@plt>
shl    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1030 <decode_digit@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1161 <decode_hex+0x41>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
mov    %r12d,%edi
not    %edi
and    $0x1,%edi
call   1040 <assert@plt>
mov    %r12,%r15
shr    %r15
cmp    $0x2,%r12
jb     118a <decode_hex+0x6a>
cmp    $0x2,%r15
mov    $0x1,%r12d
cmovae %r15,%r12
xor    %ebx,%ebx
nopl   (%rax)
movsbl 0x0(%r13,%rbx,2),%edi
call   1030 <decode_digit@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%r13,%rbx,2),%edi
call   1030 <decode_digit@plt>
add    %ebp,%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <decode_hex+0x40>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decode_hex(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%9 = load i64, i64* %5
%10 = urem i64 %9, 2
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %5
%15 = udiv i64 %14, 2
store i64 %15, i64* %7
store i64 0, i64* %8
br label %16
16: ; preds = %40, %3
%17 = load i64, i64* %8
%18 = load i64, i64* %7
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load i64, i64* %8
%23 = mul i64 %22, 2
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @decode_digit(i8 signext %25)
%27 = mul nsw i32 16, %26
%28 = load i8*, i8** %4
%29 = load i64, i64* %8
%30 = mul i64 %29, 2
%31 = add i64 %30, 1
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @decode_digit(i8 signext %33)
%35 = add nsw i32 %27, %34
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %6
%38 = load i64, i64* %8
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 %36, i8* %39
br label %40
40: ; preds = %20
%41 = load i64, i64* %8
%42 = add i64 %41, 1
store i64 %42, i64* %8
br label %16
43: ; preds = %16
%44 = load i64, i64* %7
%45 = trunc i64 %44 to i32
ret i32 %45
}

LLVM IR (-O2):
define i32 @decode_hex(i8* nocapture %0, i64 %1, i8* nocapture writeonly %2) {
%4 = trunc i64 %1 to i32
%5 = and i32 %4, 1
%6 = xor i32 %5, 1
%7 = tail call i32 @assert(i32 %6)
%8 = lshr i64 %1, 1
%9 = icmp ult i64 %1, 2
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = call i64 @llvm.umax.i64(i64 %8, i64 1)
br label %14
12: ; preds = %14, %3
%13 = trunc i64 %8 to i32
ret i32 %13
14: ; preds = %10, %14
%15 = phi i64 [ %28, %14 ], [ 0, %10 ]
%16 = shl nuw i64 %15, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i32 @decode_digit(i8 signext %18)
%20 = shl nsw i32 %19, 4
%21 = or i64 %16, 1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @decode_digit(i8 signext %23)
%25 = add nsw i32 %24, %20
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds i8, i8* %2, i64 %15
store i8 %26, i8* %27
%28 = add nuw nsw i64 %15, 1
%29 = icmp eq i64 %28, %11
br i1 %29, label %12, label %14
}