#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 */
int /*<<< orphan*/ printf(char *, ...);
void dump_buf(char *strp, uint8_t *bufp, int len) {
  int i;
  printf("%s read %d bytes: ", strp, len);
  for (i = 0; i < len; i++)
    printf("0x%02x [%c]", bufp[i],
           bufp[i] >= 32 && bufp[i] < 127 ? bufp[i] : '.');
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bf <dump_buf+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x20,(%rax,%rcx,4)
jl     1190 <dump_buf+0x80>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x7f,(%rax,%rcx,4)
jge    1190 <dump_buf+0x80>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
jmp    119d <dump_buf+0x8d>
mov    $0x2e,%eax
mov    %eax,-0x20(%rbp)
jmp    119d <dump_buf+0x8d>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113f <dump_buf+0x2f>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rsi
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1175 <dump_buf+0x55>
mov    %ebp,%ebp
lea    0xec9(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
lea    -0x20(%rsi),%eax
cmp    $0x5f,%eax
mov    $0x2e,%edx
cmovb  %esi,%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <dump_buf+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [19 x i8] c"%s read %d bytes: \00"
@.str.1 = [12 x i8] c"0x%02x [%c]\00"
define void @dump_buf(i8* %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %16, %8 ]
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = add i32 %11, -32
%13 = icmp ult i32 %12, 95
%14 = select i1 %13, i32 %11, i32 46
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14)
%16 = add nuw nsw i64 %9, 1
%17 = icmp eq i64 %16, %7
br i1 %17, label %18, label %8
18: ; preds = %8, %3
%19 = tail call i32 @putchar(i32 10)
ret void
}