#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 char uint8_t;
typedef int uint16_t;

/* Variables and functions */
scalar_t__ isprint(char);
int /*<<< orphan*/ printf(char *, char *, int, char, char);
void dump_buf(char *name, uint8_t *buf, uint16_t count) {
  for (int i = 0; i < count; i++) {
    uint8_t c = (uint8_t)buf[i];
    printf("%s %d: 0x%02x ('%c')\n", name, i, c, isprint(c) ? c : '.');
  }
}


x86 assembly (clang, -O0):
<dump_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c2 <dump_buf+0xa2>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x19(%rbp),%al
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1187 <dump_buf+0x67>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1194 <dump_buf+0x74>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    1194 <dump_buf+0x74>
mov    -0x1a(%rbp),%cl
mov    -0x20(%rbp),%edx
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%eax
lea    0xe58(%rip),%rdi
movsbl %cl,%ecx
movsbl %al,%r8d
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <dump_buf+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1183 <dump_buf+0x63>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r13d
xor    %ebx,%ebx
lea    0xebf(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%ebp
mov    %ebp,%edi
call   1040 <isprint@plt>
test   %rax,%rax
mov    %ebp,%r8d
mov    $0x2e,%eax
cmove  %eax,%r8d
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1150 <dump_buf+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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