#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*/ fill_hex(char *, unsigned char);
void fill_hex_val(char *out, void *ptr, unsigned size) {
  unsigned char *value = ptr;
  unsigned int i;
  for (i = 0; i < size; i++) {
    fill_hex(&out[i * 2], value[i]);
  }
}


x86 assembly (clang, -O0):
<fill_hex_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    116b <fill_hex_val+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
call   1030 <fill_hex@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <fill_hex_val+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_hex_val>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     114f <fill_hex_val+0x3f>
mov    %rsi,%r12
mov    %rdi,%r14
mov    %edx,%r15d
add    %r15,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
and    $0xfffffffe,%edi
add    %r14,%rdi
movzbl (%r12),%esi
call   1030 <fill_hex@plt>
add    $0x2,%rbx
add    $0x1,%r12
cmp    %rbx,%r15
jne    1130 <fill_hex_val+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @fill_hex_val(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
store i32 0, i32* %8
br label %10
10: ; preds = %26, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %8
%17 = mul i32 %16, 2
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @fill_hex(i8* %19, i8 zeroext %24)
br label %26
26: ; preds = %14
%27 = load i32, i32* %8
%28 = add i32 %27, 1
store i32 %28, i32* %8
br label %10
29: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @fill_hex_val(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %15, %7 ]
%9 = shl nuw i64 %8, 1
%10 = and i64 %9, 4294967294
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds i8, i8* %1, i64 %8
%13 = load i8, i8* %12
%14 = tail call i32 @fill_hex(i8* %11, i8 zeroext %13)
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %7
17: ; preds = %7, %3
ret void
}