#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;

/* Variables and functions */
scalar_t__ isprint(int);
int /*<<< orphan*/ isspace(int);
int /*<<< orphan*/ printf(char *, ...);
void dumphex(void *base, uint8_t *lim) {
  uint8_t *ptr = base;
  int x = 0;
  if (ptr < lim) {
    x = 0;
    while (ptr < lim) {
      if (x == 16) {
        printf("\n");
        x = 0;
      }
      if (x > 0) {
        printf("  ");
      }
      if (isprint(*ptr) && !isspace(*ptr)) {
        printf(" %c", *ptr);
      } else {
        printf("%02x", *ptr);
      }
      x++;
      ptr++;
    }
    printf("\n");
  }
  return;
}


x86 assembly (clang, -O0):
<dumphex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1227 <dumphex+0xf7>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1219 <dumphex+0xe9>
cmpl   $0x10,-0x1c(%rbp)
jne    1191 <dumphex+0x61>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11a9 <dumphex+0x79>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11eb <dumphex+0xbb>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11eb <dumphex+0xbb>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ff <dumphex+0xcf>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1164 <dumphex+0x34>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumphex>:
cmp    %rsi,%rdi
jae    11d1 <dumphex+0x91>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea6(%rip),%r12
lea    0xe9b(%rip),%r13
xor    %r15d,%r15d
jmp    1189 <dumphex+0x49>
nopl   (%rax)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
add    $0x4,%rbx
cmp    %r14,%rbx
jae    11d2 <dumphex+0x92>
cmp    $0x10,%r15d
jne    11a0 <dumphex+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r15d,%r15d
jmp    11b3 <dumphex+0x73>
xchg   %ax,%ax
test   %r15d,%r15d
jle    11b3 <dumphex+0x73>
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1060 <isprint@plt>
mov    (%rbx),%ebp
test   %rax,%rax
je     1170 <dumphex+0x30>
mov    %ebp,%edi
call   1050 <isspace@plt>
mov    %r13,%rdi
test   %eax,%eax
jne    1170 <dumphex+0x30>
jmp    1173 <dumphex+0x33>
ret
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c" \00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [5 x i8] c"%02x\00"
define void @dumphex(i8* %0, i32* readnone %1) {
%3 = bitcast i8* %0 to i32*
%4 = icmp ult i32* %3, %1
br i1 %4, label %5, label %33
5: ; preds = %2, %25
%6 = phi i32 [ %28, %25 ], [ 0, %2 ]
%7 = phi i32* [ %29, %25 ], [ %3, %2 ]
%8 = icmp eq i32 %6, 16
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @putchar(i32 10)
br label %15
11: ; preds = %5
%12 = icmp sgt i32 %6, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %9, %13, %11
%16 = phi i32 [ 0, %9 ], [ %6, %13 ], [ %6, %11 ]
%17 = load i32, i32* %7
%18 = tail call i64 @isprint(i32 %17)
%19 = icmp eq i64 %18, 0
%20 = load i32, i32* %7
br i1 %19, label %24, label %21
21: ; preds = %15
%22 = tail call i32 @isspace(i32 %20)
%23 = icmp eq i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %15, %21
br label %25
25: ; preds = %21, %24
%26 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %24 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %21 ]
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %26, i32 %20)
%28 = add nsw i32 %16, 1
%29 = getelementptr inbounds i32, i32* %7, i64 1
%30 = icmp ult i32* %29, %1
br i1 %30, label %5, label %31
31: ; preds = %25
%32 = tail call i32 @putchar(i32 10)
br label %33
33: ; preds = %31, %2
ret void
}