#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 hexdump(const char *buf, int length) {
  int i;
  printf("rmff: ascii>");
  for (i = 0; i < length; i++) {
    unsigned char c = buf[i];
    if ((c >= 32) && (c <= 128))
      printf("%c", c);
    else
      printf(".");
  }
  printf("\n");
  printf("rmff: hexdump> ");
  for (i = 0; i < length; i++) {
    unsigned char c = buf[i];
    printf("%02x", c);
    if ((i % 16) == 15)
      printf("\nrmff:         ");
    if ((i % 2) == 1)
      printf(" ");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <hexdump+0x92>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jl     1181 <hexdump+0x71>
movzbl -0x11(%rbp),%eax
cmp    $0x80,%eax
jg     1181 <hexdump+0x71>
movzbl -0x11(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118f <hexdump+0x7f>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1194 <hexdump+0x84>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <hexdump+0x24>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1248 <hexdump+0x138>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
movzbl -0x12(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    1213 <hexdump+0x103>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1235 <hexdump+0x125>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123a <hexdump+0x12a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c5 <hexdump+0xb5>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
jle    11db <hexdump+0xbb>
mov    %r14d,%ebp
xor    %ebx,%ebx
mov    $0x2e,%r15d
movzbl (%r12,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x61,%cl
cmovae %r15d,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <hexdump+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
jle    11f3 <hexdump+0xd3>
lea    0xe89(%rip),%r15
lea    0xe87(%rip),%r14
xor    %ebx,%ebx
jmp    11a9 <hexdump+0x89>
nop
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11f3 <hexdump+0xd3>
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0xf,%al
jne    11ca <hexdump+0xaa>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x1,%bl
je     11a0 <hexdump+0x80>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11a0 <hexdump+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"rmff: ascii>\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [16 x i8] c"rmff: hexdump> \00"
@.str.5 = [5 x i8] c"%02x\00"
@.str.6 = [16 x i8] c"\0Armff: \00"
@.str.7 = [2 x i8] c" \00"
define void @hexdump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %33, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
store i8 %18, i8* %6
%19 = load i8, i8* %6
%20 = zext i8 %19 to i32
%21 = icmp sge i32 %20, 32
br i1 %21, label %22, label %30
22: ; preds = %13
%23 = load i8, i8* %6
%24 = zext i8 %23 to i32
%25 = icmp sle i32 %24, 128
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i8, i8* %6
%28 = zext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %32
30: ; preds = %22, %13
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %9
36: ; preds = %9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %39
39: ; preds = %64, %36
%40 = load i32, i32* %5
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %67
43: ; preds = %39
%44 = load i8*, i8** %3
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
store i8 %48, i8* %7
%49 = load i8, i8* %7
%50 = zext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %5
%53 = srem i32 %52, 16
%54 = icmp eq i32 %53, 15
br i1 %54, label %55, label %57
55: ; preds = %43
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %55, %43
%58 = load i32, i32* %5
%59 = srem i32 %58, 2
%60 = icmp eq i32 %59, 1
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %61, %57
br label %64
64: ; preds = %63
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %39
67: ; preds = %39
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

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