#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *stdout;
void hexdump(char *buffer, int len) {
  int i;
  FILE *fp = stdout;
  for (i = 0; i < len; i++) {
    if (i != 0) {
      if (i % 4 == 0) {
        fprintf(fp, "\n");
      } else {
        fprintf(fp, " ");
      }
    }
    fprintf(fp, "0x%02x", buffer[i] & 0xff);
  }
  if (i != 0)
    fprintf(fp, "\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2eba(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11be <hexdump+0xae>
cmpl   $0x0,-0x10(%rbp)
je     118c <hexdump+0x7c>
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1175 <hexdump+0x65>
mov    -0x18(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1187 <hexdump+0x77>
mov    -0x18(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    118c <hexdump+0x7c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <hexdump+0x24>
cmpl   $0x0,-0x10(%rbp)
je     11da <hexdump+0xca>
mov    -0x18(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
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
test   %esi,%esi
jle    11d2 <hexdump+0xb2>
mov    %esi,%ebp
mov    %rdi,%r12
mov    0x2ea1(%rip),%rax
mov    (%rax),%rbx
movzbl (%rdi),%edx
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x1,%ebp
je     11b7 <hexdump+0x97>
mov    %ebp,0x4(%rsp)
mov    %ebp,%r13d
mov    $0x1,%ebp
mov    $0xa,%r14d
lea    0xe8c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   $0x3,%bpl
mov    $0x20,%edi
cmove  %r14d,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
movzbl (%r12,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1180 <hexdump+0x60>
cmpl   $0x0,0x4(%rsp)
jle    11d2 <hexdump+0xb2>
mov    $0xa,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32* null
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [7 x i8] c"0x%02x\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
%7 = load i32*, i32** @stdout
store i32* %7, i32** %6
store i32 0, i32* %5
br label %8
8: ; preds = %36, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %39
12: ; preds = %8
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i32, i32* %5
%17 = srem i32 %16, 4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %25
22: ; preds = %15
%23 = load i32*, i32** %6
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %25, %12
%27 = load i32*, i32** %6
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = and i32 %33, 255
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %26
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %8
39: ; preds = %8
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32*, i32** %6
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %45
45: ; preds = %42, %39
ret void
}

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