#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 */
void *valueToHexCh(unsigned char);
int ObjToHex(char *hex, const void *obj, int len) {
  int i = 0;
  unsigned char high, low;
  int tmp = 0;
  const char *o = (const char *)obj;
  if (obj == NULL || hex == NULL) {
    return -1;
  }
  if (len <= 0)
    return -2;
  for (; i < len; i++) {
    tmp = (unsigned char)o[i];
    high = tmp >> 4;
    low = tmp & 15;
    *hex++ = valueToHexCh(high);
    *hex++ = valueToHexCh(low);
  }
  *hex = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<ObjToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     114f <ObjToHex+0x3f>
cmpq   $0x0,-0x10(%rbp)
jne    115b <ObjToHex+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <ObjToHex+0xe7>
cmpl   $0x0,-0x1c(%rbp)
jg     1171 <ObjToHex+0x61>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11f7 <ObjToHex+0xe7>
jmp    1176 <ObjToHex+0x66>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e9 <ObjToHex+0xd9>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
sar    $0x4,%eax
mov    %al,-0x21(%rbp)
mov    -0x28(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x22(%rbp)
movzbl -0x21(%rbp),%edi
call   1030 <valueToHexCh@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
movzbl -0x22(%rbp),%edi
call   1030 <valueToHexCh@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1176 <ObjToHex+0x66>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ObjToHex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     117c <ObjToHex+0x6c>
mov    %rsi,%r14
test   %rsi,%rsi
je     117c <ObjToHex+0x6c>
test   %edx,%edx
jle    1177 <ObjToHex+0x67>
mov    %rdi,%r12
mov    %edx,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%ebp
mov    %ebp,%eax
shr    $0x4,%al
movzbl %al,%edi
call   1030 <valueToHexCh@plt>
mov    %al,(%r12,%rbx,2)
and    $0xf,%ebp
mov    %ebp,%edi
call   1030 <valueToHexCh@plt>
mov    %al,0x1(%r12,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <ObjToHex+0x30>
movb   $0x0,(%r12,%rbx,2)
xor    %eax,%eax
jmp    117c <ObjToHex+0x6c>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ObjToHex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %11
%13 = load i8*, i8** %6
store i8* %13, i8** %12
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %16, %3
store i32 -1, i32* %4
br label %57
20: ; preds = %16
%21 = load i32, i32* %7
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 -2, i32* %4
br label %57
24: ; preds = %20
br label %25
25: ; preds = %52, %24
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %55
29: ; preds = %25
%30 = load i8*, i8** %12
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = ashr i32 %36, 4
%38 = trunc i32 %37 to i8
store i8 %38, i8* %9
%39 = load i32, i32* %11
%40 = and i32 %39, 15
%41 = trunc i32 %40 to i8
store i8 %41, i8* %10
%42 = load i8, i8* %9
%43 = call i8* @valueToHexCh(i8 zeroext %42)
%44 = ptrtoint i8* %43 to i8
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %5
store i8 %44, i8* %45
%47 = load i8, i8* %10
%48 = call i8* @valueToHexCh(i8 zeroext %47)
%49 = ptrtoint i8* %48 to i8
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %5
store i8 %49, i8* %50
br label %52
52: ; preds = %29
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %25
55: ; preds = %25
%56 = load i8*, i8** %5
store i8 0, i8* %56
store i32 0, i32* %4
br label %57
57: ; preds = %55, %23, %19
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
define i32 @ObjToHex(i8* writeonly %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
%5 = icmp eq i8* %0, null
%6 = or i1 %5, %4
br i1 %6, label %29, label %7
7: ; preds = %3
%8 = icmp slt i32 %2, 1
br i1 %8, label %29, label %9
9: ; preds = %7
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %26, %11 ]
%13 = phi i8* [ %0, %9 ], [ %25, %11 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %12
%15 = load i8, i8* %14
%16 = lshr i8 %15, 4
%17 = and i8 %15, 15
%18 = tail call i8* @valueToHexCh(i8 zeroext %16)
%19 = ptrtoint i8* %18 to i64
%20 = trunc i64 %19 to i8
%21 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %20, i8* %13
%22 = tail call i8* @valueToHexCh(i8 zeroext %17)
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i8
%25 = getelementptr inbounds i8, i8* %13, i64 2
store i8 %24, i8* %21
%26 = add nuw nsw i64 %12, 1
%27 = icmp eq i64 %26, %10
br i1 %27, label %28, label %11
28: ; preds = %11
store i8 0, i8* %25
br label %29
29: ; preds = %7, %3, %28
%30 = phi i32 [ 0, %28 ], [ -1, %3 ], [ -2, %7 ]
ret i32 %30
}