#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 *, unsigned char const);
void dump_string(const char *str, long long len) {
  long long i;
  const unsigned char *s = (const unsigned char *)str;
  for (i = 0; i < len; ++i)
    if (s[i] >= 0x20 && s[i] <= 0x7e)
      printf("%c", s[i]);
    else
      printf("\\x%02x", s[i]);
}


x86 assembly (clang, -O0):
<dump_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11b3 <dump_string+0xa3>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1185 <dump_string+0x75>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jg     1185 <dump_string+0x75>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
lea    0xe89(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    119d <dump_string+0x8d>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
lea    0xe6f(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    11a2 <dump_string+0x92>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1130 <dump_string+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
jle    1162 <dump_string+0x52>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xed3(%rip),%r12
lea    0xecf(%rip),%r13
jmp    114e <dump_string+0x3e>
cs nopw 0x0(%rax,%rax,1)
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     1162 <dump_string+0x52>
movzbl (%r14,%rbx,1),%esi
lea    -0x20(%rsi),%eax
mov    %r12,%rdi
cmp    $0x5f,%al
jb     1140 <dump_string+0x30>
mov    %r13,%rdi
jmp    1140 <dump_string+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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