#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 hexdump(char *addr, unsigned int length) {
  unsigned int i, j;
  for (i = 0; i < length / 16; i++) {
    for (j = 0; j < 16; j++) {
      printf("%02hhx ", addr[i * 16 + j]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x4,%ecx
cmp    %ecx,%eax
jae    1193 <hexdump+0x83>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jae    1177 <hexdump+0x67>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x4,%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <hexdump+0x2e>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <hexdump+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x10,%esi
jb     1266 <hexdump+0x146>
mov    %esi,%r14d
mov    %rdi,%r12
and    $0xfffffff0,%r14d
lea    0xebe(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x1(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x2(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x3(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x4(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x5(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x6(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x7(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x8(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x9(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xa(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xb(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xc(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xd(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xe(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xf(%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rbx
cmp    %rbx,%r14
jne    1150 <hexdump+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%02hhx \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @hexdump(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
store i32 0, i32* %5
br label %7
7: ; preds = %32, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = udiv i32 %9, 16
%11 = icmp ult i32 %8, %10
br i1 %11, label %12, label %35
12: ; preds = %7
store i32 0, i32* %6
br label %13
13: ; preds = %27, %12
%14 = load i32, i32* %6
%15 = icmp ult i32 %14, 16
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = mul i32 %18, 16
%20 = load i32, i32* %6
%21 = add i32 %19, %20
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %17, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %16
%28 = load i32, i32* %6
%29 = add i32 %28, 1
store i32 %29, i32* %6
br label %13
30: ; preds = %13
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30
%33 = load i32, i32* %5
%34 = add i32 %33, 1
store i32 %34, i32* %5
br label %7
35: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%02hhx \00"
define void @hexdump(i8* nocapture %0, i32 %1) {
%3 = icmp ult i32 %1, 16
br i1 %3, label %92, label %4
4: ; preds = %2
%5 = lshr i32 %1, 4
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %4, %7
%8 = phi i64 [ 0, %4 ], [ %90, %7 ]
%9 = shl i64 %8, 4
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = or i64 %9, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = or i64 %9, 2
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = or i64 %9, 3
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = or i64 %9, 4
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = or i64 %9, 5
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = or i64 %9, 6
%40 = getelementptr inbounds i8, i8* %0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = or i64 %9, 7
%45 = getelementptr inbounds i8, i8* %0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = or i64 %9, 8
%50 = getelementptr inbounds i8, i8* %0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %52)
%54 = or i64 %9, 9
%55 = getelementptr inbounds i8, i8* %0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = or i64 %9, 10
%60 = getelementptr inbounds i8, i8* %0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %62)
%64 = or i64 %9, 11
%65 = getelementptr inbounds i8, i8* %0, i64 %64
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = or i64 %9, 12
%70 = getelementptr inbounds i8, i8* %0, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %72)
%74 = or i64 %9, 13
%75 = getelementptr inbounds i8, i8* %0, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %77)
%79 = or i64 %9, 14
%80 = getelementptr inbounds i8, i8* %0, i64 %79
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %82)
%84 = or i64 %9, 15
%85 = getelementptr inbounds i8, i8* %0, i64 %84
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %87)
%89 = tail call i32 @putchar(i32 10)
%90 = add nuw nsw i64 %8, 1
%91 = icmp eq i64 %90, %6
br i1 %91, label %92, label %7
92: ; preds = %7, %2
ret void
}