#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 */
unsigned char hex_get_from_bcd(unsigned char *);
int hex_get_from_char(unsigned char *in, int in_len, unsigned char *hex_out_buf,
                      int hex_out_buf_len) {
  int i;
  if (in_len / 2 > hex_out_buf_len) {
    return -1;
  }
  for (i = 0; i < in_len / 2; i++) {
    hex_out_buf[i] = hex_get_from_bcd(&in[i * 2]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<hex_get_from_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    -0x24(%rbp),%eax
jle    1146 <hex_get_from_char+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <hex_get_from_char+0x91>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    119a <hex_get_from_char+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
call   1030 <hex_get_from_bcd@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114d <hex_get_from_char+0x3d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_get_from_char>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%eax
shr    $0x1f,%eax
add    %esi,%eax
sar    %eax
mov    $0xffffffff,%r15d
cmp    %ecx,%eax
jg     1169 <hex_get_from_char+0x59>
xor    %r15d,%r15d
cmp    $0x2,%esi
jl     1169 <hex_get_from_char+0x59>
mov    %rdx,%r14
mov    %rdi,%r13
mov    %eax,%r12d
xor    %r15d,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1030 <hex_get_from_bcd@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
add    $0x2,%r13
cmp    %rbx,%r12
jne    1150 <hex_get_from_char+0x40>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @hex_get_from_char(i8* %0, i32 %1, i8* nocapture writeonly %2, i32 %3) {
%5 = sdiv i32 %1, 2
%6 = icmp sgt i32 %5, %3
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = icmp sgt i32 %1, 1
br i1 %8, label %9, label %19
9: ; preds = %7
%10 = zext i32 %5 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %17, %11 ]
%13 = shl nuw nsw i64 %12, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = tail call zeroext i8 @hex_get_from_bcd(i8* %14)
%16 = getelementptr inbounds i8, i8* %2, i64 %12
store i8 %15, i8* %16
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %19, label %11
19: ; preds = %11, %7, %4
%20 = phi i32 [ -1, %4 ], [ 0, %7 ], [ 0, %11 ]
ret i32 %20
}