#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);
int /*<<< orphan*/ putchar(unsigned char const);
void ansiescape_string(const unsigned char *s, int len) {
  for (; --len >= 0; s++)
    if (((unsigned char)*s) < 33 || ((unsigned char)*s) >= 127)
      printf("\\%03o", (unsigned char)*s);
    else
      switch (*s) {
      case '\\':
      case '\'':
        putchar('\\');
      default:
        putchar(*s);
        break;
      }
}


x86 assembly (clang, -O0):
<ansiescape_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     11d3 <ansiescape_string+0xb3>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x21,%eax
jl     1161 <ansiescape_string+0x41>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jl     1179 <ansiescape_string+0x59>
mov    -0x8(%rbp),%rax
lea    0xe94(%rip),%rdi
movzbl (%rax),%esi
call   1040 <printf@plt>
jmp    11bd <ansiescape_string+0x9d>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x10(%rbp)
sub    $0x27,%eax
je     11a2 <ansiescape_string+0x82>
jmp    1191 <ansiescape_string+0x71>
mov    -0x10(%rbp),%eax
sub    $0x5c,%eax
jne    11ac <ansiescape_string+0x8c>
jmp    11a2 <ansiescape_string+0x82>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <putchar@plt>
jmp    11bd <ansiescape_string+0x9d>
jmp    11c2 <ansiescape_string+0xa2>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112f <ansiescape_string+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ansiescape_string>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    1181 <ansiescape_string+0x61>
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x1,%ebp
lea    0xec9(%rip),%r14
jmp    1157 <ansiescape_string+0x37>
nopl   0x0(%rax)
movzbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jbe    1181 <ansiescape_string+0x61>
movzbl (%rbx),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
jbe    1140 <ansiescape_string+0x20>
cmp    $0x5c,%al
je     116a <ansiescape_string+0x4a>
cmp    $0x27,%al
jne    1177 <ansiescape_string+0x57>
mov    $0x5c,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
movzbl %al,%edi
call   1030 <putchar@plt>
jmp    114b <ansiescape_string+0x2b>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\\%03o\00"
define void @ansiescape_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 = %35, %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 %38
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = icmp slt i32 %12, 33
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp sge i32 %17, 127
br i1 %18, label %19, label %23
19: ; preds = %14, %9
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %21)
br label %34
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
switch i32 %26, label %29 [
i32 92, label %27
i32 39, label %27
]
27: ; preds = %23, %23
%28 = call i32 @putchar(i8 zeroext 92)
br label %29
29: ; preds = %23, %27
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = call i32 @putchar(i8 zeroext %31)
br label %33
33: ; preds = %29
br label %34
34: ; preds = %33, %19
br label %35
35: ; preds = %34
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
br label %5
38: ; preds = %5
ret void
}

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