#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
void dump_buffer(char *text, char *str, int len) {
  fprintf(stderr, "%s", text);
  while (len > 0) {
    if (*str >= ' ')
      fprintf(stderr, "%c", *str++);
    else
      fprintf(stderr, "(%02x)", *str++);
    len--;
  }
}


x86 assembly (clang, -O0):
<dump_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xec9(%rip),%rsi
call   1030 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11b9 <dump_buffer+0xa9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     1183 <dump_buffer+0x73>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbq (%rax),%rdx
lea    0xe8a(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ab <dump_buffer+0x9b>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbq (%rax),%rdx
lea    0xe60(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <dump_buffer+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buffer>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%rdx
mov    0x2eb8(%rip),%r13
mov    0x0(%r13),%edi
lea    0xecd(%rip),%rsi
call   1030 <fprintf@plt>
test   %ebx,%ebx
jle    117a <dump_buffer+0x6a>
add    $0x1,%ebx
lea    0xebd(%rip),%r15
lea    0xeb9(%rip),%r12
jmp    1168 <dump_buffer+0x58>
nop
movsbq %dl,%rdx
mov    %r12,%rsi
call   1030 <fprintf@plt>
add    $0x1,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jle    117a <dump_buffer+0x6a>
movzbl (%r14),%edx
mov    0x0(%r13),%edi
cmp    $0x20,%dl
jl     1150 <dump_buffer+0x40>
mov    %r15,%rsi
jmp    1157 <dump_buffer+0x47>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"(%02x)\00"
define void @dump_buffer(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %4
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %34, %3
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %10
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp sge i32 %16, 32
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i8, i8* %20
%23 = sext i8 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %34
26: ; preds = %13
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
%30 = load i8, i8* %28
%31 = sext i8 %30 to i64
%32 = inttoptr i64 %31 to i8*
%33 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %26, %18
%35 = load i32, i32* %6
%36 = add nsw i32 %35, -1
store i32 %36, i32* %6
br label %10
37: ; preds = %10
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"(%02x)\00"
define void @dump_buffer(i8* %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %25
7: ; preds = %3, %21
%8 = phi i32 [ %23, %21 ], [ %2, %3 ]
%9 = phi i8* [ %22, %21 ], [ %1, %3 ]
%10 = load i8, i8* %9
%11 = icmp sgt i8 %10, 31
%12 = load i32, i32* @stderr
br i1 %11, label %13, label %17
13: ; preds = %7
%14 = zext i8 %10 to i64
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %21
17: ; preds = %7
%18 = sext i8 %10 to i64
%19 = inttoptr i64 %18 to i8*
%20 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %17, %13
%22 = getelementptr inbounds i8, i8* %9, i64 1
%23 = add nsw i32 %8, -1
%24 = icmp sgt i32 %8, 1
br i1 %24, label %7, label %25
25: ; preds = %21, %3
ret void
}