#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*/ fputc(char, int /*<<< orphan*/ *);
void fhexdump(const char *buffer, size_t length, FILE *out) {
  const char *point;
  int i, ch;
  for (point = buffer - ((intptr_t)buffer & 0xf); point < buffer + length;
       point += 16) {
    fprintf(out, "%04tx:", point - buffer);
    for (i = 0; i < 16; i++) {
      if (i % 8 == 0) {
        fputc(' ', out);
      }
      if (buffer <= point + i && point + i < buffer + length) {
        fprintf(out, "%02x ", (unsigned char)*(point + i));
      } else {
        fprintf(out, "   ");
      }
    }
    fputc('>', out);
    for (i = 0; i < 16; i++) {
      if (buffer <= point + i && point + i < buffer + length) {
        ch = (unsigned char)*(point + i);
        if (ch < 32 || ch > 126) {
          fputc('.', out);
        } else {
          fputc(ch, out);
        }
      } else {
        fputc(' ', out);
      }
    }
    fprintf(out, "<\n");
  }
}


x86 assembly (clang, -O0):
<fhexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rdx
and    $0xf,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    130e <fhexdump+0x1ee>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
sub    %rax,%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    122d <fhexdump+0x10d>
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b1 <fhexdump+0x91>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <fputc@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
ja     1208 <fhexdump+0xe8>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    1208 <fhexdump+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    121a <fhexdump+0xfa>
mov    -0x18(%rbp),%rdi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    121f <fhexdump+0xff>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1185 <fhexdump+0x65>
mov    -0x18(%rbp),%rsi
mov    $0x3e,%edi
call   1030 <fputc@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    12eb <fhexdump+0x1cb>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
ja     12ca <fhexdump+0x1aa>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    12ca <fhexdump+0x1aa>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x20,-0x28(%rbp)
jl     12a3 <fhexdump+0x183>
cmpl   $0x7e,-0x28(%rbp)
jle    12b6 <fhexdump+0x196>
mov    -0x18(%rbp),%rsi
mov    $0x2e,%edi
call   1030 <fputc@plt>
jmp    12c5 <fhexdump+0x1a5>
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    12d8 <fhexdump+0x1b8>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1030 <fputc@plt>
jmp    12dd <fhexdump+0x1bd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1242 <fhexdump+0x122>
mov    -0x18(%rbp),%rdi
lea    0xd1b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    114c <fhexdump+0x2c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fhexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    %r12d,%r15d
and    $0xf,%r15d
neg    %r15
cmp    %rsi,%r15
jge    127c <fhexdump+0x14c>
mov    %rdx,%rbx
mov    %rsi,%r14
add    %r12,%r14
add    %r12,%r15
lea    0xea3(%rip),%rbp
jmp    1199 <fhexdump+0x69>
cs nopw 0x0(%rax,%rax,1)
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe90(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0x10,%r15
cmp    %r14,%r15
mov    %r13,%rbp
jae    127c <fhexdump+0x14c>
mov    %r15,%rdx
sub    %r12,%rdx
mov    %rbx,%rdi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %r13d,%r13d
jmp    11e3 <fhexdump+0xb3>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe3c(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0x1,%r13
cmp    $0x10,%r13
je     1220 <fhexdump+0xf0>
test   $0x7,%r13b
jne    11f6 <fhexdump+0xc6>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
lea    (%r15,%r13,1),%rax
cmp    %r12,%rax
jb     11c0 <fhexdump+0x90>
cmp    %r14,%rax
jae    11c0 <fhexdump+0x90>
movzbl (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d9 <fhexdump+0xa9>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%r13
mov    $0x3e,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
xor    %ebp,%ebp
jmp    1259 <fhexdump+0x129>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1170 <fhexdump+0x40>
lea    (%r15,%rbp,1),%rcx
mov    $0x20,%al
cmp    %r12,%rcx
jb     1240 <fhexdump+0x110>
cmp    %r14,%rcx
jae    1240 <fhexdump+0x110>
movzbl (%rcx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
jmp    1240 <fhexdump+0x110>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%04tx:\00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [3 x i8] c"<\0A\00"
define void @fhexdump(i8* %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%10 = load i8*, i8** %4
%11 = load i8*, i8** %4
%12 = ptrtoint i8* %11 to i64
%13 = and i64 %12, 15
%14 = sub i64 0, %13
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8* %15, i8** %7
br label %16
16: ; preds = %125, %3
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = icmp ult i8* %17, %20
br i1 %21, label %22, label %128
22: ; preds = %16
%23 = load i32*, i32** %6
%24 = load i8*, i8** %7
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %28)
store i32 0, i32* %8
br label %30
30: ; preds = %69, %22
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 16
br i1 %32, label %33, label %72
33: ; preds = %30
%34 = load i32, i32* %8
%35 = srem i32 %34, 8
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32*, i32** %6
%39 = call i32 @fputc(i8 signext 32, i32* %38)
br label %40
40: ; preds = %37, %33
%41 = load i8*, i8** %4
%42 = load i8*, i8** %7
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = icmp ule i8* %41, %45
br i1 %46, label %47, label %65
47: ; preds = %40
%48 = load i8*, i8** %7
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8*, i8** %4
%53 = load i64, i64* %5
%54 = getelementptr inbounds i8, i8* %52, i64 %53
%55 = icmp ult i8* %51, %54
br i1 %55, label %56, label %65
56: ; preds = %47
%57 = load i32*, i32** %6
%58 = load i8*, i8** %7
%59 = load i32, i32* %8
%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
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %63)
br label %68
65: ; preds = %47, %40
%66 = load i32*, i32** %6
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %65, %56
br label %69
69: ; preds = %68
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %30
72: ; preds = %30
%73 = load i32*, i32** %6
%74 = call i32 @fputc(i8 signext 62, i32* %73)
store i32 0, i32* %8
br label %75
75: ; preds = %119, %72
%76 = load i32, i32* %8
%77 = icmp slt i32 %76, 16
br i1 %77, label %78, label %122
78: ; preds = %75
%79 = load i8*, i8** %4
%80 = load i8*, i8** %7
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = icmp ule i8* %79, %83
br i1 %84, label %85, label %115
85: ; preds = %78
%86 = load i8*, i8** %7
%87 = load i32, i32* %8
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i8*, i8** %4
%91 = load i64, i64* %5
%92 = getelementptr inbounds i8, i8* %90, i64 %91
%93 = icmp ult i8* %89, %92
br i1 %93, label %94, label %115
94: ; preds = %85
%95 = load i8*, i8** %7
%96 = load i32, i32* %8
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = load i8, i8* %98
%100 = zext i8 %99 to i32
store i32 %100, i32* %9
%101 = load i32, i32* %9
%102 = icmp slt i32 %101, 32
br i1 %102, label %106, label %103
103: ; preds = %94
%104 = load i32, i32* %9
%105 = icmp sgt i32 %104, 126
br i1 %105, label %106, label %109
106: ; preds = %103, %94
%107 = load i32*, i32** %6
%108 = call i32 @fputc(i8 signext 46, i32* %107)
br label %114
109: ; preds = %103
%110 = load i32, i32* %9
%111 = trunc i32 %110 to i8
%112 = load i32*, i32** %6
%113 = call i32 @fputc(i8 signext %111, i32* %112)
br label %114
114: ; preds = %109, %106
br label %118
115: ; preds = %85, %78
%116 = load i32*, i32** %6
%117 = call i32 @fputc(i8 signext 32, i32* %116)
br label %118
118: ; preds = %115, %114
br label %119
119: ; preds = %118
%120 = load i32, i32* %8
%121 = add nsw i32 %120, 1
store i32 %121, i32* %8
br label %75
122: ; preds = %75
%123 = load i32*, i32** %6
%124 = call i32 (i32*, i8*, ...) @fprintf(i32* %123, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %125
125: ; preds = %122
%126 = load i8*, i8** %7
%127 = getelementptr inbounds i8, i8* %126, i64 16
store i8* %127, i8** %7
br label %16
128: ; preds = %16
ret void
}

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