#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 *, char);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void rcoxml_fput_escstr(FILE *fp, char *str) {
  while (*str) {
    switch (*str) {
    case '<':
      fputs("&lt;", fp);
      break;
    case '>':
      fputs("&gt;", fp);
      break;
    case '"':
      fputs("&quot;", fp);
      break;
    case '&':
      fputs("&amp;", fp);
      break;
    case '\n':
      fputc(*str, fp);
      break;
    default:
      if (*str < 32)
        fprintf(fp, "&#%d;", *str);
      else
        fputc(*str, fp);
    }
    str++;
  }
}


x86 assembly (clang, -O0):
<rcoxml_fput_escstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1268 <rcoxml_fput_escstr+0x138>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0xa,%eax
je     11fd <rcoxml_fput_escstr+0xcd>
jmp    1165 <rcoxml_fput_escstr+0x35>
mov    -0x14(%rbp),%eax
sub    $0x22,%eax
je     11d3 <rcoxml_fput_escstr+0xa3>
jmp    1176 <rcoxml_fput_escstr+0x46>
mov    -0x14(%rbp),%eax
sub    $0x26,%eax
je     11e8 <rcoxml_fput_escstr+0xb8>
jmp    1187 <rcoxml_fput_escstr+0x57>
mov    -0x14(%rbp),%eax
sub    $0x3c,%eax
je     11a9 <rcoxml_fput_escstr+0x79>
jmp    1198 <rcoxml_fput_escstr+0x68>
mov    -0x14(%rbp),%eax
sub    $0x3e,%eax
je     11be <rcoxml_fput_escstr+0x8e>
jmp    1214 <rcoxml_fput_escstr+0xe4>
mov    -0x8(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1030 <fputs@plt>
jmp    1257 <rcoxml_fput_escstr+0x127>
mov    -0x8(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1030 <fputs@plt>
jmp    1257 <rcoxml_fput_escstr+0x127>
mov    -0x8(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1030 <fputs@plt>
jmp    1257 <rcoxml_fput_escstr+0x127>
mov    -0x8(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1030 <fputs@plt>
jmp    1257 <rcoxml_fput_escstr+0x127>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1257 <rcoxml_fput_escstr+0x127>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    1240 <rcoxml_fput_escstr+0x110>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xde4(%rip),%rsi
movsbl (%rax),%edx
call   1050 <fprintf@plt>
jmp    1252 <rcoxml_fput_escstr+0x122>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1257 <rcoxml_fput_escstr+0x127>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1140 <rcoxml_fput_escstr+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rcoxml_fput_escstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%al
test   %al,%al
je     1210 <rcoxml_fput_escstr+0xe0>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rbx
lea    0xeaa(%rip),%r12
lea    0xf28(%rip),%r13
lea    0xf10(%rip),%rbp
lea    0xf0e(%rip),%r15
jmp    1191 <rcoxml_fput_escstr+0x61>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1050 <fwrite@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1210 <rcoxml_fput_escstr+0xe0>
movsbl %al,%edx
lea    -0x22(%rdx),%ecx
cmp    $0x1c,%ecx
ja     11c0 <rcoxml_fput_escstr+0x90>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    $0x6,%esi
mov    $0x1,%edx
lea    0xec8(%rip),%rdi
jmp    117a <rcoxml_fput_escstr+0x4a>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%edx
je     11e0 <rcoxml_fput_escstr+0xb0>
cmp    $0x1f,%al
jg     11e0 <rcoxml_fput_escstr+0xb0>
mov    %r14,%rdi
lea    0xeb8(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1182 <rcoxml_fput_escstr+0x52>
nopw   0x0(%rax,%rax,1)
mov    %edx,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    1182 <rcoxml_fput_escstr+0x52>
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r13,%rdi
jmp    117a <rcoxml_fput_escstr+0x4a>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rdi
jmp    117a <rcoxml_fput_escstr+0x4a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.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 = [6 x i8] c"&#%d;\00"
define void @rcoxml_fput_escstr(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
br label %5
5: ; preds = %46, %2
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %49
9: ; preds = %5
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %30 [
i32 60, label %13
i32 62, label %16
i32 34, label %19
i32 38, label %22
i32 10, label %25
]
13: ; preds = %9
%14 = load i32*, i32** %3
%15 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %14)
br label %46
16: ; preds = %9
%17 = load i32*, i32** %3
%18 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %17)
br label %46
19: ; preds = %9
%20 = load i32*, i32** %3
%21 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %20)
br label %46
22: ; preds = %9
%23 = load i32*, i32** %3
%24 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %23)
br label %46
25: ; preds = %9
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = load i32*, i32** %3
%29 = call i32 @fputc(i8 signext %27, i32* %28)
br label %46
30: ; preds = %9
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp slt i32 %33, 32
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i32*, i32** %3
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8 signext %38)
br label %45
40: ; preds = %30
%41 = load i8*, i8** %4
%42 = load i8, i8* %41
%43 = load i32*, i32** %3
%44 = call i32 @fputc(i8 signext %42, i32* %43)
br label %45
45: ; preds = %40, %35
br label %46
46: ; preds = %45, %25, %22, %19, %16, %13
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %4
br label %5
49: ; preds = %5
ret void
}

LLVM IR (-O2):
@.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 = [6 x i8] c"&#%d;\00"
define void @rcoxml_fput_escstr(i32* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %2, %25
%6 = phi i8 [ %27, %25 ], [ %3, %2 ]
%7 = phi i8* [ %26, %25 ], [ %1, %2 ]
%8 = sext i8 %6 to i32
switch i32 %8, label %19 [
i32 60, label %9
i32 62, label %11
i32 34, label %13
i32 38, label %15
i32 10, label %17
]
9: ; preds = %5
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %25
11: ; preds = %5
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %25
13: ; preds = %5
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 6, i64 1, i32* %0)
br label %25
15: ; preds = %5
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 5, i64 1, i32* %0)
br label %25
17: ; preds = %5
%18 = tail call i32 @fputc(i8 signext %6, i32* %0)
br label %25
19: ; preds = %5
%20 = icmp slt i8 %6, 32
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8 signext %6)
br label %25
23: ; preds = %19
%24 = tail call i32 @fputc(i8 signext %6, i32* %0)
br label %25
25: ; preds = %21, %23, %17, %15, %13, %11, %9
%26 = getelementptr inbounds i8, i8* %7, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %5
29: ; preds = %25, %2
ret void
}