#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 *, unsigned char, unsigned char);
void hexdump(unsigned char *elem, size_t sz) {
  for (unsigned i = 0; i < sz; i += 2) {
    printf("%02x%02x ", elem[i], elem[i + 1]);
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    116b <hexdump+0x5b>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
lea    0xeaf(%rip),%rdi
movzbl %dl,%esi
movzbl (%rax,%rcx,1),%edx
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <hexdump+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1151 <hexdump+0x41>
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0xed4(%rip),%r15
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%esi
mov    %rbx,%rax
or     $0x1,%rax
movzbl (%r12,%rax,1),%edx
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x2,%ebx
cmp    %r14,%rbx
jb     1130 <hexdump+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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