#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 */
struct ADrawTag {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ Utf8Decode(char const *, unsigned int *, unsigned int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char const, int /*<<< orphan*/ *);
int /*<<< orphan*/ *getPsFile(struct ADrawTag *);
void writeEscaped(struct ADrawTag *ctx, const char *string) {
  FILE *f = getPsFile(ctx);
  while (*string != '\0') {
    unsigned int code, bytes;
    switch (*string) {
    case '(':
      fprintf(f, "\\(");
      break;
    case ')':
      fprintf(f, "\\)");
      break;
    default:
      if (Utf8Decode(string, &code, &bytes)) {
        fprintf(f, "\\%o", code);
        string += bytes - 1;
      } else {
        fputc(*string, f);
      }
      break;
    }
    string++;
  }
}


x86 assembly (clang, -O0):
<writeEscaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getPsFile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1233 <writeEscaped+0xf3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x28,%eax
je     1196 <writeEscaped+0x56>
jmp    1185 <writeEscaped+0x45>
mov    -0x24(%rbp),%eax
sub    $0x29,%eax
je     11ad <writeEscaped+0x6d>
jmp    11c4 <writeEscaped+0x84>
mov    -0x18(%rbp),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1222 <writeEscaped+0xe2>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1222 <writeEscaped+0xe2>
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <Utf8Decode@plt>
cmp    $0x0,%eax
je     120b <writeEscaped+0xcb>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    121d <writeEscaped+0xdd>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1222 <writeEscaped+0xe2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115d <writeEscaped+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeEscaped>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1060 <getPsFile@plt>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     120f <writeEscaped+0xbf>
lea    0xe8c(%rip),%r15
lea    0xe82(%rip),%r12
lea    0x4(%rsp),%r13
mov    %rsp,%rbp
jmp    11b1 <writeEscaped+0x61>
nopl   0x0(%rax,%rax,1)
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1070 <fwrite@plt>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     120f <writeEscaped+0xbf>
movsbl %al,%eax
cmp    $0x29,%eax
je     1190 <writeEscaped+0x40>
cmp    $0x28,%eax
jne    11d0 <writeEscaped+0x80>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    119d <writeEscaped+0x4d>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1030 <Utf8Decode@plt>
test   %eax,%eax
je     1202 <writeEscaped+0xb2>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
lea    0xe16(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rsp),%eax
add    $0xffffffff,%eax
add    %rax,%rbx
jmp    11a5 <writeEscaped+0x55>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
jmp    11a5 <writeEscaped+0x55>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ADrawTag = type { i32 }
@.str = [3 x i8] c"\\(\00"
@.str.1 = [3 x i8] c"\\)\00"
@.str.2 = [4 x i8] c"\\%o\00"
define void @writeEscaped(%struct.ADrawTag* %0, i8* %1) {
%3 = alloca %struct.ADrawTag*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store %struct.ADrawTag* %0, %struct.ADrawTag** %3
store i8* %1, i8** %4
%8 = load %struct.ADrawTag*, %struct.ADrawTag** %3
%9 = call i32* @getPsFile(%struct.ADrawTag* %8)
store i32* %9, i32** %5
br label %10
10: ; preds = %44, %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %47
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %25 [
i32 40, label %19
i32 41, label %22
]
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %44
22: ; preds = %15
%23 = load i32*, i32** %5
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %44
25: ; preds = %15
%26 = load i8*, i8** %4
%27 = call i32 @Utf8Decode(i8* %26, i32* %6, i32* %7)
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32*, i32** %5
%31 = load i32, i32* %6
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %7
%34 = sub i32 %33, 1
%35 = load i8*, i8** %4
%36 = zext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %4
br label %43
38: ; preds = %25
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = load i32*, i32** %5
%42 = call i32 @fputc(i8 signext %40, i32* %41)
br label %43
43: ; preds = %38, %29
br label %44
44: ; preds = %43, %22, %19
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
br label %10
47: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.ADrawTag = type { i32 }
@.str = [3 x i8] c"\\(\00"
@.str.1 = [3 x i8] c"\\)\00"
@.str.2 = [4 x i8] c"\\%o\00"
define void @writeEscaped(%struct.ADrawTag* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32* @getPsFile(%struct.ADrawTag* %0)
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 0
br i1 %7, label %37, label %8
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
br label %11
11: ; preds = %8, %32
%12 = phi i8 [ %6, %8 ], [ %35, %32 ]
%13 = phi i8* [ %1, %8 ], [ %34, %32 ]
%14 = sext i8 %12 to i32
switch i32 %14, label %19 [
i32 40, label %15
i32 41, label %17
]
15: ; preds = %11
%16 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %5)
br label %32
17: ; preds = %11
%18 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %5)
br label %32
19: ; preds = %11
%20 = call i32 @Utf8Decode(i8* %13, i32* %3, i32* %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = add i32 %25, -1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %13, i64 %27
br label %32
29: ; preds = %19
%30 = load i8, i8* %13
%31 = call i32 @fputc(i8 signext %30, i32* %5)
br label %32
32: ; preds = %22, %29, %17, %15
%33 = phi i8* [ %28, %22 ], [ %13, %29 ], [ %13, %17 ], [ %13, %15 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %11
37: ; preds = %32, %2
ret void
}