#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void print_string(char *str, FILE *fp) {
  if (str == NULL)
    return;
  for (char *walk = str; *walk != '\0'; ++walk) {
    if (*walk != '\\') {
      fputc(*walk, fp);
    } else if (*(walk + 1) == '\\') {
      fputc('\\', fp);
    }
  }
}


x86 assembly (clang, -O0):
<print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1130 <print_string+0x20>
jmp    11a9 <print_string+0x99>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a9 <print_string+0x99>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     116f <print_string+0x5f>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    1193 <print_string+0x83>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x5c,%eax
jne    118e <print_string+0x7e>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1030 <fputc@plt>
jmp    1193 <print_string+0x83>
jmp    1198 <print_string+0x88>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <print_string+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_string>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1154 <print_string+0x44>
mov    %rsi,%r14
mov    %rdi,%rbx
jmp    113f <print_string+0x2f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %al,%al
je     1154 <print_string+0x44>
movsbl %al,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0x5c,%al
jne    1130 <print_string+0x20>
mov    $0x5c,%al
cmpb   $0x5c,(%rbx)
jne    113f <print_string+0x2f>
jmp    1134 <print_string+0x24>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @print_string(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
br label %40
9: ; preds = %2
%10 = load i8*, i8** %3
store i8* %10, i8** %5
br label %11
11: ; preds = %37, %9
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %40
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 92
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = load i32*, i32** %4
%25 = call i32 @fputc(i8 signext %23, i32* %24)
br label %36
26: ; preds = %16
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 92
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32*, i32** %4
%34 = call i32 @fputc(i8 signext 92, i32* %33)
br label %35
35: ; preds = %32, %26
br label %36
36: ; preds = %35, %21
br label %37
37: ; preds = %36
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
br label %11
40: ; preds = %8, %11
ret void
}

LLVM IR (-O2):
define void @print_string(i8* %0, i32* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %16, label %4
4: ; preds = %2, %14
%5 = phi i8* [ %15, %14 ], [ %0, %2 ]
%6 = load i8, i8* %5
switch i8 %6, label %11 [
i8 0, label %16
i8 92, label %7
]
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 92
br i1 %10, label %11, label %14
11: ; preds = %7, %4
%12 = phi i8 [ %6, %4 ], [ 92, %7 ]
%13 = tail call i32 @fputc(i8 signext %12, i32* %1)
br label %14
14: ; preds = %11, %7
%15 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
16: ; preds = %4, %2
ret void
}