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


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

x86 assembly (clang, -O2):
<pr_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1197 <pr_string+0x77>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0xeca(%rip),%r14
lea    0xec0(%rip),%r15
lea    0xeb6(%rip),%r12
jmp    1165 <pr_string+0x45>
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1197 <pr_string+0x77>
movsbl %al,%edi
cmp    $0xa,%edi
je     1180 <pr_string+0x60>
cmp    $0x5c,%edi
je     1150 <pr_string+0x30>
cmp    $0x22,%edi
jne    1190 <pr_string+0x70>
mov    %r12,%rdi
jmp    1153 <pr_string+0x33>
nopl   0x0(%rax)
mov    %r14,%rdi
jmp    1153 <pr_string+0x33>
cs nopw 0x0(%rax,%rax,1)
nop
call   1030 <putchar@plt>
jmp    115a <pr_string+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
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 @pr_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*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %24
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(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*, ...) @printf(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*, ...) @printf(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"
define i32 @pr_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*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %4
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) 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*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %4
%15 = tail call i32 @putchar(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
}