#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*/ g_printf(char *, ...);
int /*<<< orphan*/ g_writeln(char *);
void g_hexdump(char *p, int len) {
  unsigned char *line;
  int i;
  int thisline;
  int offset;
  line = (unsigned char *)p;
  offset = 0;
  while (offset < len) {
    g_printf("%04x ", offset);
    thisline = len - offset;
    if (thisline > 16) {
      thisline = 16;
    }
    for (i = 0; i < thisline; i++) {
      g_printf("%02x ", line[i]);
    }
    for (; i < 16; i++) {
      g_printf("   ");
    }
    for (i = 0; i < thisline; i++) {
      g_printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
    }
    g_writeln("");
    offset += thisline;
    line += thisline;
  }
}


x86 assembly (clang, -O0):
<g_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1283 <g_hexdump+0x163>
mov    -0x24(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <g_printf@plt>
mov    -0xc(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jle    1175 <g_hexdump+0x55>
movl   $0x10,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b0 <g_hexdump+0x90>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <g_printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117c <g_hexdump+0x5c>
jmp    11b5 <g_hexdump+0x95>
cmpl   $0x10,-0x1c(%rbp)
jge    11db <g_hexdump+0xbb>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <g_printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <g_hexdump+0x95>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1258 <g_hexdump+0x138>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     122c <g_hexdump+0x10c>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jge    122c <g_hexdump+0x10c>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
jmp    1239 <g_hexdump+0x119>
mov    $0x2e,%eax
mov    %eax,-0x28(%rbp)
jmp    1239 <g_hexdump+0x119>
mov    -0x28(%rbp),%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <g_printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e2 <g_hexdump+0xc2>
lea    0xdb0(%rip),%rdi
call   1030 <g_writeln@plt>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    113e <g_hexdump+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    127b <g_hexdump+0x15b>
mov    %esi,%r14d
mov    %rdi,%r13
lea    0xec3(%rip),%rbp
lea    0xec2(%rip),%r15
xor    %ebx,%ebx
mov    %esi,0x10(%rsp)
jmp    1190 <g_hexdump+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xea8(%rip),%rdi
call   1030 <g_writeln@plt>
mov    0x14(%rsp),%ebx
mov    0xc(%rsp),%eax
add    %eax,%ebx
cltq
add    %rax,%r13
mov    0x10(%rsp),%r14d
cmp    %r14d,%ebx
lea    0xe7c(%rip),%rbp
jge    127b <g_hexdump+0x15b>
lea    0xe69(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <g_printf@plt>
mov    %ebx,0x14(%rsp)
sub    %ebx,%r14d
cmp    $0x10,%r14d
mov    $0x10,%eax
cmovl  %r14d,%eax
mov    %eax,0xc(%rsp)
mov    $0x0,%r12d
test   %r14d,%r14d
jle    11ff <g_hexdump+0xdf>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%r12d
cmovge %eax,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <g_printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11e0 <g_hexdump+0xc0>
cmp    $0xf,%r12d
ja     121f <g_hexdump+0xff>
add    $0xfffffff0,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <g_printf@plt>
inc    %r12d
jne    1210 <g_hexdump+0xf0>
test   %r14d,%r14d
mov    $0x2e,%r14d
lea    0xde1(%rip),%r12
jle    1160 <g_hexdump+0x40>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
cmovae %r14d,%eax
movzbl %al,%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <g_printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1250 <g_hexdump+0x130>
jmp    1160 <g_hexdump+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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