#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 uint8_t;
typedef scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void diag_vdump_buf_with_offset(uint8_t *p, uint32_t s, uint8_t *base) {
  int i, c;
  if ((uint32_t)s > (uint32_t)p) {
    s = (uint32_t)s - (uint32_t)p;
  }
  while ((int)s > 0) {
    if (base) {
      printf("%08X: ", (int)((uint32_t)p - (uint32_t)base));
    } else {
      printf("%08X: ", (int)p);
    }
    for (i = 0; i < 16; i++) {
      if (i < (int)s) {
        printf("%02X ", p[i] & 0xFF);
      } else {
        printf("   ");
      }
      if (i == 7)
        printf(" ");
    }
    printf(" |");
    for (i = 0; i < 16; i++) {
      if (i < (int)s) {
        c = p[i] & 0xFF;
        if ((c < 0x20) || (c >= 0x7F))
          c = '.';
      } else {
        c = ' ';
      }
      printf("%c", c);
    }
    printf("|\n\r");
    s -= 16;
    p += 16;
  }
}


x86 assembly (clang, -O0):
<diag_vdump_buf_with_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmp    %rcx,%rax
jle    1144 <diag_vdump_buf_with_offset+0x34>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1149 <diag_vdump_buf_with_offset+0x39>
mov    -0x10(%rbp),%rax
cmp    $0x0,%eax
jle    12c4 <diag_vdump_buf_with_offset+0x1b4>
cmpq   $0x0,-0x18(%rbp)
je     1181 <diag_vdump_buf_with_offset+0x71>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1195 <diag_vdump_buf_with_offset+0x85>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    1212 <diag_vdump_buf_with_offset+0x102>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    %ecx,%eax
jge    11d9 <diag_vdump_buf_with_offset+0xc9>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
and    $0xff,%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e7 <diag_vdump_buf_with_offset+0xd7>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x7,-0x1c(%rbp)
jne    11ff <diag_vdump_buf_with_offset+0xef>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <diag_vdump_buf_with_offset+0xf4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <diag_vdump_buf_with_offset+0x8c>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    1299 <diag_vdump_buf_with_offset+0x189>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    %ecx,%eax
jge    1273 <diag_vdump_buf_with_offset+0x163>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x20,-0x20(%rbp)
jl     1267 <diag_vdump_buf_with_offset+0x157>
cmpl   $0x7f,-0x20(%rbp)
jl     126e <diag_vdump_buf_with_offset+0x15e>
movl   $0x2e,-0x20(%rbp)
jmp    127a <diag_vdump_buf_with_offset+0x16a>
movl   $0x20,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1227 <diag_vdump_buf_with_offset+0x117>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
sub    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x8(%rbp)
jmp    1149 <diag_vdump_buf_with_offset+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diag_vdump_buf_with_offset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x8(%rsp)
xor    %eax,%eax
cmp    %rsi,%rdi
cmovl  %rdi,%rax
sub    %rax,%rsi
test   %esi,%esi
jle    125d <diag_vdump_buf_with_offset+0x13d>
mov    %rdi,%rbx
movslq %esi,%r12
lea    0xeb3(%rip),%rbp
mov    $0x2e,%r14d
lea    0xeac(%rip),%r13
jmp    119a <diag_vdump_buf_with_offset+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rsi
add    $0xfffffffffffffff0,%rsi
add    $0x40,%rbx
add    $0xfffffffffffffff0,%r12
test   %esi,%esi
mov    %r15,%rbp
jle    125d <diag_vdump_buf_with_offset+0x13d>
mov    %rsi,0x10(%rsp)
mov    %ebx,%esi
sub    0x8(%rsp),%esi
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r15d,%r15d
jmp    11ca <diag_vdump_buf_with_offset+0xaa>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    $0x10,%r15
je     1210 <diag_vdump_buf_with_offset+0xf0>
cmp    %r12,%r15
jge    11f0 <diag_vdump_buf_with_offset+0xd0>
movzbl (%rbx,%r15,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x7,%r15
jne    11c0 <diag_vdump_buf_with_offset+0xa0>
jmp    1200 <diag_vdump_buf_with_offset+0xe0>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x7,%r15
jne    11c0 <diag_vdump_buf_with_offset+0xa0>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11c0 <diag_vdump_buf_with_offset+0xa0>
nopl   0x0(%rax)
mov    %rbp,%r15
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
jmp    1243 <diag_vdump_buf_with_offset+0x123>
cs nopw 0x0(%rax,%rax,1)
nop
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1170 <diag_vdump_buf_with_offset+0x50>
mov    $0x20,%edi
cmp    %r12,%rbp
jge    1230 <diag_vdump_buf_with_offset+0x110>
movzbl (%rbx,%rbp,4),%edi
lea    -0x7f(%rdi),%eax
cmp    $0xffffffa1,%eax
cmovb  %r14d,%edi
jmp    1230 <diag_vdump_buf_with_offset+0x110>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%08X: \00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [4 x i8] c" \00"
@.str.4 = [3 x i8] c" |\00"
@.str.6 = [4 x i8] c"|\0A\0D\00"
define void @diag_vdump_buf_with_offset(i32* %0, i64 %1, i32* %2) {
%4 = ptrtoint i32* %0 to i64
%5 = icmp slt i64 %4, %1
%6 = select i1 %5, i64 %4, i64 0
%7 = sub nsw i64 %1, %6
%8 = trunc i64 %7 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %63
10: ; preds = %3
%11 = ptrtoint i32* %2 to i64
%12 = shl i64 %7, 32
%13 = ashr exact i64 %12, 32
br label %14
14: ; preds = %10, %56
%15 = phi i64 [ %13, %10 ], [ %62, %56 ]
%16 = phi i32* [ %0, %10 ], [ %60, %56 ]
%17 = phi i64 [ %7, %10 ], [ %58, %56 ]
%18 = ptrtoint i32* %16 to i64
%19 = sub nsw i64 %18, %11
%20 = trunc i64 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %14, %36
%23 = phi i64 [ 0, %14 ], [ %37, %36 ]
%24 = icmp slt i64 %23, %15
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = getelementptr inbounds i32, i32* %16, i64 %23
%27 = load i32, i32* %26
%28 = and i32 %27, 255
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %32
30: ; preds = %22
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = icmp eq i64 %23, 7
br i1 %33, label %34, label %36
34: ; preds = %32
%35 = tail call i32 @putchar(i32 32)
br label %36
36: ; preds = %32, %34
%37 = add nuw nsw i64 %23, 1
%38 = icmp eq i64 %37, 16
br i1 %38, label %39, label %22
39: ; preds = %36
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %51
%42 = phi i64 [ 0, %39 ], [ %54, %51 ]
%43 = icmp slt i64 %42, %15
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = getelementptr inbounds i32, i32* %16, i64 %42
%46 = load i32, i32* %45
%47 = and i32 %46, 255
%48 = add nsw i32 %47, -127
%49 = icmp ult i32 %48, -95
%50 = select i1 %49, i32 46, i32 %47
br label %51
51: ; preds = %41, %44
%52 = phi i32 [ %50, %44 ], [ 32, %41 ]
%53 = tail call i32 @putchar(i32 %52)
%54 = add nuw nsw i64 %42, 1
%55 = icmp eq i64 %54, 16
br i1 %55, label %56, label %41
56: ; preds = %51
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%58 = add nsw i64 %17, -16
%59 = trunc i64 %58 to i32
%60 = getelementptr inbounds i32, i32* %16, i64 16
%61 = icmp sgt i32 %59, 0
%62 = add nsw i64 %15, -16
br i1 %61, label %14, label %63
63: ; preds = %56, %3
ret void
}