#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
void hex(void *vcp, int len) {
  uint8_t *cp = vcp;
  int i;
  for (i = 0; i < len; ++i) {
    printf("%02x%c", *cp++, ((i & 15) == 15) ? 10 : 32);
  }
  if (i & 15)
    puts("");
}


x86 assembly (clang, -O0):
<hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118b <hex+0x6b>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%esi
mov    -0x1c(%rbp),%ecx
and    $0xf,%ecx
mov    $0x20,%edx
mov    $0xa,%eax
cmp    $0xf,%ecx
cmove  %eax,%edx
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <hex+0x1e>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     11a6 <hex+0x86>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex>:
test   %esi,%esi
jle    1192 <hex+0x72>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r12
mov    %esi,%ebp
xor    %ebx,%ebx
mov    $0xa,%r13d
lea    0xeba(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%esi
mov    %ebx,%eax
not    %eax
test   $0xf,%al
mov    $0x20,%edx
cmove  %r13d,%edx
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1150 <hex+0x30>
test   $0xf,%r14b
lea    0x8(%rsp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
je     1192 <hex+0x72>
mov    $0xa,%edi
jmp    1030 <putchar@plt>
ret

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

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