#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 */
char asctohex11(char, char);
int /*<<< orphan*/ memcpy(char *, char *, int);
int aschex_to_bcdhex11(char aschex[], int len, char bcdhex[]) {
  int i, j;
  char buf[512];
  memcpy(buf, aschex, len);
  if (len % 2 == 0)
    j = len / 2;
  else
    j = len / 2 + 1;
  for (i = 0; i < j; i++)
    bcdhex[i] = asctohex11(aschex[2 * i], aschex[2 * i + 1]);
  return (j);
}


x86 assembly (clang, -O0):
<aschex_to_bcdhex11>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1170 <aschex_to_bcdhex11+0x50>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
jmp    1181 <aschex_to_bcdhex11+0x61>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11db <aschex_to_bcdhex11+0xbb>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl %dl,%edi
movsbl (%rax,%rcx,1),%esi
call   1040 <asctohex11@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <aschex_to_bcdhex11+0x68>
mov    -0x20(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aschex_to_bcdhex11>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
mov    %r15d,%eax
and    $0x1,%eax
mov    %r15d,%r12d
shr    $0x1f,%r12d
add    %r15d,%r12d
sar    %r12d
add    %eax,%r12d
test   %r12d,%r12d
jle    118b <aschex_to_bcdhex11+0x6b>
mov    %r12d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,2),%edi
movsbl 0x1(%rbx,%rbp,2),%esi
call   1040 <asctohex11@plt>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1170 <aschex_to_bcdhex11+0x50>
mov    %r12d,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @aschex_to_bcdhex11(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32 @memcpy(i8* %10, i8* %11, i32 %12)
%14 = load i32, i32* %5
%15 = srem i32 %14, 2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %5
%19 = sdiv i32 %18, 2
store i32 %19, i32* %8
br label %24
20: ; preds = %3
%21 = load i32, i32* %5
%22 = sdiv i32 %21, 2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %24
24: ; preds = %20, %17
store i32 0, i32* %7
br label %25
25: ; preds = %48, %24
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %51
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = mul nsw i32 2, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = load i8*, i8** %4
%37 = load i32, i32* %7
%38 = mul nsw i32 2, %37
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
%42 = load i8, i8* %41
%43 = call signext i8 @asctohex11(i8 signext %35, i8 signext %42)
%44 = load i8*, i8** %6
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 %43, i8* %47
br label %48
48: ; preds = %29
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %25
51: ; preds = %25
%52 = load i32, i32* %8
ret i32 %52
}

LLVM IR (-O2):
define i32 @aschex_to_bcdhex11(i8* %0, i32 %1, i8* nocapture writeonly %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i32 @memcpy(i8* %5, i8* %0, i32 %1)
%7 = and i32 %1, 1
%8 = sdiv i32 %1, 2
%9 = add nsw i32 %8, %7
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %3
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %23, %13 ]
%15 = shl nuw nsw i64 %14, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = or i64 %15, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = call signext i8 @asctohex11(i8 signext %17, i8 signext %20)
%22 = getelementptr inbounds i8, i8* %2, i64 %14
store i8 %21, i8* %22
%23 = add nuw nsw i64 %14, 1
%24 = icmp eq i64 %23, %12
br i1 %24, label %25, label %13
25: ; preds = %13, %3
ret i32 %9
}