#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 *, ...);
void display_buffer_hex(unsigned char *buffer, unsigned size) {
  unsigned i, j, k;
  for (i = 0; i < size; i += 16) {
    printf("\n  %08x  ", i);
    for (j = 0, k = 0; k < 16; j++, k++) {
      if (i + j < size) {
        printf("%02x", buffer[i + j]);
      } else {
        printf("  ");
      }
      printf(" ");
    }
    printf(" ");
    for (j = 0, k = 0; k < 16; j++, k++) {
      if (i + j < size) {
        if ((buffer[i + j] < 32) || (buffer[i + j] > 126)) {
          printf(".");
        } else {
          printf("%c", buffer[i + j]);
        }
      }
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<display_buffer_hex>:
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
jae    128c <display_buffer_hex+0x17c>
mov    -0x10(%rbp),%esi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jae    11c0 <display_buffer_hex+0xb0>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    118d <display_buffer_hex+0x7d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119b <display_buffer_hex+0x8b>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1151 <display_buffer_hex+0x41>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jae    1279 <display_buffer_hex+0x169>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    125d <display_buffer_hex+0x14d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1227 <display_buffer_hex+0x117>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    123a <display_buffer_hex+0x12a>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1258 <display_buffer_hex+0x148>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125d <display_buffer_hex+0x14d>
jmp    1262 <display_buffer_hex+0x152>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11dc <display_buffer_hex+0xcc>
jmp    127e <display_buffer_hex+0x16e>
mov    -0x10(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <display_buffer_hex+0x16>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_buffer_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
mov    %esi,0xc(%rsp)
test   %esi,%esi
je     1224 <display_buffer_hex+0x104>
mov    0xc(%rsp),%ebx
lea    0xec0(%rip),%rbp
lea    0xeb6(%rip),%r15
xor    %esi,%esi
jmp    1171 <display_buffer_hex+0x51>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x10(%r14),%esi
cmp    0xc(%rsp),%esi
mov    %r13,%rbp
jae    1224 <display_buffer_hex+0x104>
mov    %esi,%r14d
mov    0x10(%rsp),%rax
lea    (%rax,%r14,1),%r12
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r13d,%r13d
jmp    11ae <display_buffer_hex+0x8e>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x1,%r13
cmp    $0x10,%r13
je     11d0 <display_buffer_hex+0xb0>
lea    (%r14,%r13,1),%rax
cmp    %rbx,%rax
jae    1190 <display_buffer_hex+0x70>
movzbl (%r12,%r13,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119a <display_buffer_hex+0x7a>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r13
mov    $0x20,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    11fe <display_buffer_hex+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1160 <display_buffer_hex+0x40>
lea    (%r14,%rbp,1),%rax
cmp    %rbx,%rax
jae    11f0 <display_buffer_hex+0xd0>
movzbl (%r12,%rbp,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
mov    $0x2e,%ecx
cmovb  %ecx,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
jmp    11f0 <display_buffer_hex+0xd0>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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