#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*/ assert(char *);
int /*<<< orphan*/ bee_fnprint(int /*<<< orphan*/, size_t, char *);
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
void print_escaped(char *s, size_t n) {
  char *c;
  assert(s);
  c = s;
  bee_fnprint(stdout, 0, "'");
  while ((c = strchr(s, '\'')) && c - s < n) {
    if (c - s)
      bee_fnprint(stdout, c - s, s);
    bee_fnprint(stdout, 0, "'\\''");
    n -= c - s + 1;
    s = c + 1;
  }
  if (n)
    bee_fnprint(stdout, n, s);
  bee_fnprint(stdout, 0, "'\n");
}


x86 assembly (clang, -O0):
<print_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe9e(%rip),%rdx
call   1030 <bee_fnprint@plt>
mov    -0x8(%rbp),%rdi
mov    $0x27,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     11a3 <print_escaped+0x73>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11b3 <print_escaped+0x83>
jmp    1229 <print_escaped+0xf9>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x0,%rax
je     11e5 <print_escaped+0xb5>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rax
sub    %rax,%rsi
mov    -0x8(%rbp),%rdx
call   1030 <bee_fnprint@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe07(%rip),%rdx
call   1030 <bee_fnprint@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
sub    %rax,%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116a <print_escaped+0x3a>
cmpq   $0x0,-0x10(%rbp)
je     124a <print_escaped+0x11a>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <bee_fnprint@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xda7(%rip),%rdx
call   1030 <bee_fnprint@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_escaped>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
call   1050 <assert@plt>
mov    0x2e93(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xeac(%rip),%rdx
xor    %esi,%esi
call   1030 <bee_fnprint@plt>
mov    %r13,%rdi
mov    $0x27,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11cf <print_escaped+0x9f>
mov    %rax,%r12
lea    0xe86(%rip),%r15
jmp    11af <print_escaped+0x7f>
nopl   0x0(%rax)
mov    0x0(%rbp),%edi
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <bee_fnprint@plt>
not    %rbx
add    %rbx,%r14
mov    %r12,%r13
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x27,%esi
call   1040 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
je     11cf <print_escaped+0x9f>
mov    %r12,%rbx
sub    %r13,%rbx
cmp    %r14,%rbx
jae    11cf <print_escaped+0x9f>
test   %rbx,%rbx
je     1180 <print_escaped+0x50>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <bee_fnprint@plt>
jmp    1180 <print_escaped+0x50>
test   %r14,%r14
je     11e2 <print_escaped+0xb2>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <bee_fnprint@plt>
mov    0x0(%rbp),%edi
lea    0xe19(%rip),%rdx
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <bee_fnprint@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"'\00"
@.str.1 = [5 x i8] c"'\\''\00"
@.str.2 = [3 x i8] c"'\0A\00"
define void @print_escaped(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = call i32 @assert(i8* %6)
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i32, i32* @stdout
%10 = call i32 @bee_fnprint(i32 %9, i64 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %41, %2
%12 = load i8*, i8** %3
%13 = call i8* @strchr(i8* %12, i8 signext 39)
store i8* %13, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8*, i8** %3
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = load i64, i64* %4
%22 = icmp ult i64 %20, %21
br label %23
23: ; preds = %15, %11
%24 = phi i1 [ false, %11 ], [ %22, %15 ]
br i1 %24, label %25, label %54
25: ; preds = %23
%26 = load i8*, i8** %5
%27 = load i8*, i8** %3
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %25
%33 = load i32, i32* @stdout
%34 = load i8*, i8** %5
%35 = load i8*, i8** %3
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = load i8*, i8** %3
%40 = call i32 @bee_fnprint(i32 %33, i64 %38, i8* %39)
br label %41
41: ; preds = %32, %25
%42 = load i32, i32* @stdout
%43 = call i32 @bee_fnprint(i32 %42, i64 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%44 = load i8*, i8** %5
%45 = load i8*, i8** %3
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = add nsw i64 %48, 1
%50 = load i64, i64* %4
%51 = sub i64 %50, %49
store i64 %51, i64* %4
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i64 1
store i8* %53, i8** %3
br label %11
54: ; preds = %23
%55 = load i64, i64* %4
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i32, i32* @stdout
%59 = load i64, i64* %4
%60 = load i8*, i8** %3
%61 = call i32 @bee_fnprint(i32 %58, i64 %59, i8* %60)
br label %62
62: ; preds = %57, %54
%63 = load i32, i32* @stdout
%64 = call i32 @bee_fnprint(i32 %63, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [2 x i8] c"'\00"
@.str.1 = [5 x i8] c"'\\''\00"
@.str.2 = [3 x i8] c"'\0A\00"
define void @print_escaped(i8* %0, i64 %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = load i32, i32* @stdout
%5 = tail call i32 @bee_fnprint(i32 %4, i64 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 39)
%7 = icmp eq i8* %6, null
br i1 %7, label %29, label %8
8: ; preds = %2, %21
%9 = phi i8* [ %27, %21 ], [ %6, %2 ]
%10 = phi i64 [ %25, %21 ], [ %1, %2 ]
%11 = phi i8* [ %26, %21 ], [ %0, %2 ]
%12 = ptrtoint i8* %9 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = icmp ult i64 %14, %10
br i1 %15, label %16, label %29
16: ; preds = %8
%17 = icmp eq i64 %14, 0
br i1 %17, label %21, label %18
18: ; preds = %16
%19 = load i32, i32* @stdout
%20 = tail call i32 @bee_fnprint(i32 %19, i64 %14, i8* %11)
br label %21
21: ; preds = %18, %16
%22 = load i32, i32* @stdout
%23 = tail call i32 @bee_fnprint(i32 %22, i64 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = xor i64 %14, -1
%25 = add i64 %10, %24
%26 = getelementptr inbounds i8, i8* %9, i64 1
%27 = tail call i8* @strchr(i8* dereferenceable(1) %26, i8 signext 39)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %8
29: ; preds = %8, %21, %2
%30 = phi i8* [ %0, %2 ], [ %26, %21 ], [ %11, %8 ]
%31 = phi i64 [ %1, %2 ], [ %25, %21 ], [ %10, %8 ]
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i32, i32* @stdout
%35 = tail call i32 @bee_fnprint(i32 %34, i64 %31, i8* %30)
br label %36
36: ; preds = %33, %29
%37 = load i32, i32* @stdout
%38 = tail call i32 @bee_fnprint(i32 %37, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}