#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*/ sprintf(char *, char *, unsigned char const);
__attribute__((always_)) void uchar2hexchar(const unsigned char *source,
                                            char *result) {
  if (!source || !result)
    return;
  unsigned int i = 0;
  for (; i < 32; i++) {
    sprintf(result, "%02x", source[i]);
    result += 2;
  }
}


x86 assembly (clang, -O0):
<uchar2hexchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1136 <uchar2hexchar+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    113b <uchar2hexchar+0x2b>
jmp    1181 <uchar2hexchar+0x71>
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jae    1181 <uchar2hexchar+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
lea    0xea2(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <uchar2hexchar+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uchar2hexchar>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     115e <uchar2hexchar+0x4e>
mov    %rsi,%r12
test   %rsi,%rsi
je     115e <uchar2hexchar+0x4e>
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xecf(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
add    $0x2,%r12
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    1140 <uchar2hexchar+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define void @uchar2hexchar(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %8, %2
br label %29
12: ; preds = %8
store i32 0, i32* %5
br label %13
13: ; preds = %26, %12
%14 = load i32, i32* %5
%15 = icmp ult i32 %14, 32
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %22)
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8* %25, i8** %4
br label %26
26: ; preds = %16
%27 = load i32, i32* %5
%28 = add i32 %27, 1
store i32 %28, i32* %5
br label %13
29: ; preds = %11, %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @uchar2hexchar(i8* %0, i8* writeonly %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %15
6: ; preds = %2, %6
%7 = phi i64 [ %13, %6 ], [ 0, %2 ]
%8 = phi i8* [ %12, %6 ], [ %1, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
%12 = getelementptr inbounds i8, i8* %8, i64 2
%13 = add nuw nsw i64 %7, 1
%14 = icmp eq i64 %13, 32
br i1 %14, label %15, label %6
15: ; preds = %6, %2
ret void
}