#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);
int /*<<< orphan*/ putchar(unsigned char const);
void escape_string(const unsigned char *s, int len) {
  for (; --len >= 0; s++) {
    if (*s <= 0x20 || (*s > 0x7f && *s < 0xa0))
      printf("\\0%03o", *s);
    else
      putchar(*s);
  }
}


x86 assembly (clang, -O0):
<escape_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     11ad <escape_string+0x8d>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jle    1173 <escape_string+0x53>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jle    118b <escape_string+0x6b>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa0,%eax
jge    118b <escape_string+0x6b>
mov    -0x8(%rbp),%rax
lea    0xe82(%rip),%rdi
movzbl (%rax),%esi
call   1040 <printf@plt>
jmp    1197 <escape_string+0x77>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <putchar@plt>
jmp    119c <escape_string+0x7c>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112f <escape_string+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_string>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    116c <escape_string+0x4c>
mov    %esi,%ebx
mov    %rdi,%r14
add    $0x1,%ebx
lea    0xec8(%rip),%r15
jmp    1154 <escape_string+0x34>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jbe    116c <escape_string+0x4c>
movzbl (%r14),%eax
movzbl %al,%esi
cmp    $0x21,%al
jb     1140 <escape_string+0x20>
cmp    $0x9f,%al
jle    1140 <escape_string+0x20>
mov    %esi,%edi
call   1030 <putchar@plt>
jmp    1148 <escape_string+0x28>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"\\0%03o\00"
define void @escape_string(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %19
4: ; preds = %2, %16
%5 = phi i32 [ %7, %16 ], [ %1, %2 ]
%6 = phi i8* [ %17, %16 ], [ %0, %2 ]
%7 = add nsw i32 %5, -1
%8 = load i8, i8* %6
%9 = icmp ult i8 %8, 33
%10 = icmp slt i8 %8, -96
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %8)
br label %16
14: ; preds = %4
%15 = tail call i32 @putchar(i8 zeroext %8)
br label %16
16: ; preds = %12, %14
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = icmp ugt i32 %5, 1
br i1 %18, label %4, label %19
19: ; preds = %16, %2
ret void
}