#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*/ putchar(char const);
void print_buffer(const void *buf, int bytes) {
  static const char digits[] = "0123456789ABCDEF";
  const char *src = (const char *)buf;
  while (bytes--) {
    char ch = *src++;
    if (ch > 0x1F && ch < 0x7F) {
      putchar(ch);
    } else {
      putchar('\\');
      putchar('x');
      putchar(digits[ch & 0x0F]);
      putchar(digits[(ch >> 4) & 0x0F]);
    }
  }
}


x86 assembly (clang, -O0):
<print_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11c7 <print_buffer+0xb7>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x1f,%eax
jle    1177 <print_buffer+0x67>
movsbl -0x19(%rbp),%eax
cmp    $0x7f,%eax
jge    1177 <print_buffer+0x67>
movsbl -0x19(%rbp),%edi
call   1030 <putchar@plt>
jmp    11c2 <print_buffer+0xb2>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x78,%edi
call   1030 <putchar@plt>
movsbl -0x19(%rbp),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe64(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
movsbl -0x19(%rbp),%eax
sar    $0x4,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe47(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    1127 <print_buffer+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buffer>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
je     1182 <print_buffer+0x72>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
lea    0xed4(%rip),%r12
jmp    1141 <print_buffer+0x31>
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %ebx,%r15d
je     1182 <print_buffer+0x72>
movzbl (%r14,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
jb     1130 <print_buffer+0x20>
movzbl %al,%r13d
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    $0x78,%edi
call   1030 <putchar@plt>
mov    %r13d,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%edi
call   1030 <putchar@plt>
shr    $0x4,%r13
movzbl 0x0(%r13,%r12,1),%eax
jmp    1130 <print_buffer+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@print_buffer.digits = internal constant [17 x i8] c"0123456789ABCDEF\00"
define void @print_buffer(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
br label %8
8: ; preds = %44, %2
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %45
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
%15 = load i8, i8* %13
store i8 %15, i8* %6
%16 = load i8, i8* %6
%17 = sext i8 %16 to i32
%18 = icmp sgt i32 %17, 31
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
%22 = icmp slt i32 %21, 127
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8, i8* %6
%25 = call i32 @putchar(i8 signext %24)
br label %44
26: ; preds = %19, %12
%27 = call i32 @putchar(i8 signext 92)
%28 = call i32 @putchar(i8 signext 120)
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = and i32 %30, 15
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [17 x i8], [17 x i8]* @print_buffer.digits, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @putchar(i8 signext %34)
%36 = load i8, i8* %6
%37 = sext i8 %36 to i32
%38 = ashr i32 %37, 4
%39 = and i32 %38, 15
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [17 x i8], [17 x i8]* @print_buffer.digits, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @putchar(i8 signext %42)
br label %44
44: ; preds = %26, %23
br label %8
45: ; preds = %8
ret void
}

LLVM IR (-O2):
@print_buffer.digits = internal unnamed_addr constant [17 x i8] c"0123456789ABCDEF\00"
define void @print_buffer(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %29, label %4
4: ; preds = %2, %25
%5 = phi i32 [ %7, %25 ], [ %1, %2 ]
%6 = phi i8* [ %8, %25 ], [ %0, %2 ]
%7 = add nsw i32 %5, -1
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = load i8, i8* %6
%10 = zext i8 %9 to i32
%11 = add i8 %9, -32
%12 = icmp ult i8 %11, 95
br i1 %12, label %25, label %13
13: ; preds = %4
%14 = tail call i32 @putchar(i8 signext 92)
%15 = tail call i32 @putchar(i8 signext 120)
%16 = and i32 %10, 15
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [17 x i8], [17 x i8]* @print_buffer.digits, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = tail call i32 @putchar(i8 signext %19)
%21 = lshr i32 %10, 4
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @print_buffer.digits, i64 0, i64 %22
%24 = load i8, i8* %23
br label %25
25: ; preds = %4, %13
%26 = phi i8 [ %24, %13 ], [ %9, %4 ]
%27 = tail call i32 @putchar(i8 signext %26)
%28 = icmp eq i32 %7, 0
br i1 %28, label %29, label %4
29: ; preds = %25, %2
ret void
}