#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__ chk_calloc(int, int);
char hexToChar(int, char *);
char *hexstrToStr(int len, char *s) {
  int reslen = len / 8;
  char *res = (char *)chk_calloc(reslen, sizeof(char));
  int i = 0;
  for (; i < reslen; i++) {
    res[i] = hexToChar(8, &s[i * 8]);
  }
  return res;
}


x86 assembly (clang, -O0):
<hexstrToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <chk_calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1195 <hexstrToStr+0x75>
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rsi
mov    $0x8,%edi
call   1040 <hexToChar@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1155 <hexstrToStr+0x35>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexstrToStr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
lea    0x7(%r15),%ebp
test   %edi,%edi
cmovns %edi,%ebp
sar    $0x3,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <chk_calloc@plt>
mov    %rax,%r14
cmp    $0x8,%r15d
jl     117e <hexstrToStr+0x5e>
mov    %ebp,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x8,%edi
mov    %rbx,%rsi
call   1040 <hexToChar@plt>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
add    $0x8,%rbx
cmp    %rbp,%r15
jne    1160 <hexstrToStr+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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