#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 debug_buffer(char *buffer, int len) {
  int i;
  char tmp[2];
  tmp[0] = ' ';
  tmp[1] = '\0';
  printf("buffer:\n>>>\n");
  for (i = 0; i < len; ++i) {
    char c = buffer[i];
    if ((c >= ' ' && c <= 'z') || (c == 0x0d) || (c == 0x0a)) {
      tmp[0] = c;
    } else {
      tmp[0] = '*';
    }
    printf("%s", (char *)tmp);
  }
  printf("\n<<<\n");
}


x86 assembly (clang, -O0):
<debug_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x20,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b9 <debug_buffer+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x13(%rbp)
movsbl -0x13(%rbp),%eax
cmp    $0x20,%eax
jl     1170 <debug_buffer+0x60>
movsbl -0x13(%rbp),%eax
cmp    $0x7a,%eax
jle    118a <debug_buffer+0x7a>
movsbl -0x13(%rbp),%eax
cmp    $0xd,%eax
je     118a <debug_buffer+0x7a>
movsbl -0x13(%rbp),%eax
cmp    $0xa,%eax
jne    1195 <debug_buffer+0x85>
mov    -0x13(%rbp),%al
mov    %al,-0x12(%rbp)
jmp    1199 <debug_buffer+0x89>
movb   $0x2a,-0x12(%rbp)
lea    -0x12(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <debug_buffer+0x2c>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r13
movw   $0x20,0x6(%rsp)
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jle    11a0 <debug_buffer+0x80>
mov    %ebp,%ebp
mov    $0xd,%r12d
lea    0xeaa(%rip),%r14
lea    0x6(%rsp),%r15
xor    %ebx,%ebx
nopl   (%rax)
movzbl 0x0(%r13,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0xa,%al
setne  %dl
shl    $0x5,%dl
or     $0xa,%dl
cmp    $0xd,%al
movzbl %dl,%edx
cmove  %r12d,%edx
cmp    $0x5b,%cl
movzbl %al,%eax
cmovae %edx,%eax
mov    %al,0x6(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <debug_buffer+0x40>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@str = [12 x i8] c"buffer:\0A>>>\00"
@str.3 = [5 x i8] c"\0A<<<\00"
define void @debug_buffer(i8* nocapture %0, i32 %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 32, i8* %4
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %25
8: ; preds = %2
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %23, %10 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = freeze i8 %13
%15 = add i8 %14, -32
%16 = icmp ult i8 %15, 91
%17 = icmp eq i8 %14, 10
%18 = select i1 %17, i8 10, i8 42
%19 = icmp eq i8 %14, 13
%20 = select i1 %19, i8 13, i8 %18
%21 = select i1 %16, i8 %14, i8 %20
store i8 %21, i8* %4
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%23 = add nuw nsw i64 %11, 1
%24 = icmp eq i64 %23, %9
br i1 %24, label %25, label %10
25: ; preds = %10, %2
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.3, i64 0, i64 0))
ret void
}