#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int hexdump(uint8_t *buf, int buflen) {
  int i;
  int pos;
  pos = 0;
  printf("\n");
  for (i = 0; i < buflen; i++) {
    printf("%02x ", buf[i]);
    pos++;
    if (pos == 16) {
      printf("\n");
      pos = 0;
    }
    if (pos == 8) {
      printf("  ");
    }
  }
  printf("\n");
  return (0);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b3 <hexdump+0xa3>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jne    1188 <hexdump+0x78>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jne    11a0 <hexdump+0x90>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a5 <hexdump+0x95>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113b <hexdump+0x2b>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r12
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
jle    11a5 <hexdump+0x85>
mov    %ebp,%r13d
lea    0xeb8(%rip),%r14
lea    0xeb7(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1178 <hexdump+0x58>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x8,%ebp
add    $0x1,%rbx
cmp    %rbx,%r13
je     11a5 <hexdump+0x85>
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x7,%ebp
je     1160 <hexdump+0x40>
cmp    $0xf,%ebp
jne    11a0 <hexdump+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    116f <hexdump+0x4f>
xchg   %ax,%ax
add    $0x1,%ebp
jmp    116f <hexdump+0x4f>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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