#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*/ memset(unsigned char *, char, int);
void hexdump(FILE *fl, void *buffer, int size) {
  unsigned char *c = buffer;
  unsigned char ascii[17] = {
      0,
  };
  int i;
  for (i = 0; i < size; i++) {
    if ((i % 16) == 0) {
      if (i > 0)
        fprintf(fl, " %s\n", ascii);
      memset(ascii, ' ', 16);
      fprintf(fl, "%08x  ", i);
    }
    fprintf(fl, "%02x ", c[i]);
    ascii[i % 16] = (c[i] >= 32 && c[i] <= 127) ? c[i] : '.';
  }
  while ((i++ % 16) != 0)
    fprintf(fl, "   ");
  fprintf(fl, " %s\n", ascii);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1030 <memset@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1248 <hexdump+0x128>
mov    -0x44(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ba <hexdump+0x9a>
cmpl   $0x0,-0x44(%rbp)
jle    1192 <hexdump+0x72>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1216 <hexdump+0xf6>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jg     1216 <hexdump+0xf6>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x48(%rbp)
jmp    1223 <hexdump+0x103>
mov    $0x2e,%eax
mov    %eax,-0x48(%rbp)
jmp    1223 <hexdump+0x103>
mov    -0x48(%rbp),%eax
mov    %al,%cl
mov    -0x44(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1152 <hexdump+0x32>
jmp    124d <hexdump+0x12d>
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x44(%rbp)
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1280 <hexdump+0x160>
mov    -0x8(%rbp),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    124d <hexdump+0x12d>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
test   %edx,%edx
jle    12a1 <hexdump+0x171>
mov    %edx,%ebp
mov    %rsi,%r12
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    0xe8f(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r12),%edx
lea    0xe7e(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r12),%eax
cmp    $0x20,%al
mov    $0x2e,%ecx
cmovl  %ecx,%eax
mov    %al,0x10(%rsp)
mov    $0x1,%r14d
cmp    $0x1,%ebp
je     1265 <hexdump+0x135>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r14d
mov    $0x1,%ebp
lea    0xe3f(%rip),%rbx
jmp    11ff <hexdump+0xcf>
nop
movzbl (%r12,%rbp,1),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r12,%rbp,1),%eax
cmp    $0x20,%al
mov    $0x2e,%ecx
cmovl  %ecx,%eax
mov    %al,0x10(%rsp,%r13,1)
add    $0x1,%rbp
cmp    %rbp,%r14
je     125e <hexdump+0x12e>
mov    %rbp,%r13
and    $0xf,%r13
jne    11d0 <hexdump+0xa0>
mov    %r15,%rdi
lea    0xdee(%rip),%rsi
mov    %r15,%rbx
mov    %r12,%r15
lea    0x10(%rsp),%r12
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12,%rdi
mov    %r15,%r12
mov    %rbx,%r15
lea    0xdd5(%rip),%rbx
mov    $0x20,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    %r15,%rdi
lea    0xdb5(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d0 <hexdump+0xa0>
testb  $0xf,0xc(%rsp)
je     12a1 <hexdump+0x171>
add    $0x1,%r14d
lea    0xda2(%rip),%rbx
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %r15,%rcx
call   1050 <fwrite@plt>
add    $0x1,%ebp
test   $0xf,%r14b
mov    %ebp,%r14d
jne    1280 <hexdump+0x150>
lea    0xd58(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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