#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*/ printf(char *, ...);
void printhex(char *start, void *dst, int len, char *end) {
  unsigned char *p = NULL;
  int i;
  if (start != NULL)
    printf("%s", start);
  for (p = (unsigned char *)dst, i = 0; i < len; i++, p++) {
    if (*p >= 0x10)
      printf("0x%2x ", *p);
    else
      printf("0x0%1x ", *p);
  }
  if (end != NULL)
    printf("%s", end);
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114c <printhex+0x3c>
mov    -0x8(%rbp),%rsi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c5 <printhex+0xb5>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x10,%eax
jl     1191 <printhex+0x81>
mov    -0x28(%rbp),%rax
movzbl (%rax),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a6 <printhex+0x96>
mov    -0x28(%rbp),%rax
movzbl (%rax),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ab <printhex+0x9b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115b <printhex+0x4b>
cmpq   $0x0,-0x20(%rbp)
je     11e2 <printhex+0xd2>
mov    -0x20(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r13
test   %rdi,%rdi
je     1139 <printhex+0x29>
mov    %rdi,%rsi
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
jle    116f <printhex+0x5f>
mov    %ebp,%ebp
lea    0xebd(%rip),%r15
lea    0xebd(%rip),%r12
xor    %ebx,%ebx
nop
movzbl 0x0(%r13,%rbx,1),%esi
cmp    $0x10,%esi
mov    %r12,%rdi
cmovae %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1150 <printhex+0x40>
test   %r14,%r14
je     1193 <printhex+0x83>
lea    0xe85(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"0x%2x \00"
@.str.2 = [8 x i8] c"0x0%1x \00"
define void @printhex(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i8* null, i8** %9
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %4
%17 = load i8*, i8** %6
store i8* %17, i8** %9
store i32 0, i32* %10
br label %18
18: ; preds = %38, %16
%19 = load i32, i32* %10
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = load i8*, i8** %9
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp sge i32 %25, 16
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %9
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %37
32: ; preds = %22
%33 = load i8*, i8** %9
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %32, %27
br label %38
38: ; preds = %37
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %9
br label %18
43: ; preds = %18
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i8*, i8** %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %43
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"0x%2x \00"
@.str.2 = [8 x i8] c"0x0%1x \00"
define void @printhex(i8* %0, i8* nocapture %1, i32 %2, i8* %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %4
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %21
10: ; preds = %8, %10
%11 = phi i32 [ %18, %10 ], [ 0, %8 ]
%12 = phi i8* [ %19, %10 ], [ %1, %8 ]
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp ugt i8 %13, 15
%16 = select i1 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %16, i32 %14)
%18 = add nuw nsw i32 %11, 1
%19 = getelementptr inbounds i8, i8* %12, i64 1
%20 = icmp eq i32 %18, %2
br i1 %20, label %21, label %10
21: ; preds = %10, %8
%22 = icmp eq i8* %3, null
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %25
25: ; preds = %23, %21
ret void
}