out_string(s) char *s;
{
  for (; *s != '\0'; s++)
    switch (*s) {
    case '"':
      out("\\\"");
      break;
    case '\\':
      out("\\\\");
      break;
    case '\n':
      out("\\n");
      break;
    default:
      out("%c", *s);
    }
}


x86 assembly (clang, -O0):
<out_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ca <out_string+0xba>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0xa,%eax
je     118c <out_string+0x7c>
jmp    1144 <out_string+0x34>
mov    -0x14(%rbp),%eax
sub    $0x22,%eax
je     1166 <out_string+0x56>
jmp    1155 <out_string+0x45>
mov    -0x14(%rbp),%eax
sub    $0x5c,%eax
je     1179 <out_string+0x69>
jmp    119f <out_string+0x8f>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <out@plt>
jmp    11b4 <out_string+0xa4>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <out@plt>
jmp    11b4 <out_string+0xa4>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <out@plt>
jmp    11b4 <out_string+0xa4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <out@plt>
jmp    11b9 <out_string+0xa9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    111c <out_string+0xc>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<out_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     119c <out_string+0x8c>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0xed9(%rip),%r14
lea    0xecf(%rip),%r15
lea    0xec5(%rip),%r12
lea    0xec7(%rip),%r13
jmp    1165 <out_string+0x55>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <out@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     119c <out_string+0x8c>
movsbl %al,%esi
cmp    $0xa,%esi
je     1180 <out_string+0x70>
cmp    $0x5c,%esi
je     1150 <out_string+0x40>
cmp    $0x22,%esi
jne    1190 <out_string+0x80>
mov    %r12,%rdi
jmp    1153 <out_string+0x43>
nopl   0x0(%rax)
mov    %r14,%rdi
jmp    1153 <out_string+0x43>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <out@plt>
jmp    115a <out_string+0x4a>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\\22\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @out_string(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
br label %4
4: ; preds = %25, %1
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %4
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %19 [
i32 34, label %13
i32 92, label %15
i32 10, label %17
]
13: ; preds = %9
%14 = call i32 (i8*, ...) bitcast (i32 (...)* @out to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %24
15: ; preds = %9
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @out to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
17: ; preds = %9
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @out to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
19: ; preds = %9
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @out to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %19, %17, %15, %13
br label %25
25: ; preds = %24
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
br label %4
28: ; preds = %4
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\\22\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @out_string(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %16
%5 = phi i8 [ %18, %16 ], [ %2, %1 ]
%6 = phi i8* [ %17, %16 ], [ %0, %1 ]
%7 = sext i8 %5 to i32
switch i32 %7, label %14 [
i32 34, label %8
i32 92, label %10
i32 10, label %12
]
8: ; preds = %4
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @out to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %4
%11 = tail call i32 (i8*, ...) bitcast (i32 (...)* @out to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %16
12: ; preds = %4
%13 = tail call i32 (i8*, ...) bitcast (i32 (...)* @out to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %4
%15 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @out to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %16
16: ; preds = %8, %10, %12, %14
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %4
20: ; preds = %16, %1
ret i32 undef
}