#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 *, ...);
int hexdump(char *buf, int len) {
  int i, j;
  for (i = 0; i < len; i++) {
    for (j = 0; j < 16; j++) {
      if (i + j >= len)
        printf("%3s", "");
      else
        printf("%02x ", (unsigned char)buf[i + j]);
    }
    printf("%3s", "");
    for (j = 0; j < 16; j++) {
      if (i + j >= len)
        printf("%1s", "");
      else if (buf[i + j] > '\x1f' && buf[i + j] < '\x7f')
        printf("%c", buf[i + j]);
      else
        printf(".");
    }
    i += 15;
    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,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1290 <hexdump+0x180>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    119e <hexdump+0x8e>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     116c <hexdump+0x5c>
lea    0xea7(%rip),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118b <hexdump+0x7b>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1190 <hexdump+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <hexdump+0x29>
lea    0xe5b(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    126b <hexdump+0x15b>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11ed <hexdump+0xdd>
lea    0xe30(%rip),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1258 <hexdump+0x148>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1f,%eax
jle    1245 <hexdump+0x135>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jge    1245 <hexdump+0x135>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1253 <hexdump+0x143>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1258 <hexdump+0x148>
jmp    125d <hexdump+0x14d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <hexdump+0xaa>
mov    -0x10(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x10(%rbp)
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <hexdump+0x16>
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,0x4(%rsp)
test   %esi,%esi
jle    1237 <hexdump+0x117>
mov    %rdi,%r12
mov    0x4(%rsp),%r14d
lea    0xebe(%rip),%rbx
lea    0xeb3(%rip),%r13
xor    %r15d,%r15d
jmp    1180 <hexdump+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%r15
add    $0x10,%r12
cmp    0x4(%rsp),%r15d
mov    %rbp,%r13
jge    1237 <hexdump+0x117>
xor    %ebp,%ebp
jmp    11a9 <hexdump+0x89>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r12,%rbp,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     11d0 <hexdump+0xb0>
lea    (%r15,%rbp,1),%rax
cmp    %r14,%rax
jl     1190 <hexdump+0x70>
mov    %r13,%rdi
lea    0xe4d(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119f <hexdump+0x7f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rbp
mov    %r13,%rdi
lea    0xe2c(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r13d,%r13d
jmp    1213 <hexdump+0xf3>
nopl   0x0(%rax)
lea    0xe13(%rip),%rdi
lea    0xe0b(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
cmp    $0x10,%r13
je     1160 <hexdump+0x40>
lea    (%r15,%r13,1),%rax
cmp    %r14,%rax
jge    11f0 <hexdump+0xd0>
movzbl (%r12,%r13,1),%edi
lea    -0x7f(%rdi),%eax
cmp    $0xa1,%al
jae    1230 <hexdump+0x110>
mov    $0x2e,%edi
jmp    1230 <hexdump+0x110>
nop
call   1030 <putchar@plt>
jmp    1205 <hexdump+0xe5>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%3s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [6 x i8] c"%02x \00"
@.str.3 = [4 x i8] c"%1s\00"
define i32 @hexdump(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %48
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %43
%7 = phi i64 [ 0, %4 ], [ %45, %43 ]
br label %8
8: ; preds = %6, %19
%9 = phi i64 [ 0, %6 ], [ %20, %19 ]
%10 = add nuw nsw i64 %9, %7
%11 = icmp slt i64 %10, %5
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %19
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %0, i64 %10
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %12, %14
%20 = add nuw nsw i64 %9, 1
%21 = icmp eq i64 %20, 16
br i1 %21, label %22, label %8
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %40
%25 = phi i64 [ 0, %22 ], [ %41, %40 ]
%26 = add nuw nsw i64 %25, %7
%27 = icmp slt i64 %26, %5
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %40
30: ; preds = %24
%31 = getelementptr inbounds i8, i8* %0, i64 %26
%32 = load i8, i8* %31
%33 = add i8 %32, -127
%34 = icmp ult i8 %33, -95
br i1 %34, label %38, label %35
35: ; preds = %30
%36 = zext i8 %32 to i32
%37 = tail call i32 @putchar(i32 %36)
br label %40
38: ; preds = %30
%39 = tail call i32 @putchar(i32 46)
br label %40
40: ; preds = %28, %38, %35
%41 = add nuw nsw i64 %25, 1
%42 = icmp eq i64 %41, 16
br i1 %42, label %43, label %24
43: ; preds = %40
%44 = tail call i32 @putchar(i32 10)
%45 = add nuw i64 %7, 16
%46 = trunc i64 %45 to i32
%47 = icmp slt i32 %46, %1
br i1 %47, label %6, label %48
48: ; preds = %43, %2
ret i32 0
}