#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int strlen(char *);
void saveWithSpecialChars(FILE *ofp, char *text) {
  int i;
  if (text == NULL) {
    return;
  }
  for (i = 0; i < strlen(text); i++) {
    if (text[i] == '\0') {
      break;
    } else if (text[i] == '\\' || text[i] == '#') {
      fprintf(ofp, "\\");
    }
    fprintf(ofp, "%c", text[i]);
  }
}


x86 assembly (clang, -O0):
<saveWithSpecialChars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1140 <saveWithSpecialChars+0x20>
jmp    11ea <saveWithSpecialChars+0xca>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11ea <saveWithSpecialChars+0xca>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    117d <saveWithSpecialChars+0x5d>
jmp    11ea <saveWithSpecialChars+0xca>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     11a7 <saveWithSpecialChars+0x87>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x23,%eax
jne    11b9 <saveWithSpecialChars+0x99>
mov    -0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11be <saveWithSpecialChars+0x9e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <saveWithSpecialChars+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveWithSpecialChars>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1181 <saveWithSpecialChars+0x61>
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1181 <saveWithSpecialChars+0x61>
xor    %ebx,%ebx
jmp    1170 <saveWithSpecialChars+0x50>
mov    $0x5c,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
movzbl (%r15,%rbx,1),%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1181 <saveWithSpecialChars+0x61>
movzbl (%r15,%rbx,1),%eax
cmp    $0x23,%al
je     1140 <saveWithSpecialChars+0x20>
cmp    $0x5c,%al
je     1140 <saveWithSpecialChars+0x20>
test   %al,%al
jne    1152 <saveWithSpecialChars+0x32>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\\\00"
@.str.1 = [3 x i8] c"%c\00"
define void @saveWithSpecialChars(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
br label %56
9: ; preds = %2
store i32 0, i32* %5
br label %10
10: ; preds = %53, %9
%11 = load i32, i32* %5
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %56
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
br label %56
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 92
br i1 %31, label %40, label %32
32: ; preds = %24
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 35
br i1 %39, label %40, label %43
40: ; preds = %32, %24
%41 = load i32*, i32** %3
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %40, %32
br label %44
44: ; preds = %43
%45 = load i32*, i32** %3
%46 = load i8*, i8** %4
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %44
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %10
56: ; preds = %8, %23, %10
ret void
}

LLVM IR (-O2):
define void @saveWithSpecialChars(i32* nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %4, %14
%8 = phi i64 [ %18, %14 ], [ 0, %4 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %14 [
i8 0, label %22
i8 92, label %11
i8 35, label %11
]
11: ; preds = %7, %7
%12 = tail call i32 @fputc(i32 92, i32* %0)
%13 = load i8, i8* %9
br label %14
14: ; preds = %7, %11
%15 = phi i8 [ %10, %7 ], [ %13, %11 ]
%16 = sext i8 %15 to i32
%17 = tail call i32 @fputc(i32 %16, i32* %0)
%18 = add nuw nsw i64 %8, 1
%19 = tail call i32 @strlen(i8* %1)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %7, label %22
22: ; preds = %7, %14, %4, %2
ret void
}