#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*/ out_fputs(char *);
int /*<<< orphan*/ out_putc(char);
void escape_string(register char const *s) {
  register char c;
  for (;;) {
    switch ((c = *s++)) {
    case 0:
      return;
    case '\t':
      out_fputs("\\t");
      break;
    case '\n':
      out_fputs("\\n");
      break;
    case ' ':
      out_fputs("\\040");
      break;
    case '$':
      out_fputs("\\044");
      break;
    case '\\':
      out_fputs("\\\\");
      break;
    default:
      out_putc(c);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<escape_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    %al,%cl
mov    %cl,-0x9(%rbp)
test   %eax,%eax
je     11a8 <escape_string+0x88>
jmp    1153 <escape_string+0x33>
mov    -0x10(%rbp),%eax
sub    $0x9,%eax
je     11ae <escape_string+0x8e>
jmp    1164 <escape_string+0x44>
mov    -0x10(%rbp),%eax
sub    $0xa,%eax
je     11bf <escape_string+0x9f>
jmp    1175 <escape_string+0x55>
mov    -0x10(%rbp),%eax
sub    $0x20,%eax
je     11d0 <escape_string+0xb0>
jmp    1186 <escape_string+0x66>
mov    -0x10(%rbp),%eax
sub    $0x24,%eax
je     11e1 <escape_string+0xc1>
jmp    1197 <escape_string+0x77>
mov    -0x10(%rbp),%eax
sub    $0x5c,%eax
je     11f2 <escape_string+0xd2>
jmp    1203 <escape_string+0xe3>
add    $0x10,%rsp
pop    %rbp
ret
lea    0xe4b(%rip),%rdi
call   1040 <out_fputs@plt>
jmp    120c <escape_string+0xec>
lea    0xe3d(%rip),%rdi
call   1040 <out_fputs@plt>
jmp    120c <escape_string+0xec>
lea    0xe2f(%rip),%rdi
call   1040 <out_fputs@plt>
jmp    120c <escape_string+0xec>
lea    0xe23(%rip),%rdi
call   1040 <out_fputs@plt>
jmp    120c <escape_string+0xec>
lea    0xe17(%rip),%rdi
call   1040 <out_fputs@plt>
jmp    120c <escape_string+0xec>
movsbl -0x9(%rbp),%edi
call   1030 <out_putc@plt>
jmp    112c <escape_string+0xc>

x86 assembly (clang, -O2):
<escape_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xecb(%rip),%r14
lea    0xf58(%rip),%r15
lea    0xf54(%rip),%r12
lea    0xf50(%rip),%r13
lea    0xf4e(%rip),%rbp
jmp    1160 <escape_string+0x40>
call   1030 <out_putc@plt>
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
add    $0x1,%rbx
cmp    $0x24,%edi
ja     1180 <escape_string+0x60>
movslq (%r14,%rdi,4),%rax
add    %r14,%rax
jmp    *%rax
mov    %r15,%rdi
call   1040 <out_fputs@plt>
jmp    1160 <escape_string+0x40>
nop
cmp    $0x5c,%edi
jne    1153 <escape_string+0x33>
lea    0xf18(%rip),%rdi
call   1040 <out_fputs@plt>
jmp    1160 <escape_string+0x40>
mov    %r12,%rdi
call   1040 <out_fputs@plt>
jmp    1160 <escape_string+0x40>
mov    %r13,%rdi
call   1040 <out_fputs@plt>
jmp    1160 <escape_string+0x40>
mov    %rbp,%rdi
call   1040 <out_fputs@plt>
jmp    1160 <escape_string+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [5 x i8] c"\\040\00"
@.str.3 = [5 x i8] c"\\044\00"
@.str.4 = [3 x i8] c"\\\\\00"
define void @escape_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
store i8* %0, i8** %2
br label %4
4: ; preds = %23, %1
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %2
%7 = load i8, i8* %5
store i8 %7, i8* %3
%8 = sext i8 %7 to i32
switch i32 %8, label %20 [
i32 0, label %9
i32 9, label %10
i32 10, label %12
i32 32, label %14
i32 36, label %16
i32 92, label %18
]
9: ; preds = %4
ret void
10: ; preds = %4
%11 = call i32 @out_fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %23
12: ; preds = %4
%13 = call i32 @out_fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %23
14: ; preds = %4
%15 = call i32 @out_fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %23
16: ; preds = %4
%17 = call i32 @out_fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %23
18: ; preds = %4
%19 = call i32 @out_fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %23
20: ; preds = %4
%21 = load i8, i8* %3
%22 = call i32 @out_putc(i8 signext %21)
br label %23
23: ; preds = %20, %18, %16, %14, %12, %10
br label %4
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [5 x i8] c"\\040\00"
@.str.3 = [5 x i8] c"\\044\00"
@.str.4 = [3 x i8] c"\\\\\00"
define void @escape_string(i8* nocapture %0) {
br label %2
2: ; preds = %20, %1
%3 = phi i8* [ %0, %1 ], [ %4, %20 ]
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
switch i32 %6, label %18 [
i32 0, label %7
i32 9, label %8
i32 10, label %10
i32 32, label %12
i32 36, label %14
i32 92, label %16
]
7: ; preds = %2
ret void
8: ; preds = %2
%9 = tail call i32 @out_fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %20
10: ; preds = %2
%11 = tail call i32 @out_fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %20
12: ; preds = %2
%13 = tail call i32 @out_fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %20
14: ; preds = %2
%15 = tail call i32 @out_fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %20
16: ; preds = %2
%17 = tail call i32 @out_fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %20
18: ; preds = %2
%19 = tail call i32 @out_putc(i8 signext %5)
br label %20
20: ; preds = %18, %16, %14, %12, %10, %8
br label %2
}