#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*/ *getSvgFile(struct ADrawTag *);
void writeEscaped(struct ADrawTag *ctx, const char *string) {
  FILE *f = getSvgFile(ctx);
  while (*string != '\0') {
    unsigned int code, bytes;
    switch (*string) {
    case '<':
      fprintf(f, "&lt;");
      break;
    case '>':
      fprintf(f, "&gt;");
      break;
    case '"':
      fprintf(f, "&quot;");
      break;
    case '&':
      fprintf(f, "&amp;");
      break;
    default:
      if (Utf8Decode(string, &code, &bytes)) {
        fprintf(f, "&#x%x;", 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   1040 <getSvgFile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1265 <writeEscaped+0x125>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x1c,%eax
ja     11f6 <writeEscaped+0xb6>
mov    -0x28(%rbp),%rax
lea    0xe6f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
lea    0xecf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1254 <writeEscaped+0x114>
mov    -0x18(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1254 <writeEscaped+0x114>
mov    -0x18(%rbp),%rdi
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1254 <writeEscaped+0x114>
mov    -0x18(%rbp),%rdi
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1254 <writeEscaped+0x114>
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <Utf8Decode@plt>
cmp    $0x0,%eax
je     123d <writeEscaped+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    124f <writeEscaped+0x10f>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1254 <writeEscaped+0x114>
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   1040 <getSvgFile@plt>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     1262 <writeEscaped+0x112>
lea    0xe89(%rip),%rbp
lea    0xf07(%rip),%r13
lea    0xeef(%rip),%r15
lea    0xeed(%rip),%r12
jmp    11b5 <writeEscaped+0x65>
xchg   %ax,%ax
mov    $0x4,%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     1262 <writeEscaped+0x112>
movsbl %al,%eax
add    $0xffffffde,%eax
cmp    $0x1c,%eax
ja     11e0 <writeEscaped+0x90>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    $0x6,%esi
mov    $0x1,%edx
lea    0xea3(%rip),%rdi
jmp    119d <writeEscaped+0x4d>
nopl   (%rax)
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <Utf8Decode@plt>
test   %eax,%eax
je     1252 <writeEscaped+0x102>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
lea    0xe89(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rsp),%eax
add    $0xffffffff,%eax
add    %rax,%rbx
jmp    11a5 <writeEscaped+0x55>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r13,%rdi
jmp    119d <writeEscaped+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    119d <writeEscaped+0x4d>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1050 <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 = [5 x i8] c"&lt;\00"
@.str.1 = [5 x i8] c"&gt;\00"
@.str.2 = [7 x i8] c"&quot;\00"
@.str.3 = [6 x i8] c"&amp;\00"
@.str.4 = [7 x i8] c"&#x%x;\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* @getSvgFile(%struct.ADrawTag* %8)
store i32* %9, i32** %5
br label %10
10: ; preds = %50, %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 %53
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %31 [
i32 60, label %19
i32 62, label %22
i32 34, label %25
i32 38, label %28
]
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %50
22: ; preds = %15
%23 = load i32*, i32** %5
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %50
25: ; preds = %15
%26 = load i32*, i32** %5
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %50
28: ; preds = %15
%29 = load i32*, i32** %5
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %50
31: ; preds = %15
%32 = load i8*, i8** %4
%33 = call i32 @Utf8Decode(i8* %32, i32* %6, i32* %7)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i32*, i32** %5
%37 = load i32, i32* %6
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %7
%40 = sub i32 %39, 1
%41 = load i8*, i8** %4
%42 = zext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %4
br label %49
44: ; preds = %31
%45 = load i8*, i8** %4
%46 = load i8, i8* %45
%47 = load i32*, i32** %5
%48 = call i32 @fputc(i8 signext %46, i32* %47)
br label %49
49: ; preds = %44, %35
br label %50
50: ; preds = %49, %28, %25, %22, %19
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %4
br label %10
53: ; preds = %10
ret void
}

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