#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 pool {
  int dummy;
};

/* Variables and functions */
int pool_append_char(struct pool *, int, char const);
int pool_append_str(struct pool *, int, char *);
int /*<<< orphan*/ pool_restore(struct pool *, int);
int pool_state(struct pool *);
int xml_append_esc(struct pool *pool, int h, const char *str) {
  int mark;
  if (!str)
    return h;
  mark = pool_state(pool);
  for (; *str; str++) {
    switch (*str) {
    case '\'':
      h = pool_append_str(pool, h, "&apos;");
      break;
    case '"':
      h = pool_append_str(pool, h, "&quot;");
      break;
    case '&':
      h = pool_append_str(pool, h, "&amp;");
      break;
    case '<':
      h = pool_append_str(pool, h, "&lt;");
      break;
    case '>':
      h = pool_append_str(pool, h, "&gt;");
      break;
    default:
      h = pool_append_char(pool, h, *str);
    }
    if (h == (-1)) {
      pool_restore(pool, mark);
      break;
    }
  }
  return h;
}


x86 assembly (clang, -O0):
<xml_append_esc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1169 <xml_append_esc+0x29>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <xml_append_esc+0x143>
mov    -0x10(%rbp),%rdi
call   1030 <pool_state@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     127d <xml_append_esc+0x13d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x1c,%eax
ja     1236 <xml_append_esc+0xf6>
mov    -0x30(%rbp),%rax
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xeb7(%rip),%rdx
call   1060 <pool_append_str@plt>
mov    %eax,-0x14(%rbp)
jmp    124c <xml_append_esc+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xea3(%rip),%rdx
call   1060 <pool_append_str@plt>
mov    %eax,-0x14(%rbp)
jmp    124c <xml_append_esc+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe8f(%rip),%rdx
call   1060 <pool_append_str@plt>
mov    %eax,-0x14(%rbp)
jmp    124c <xml_append_esc+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe7a(%rip),%rdx
call   1060 <pool_append_str@plt>
mov    %eax,-0x14(%rbp)
jmp    124c <xml_append_esc+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe64(%rip),%rdx
call   1060 <pool_append_str@plt>
mov    %eax,-0x14(%rbp)
jmp    124c <xml_append_esc+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
movsbl (%rax),%edx
call   1040 <pool_append_char@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1267 <xml_append_esc+0x127>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <pool_restore@plt>
jmp    127d <xml_append_esc+0x13d>
jmp    126c <xml_append_esc+0x12c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1175 <xml_append_esc+0x35>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xml_append_esc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
test   %rdx,%rdx
je     121d <xml_append_esc+0xdd>
mov    %rdx,%rbx
mov    %rdi,%r14
call   1030 <pool_state@plt>
mov    %eax,%r15d
mov    (%rbx),%al
test   %al,%al
je     121d <xml_append_esc+0xdd>
add    $0x1,%rbx
lea    0xe87(%rip),%r13
lea    0xf0d(%rip),%r12
movsbl %al,%edx
lea    -0x22(%rdx),%eax
cmp    $0x1c,%eax
ja     11a3 <xml_append_esc+0x63>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xeda(%rip),%rdx
jmp    11f0 <xml_append_esc+0xb0>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <pool_append_char@plt>
jmp    11f5 <xml_append_esc+0xb5>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xec7(%rip),%rdx
jmp    11f0 <xml_append_esc+0xb0>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xeab(%rip),%rdx
jmp    11f0 <xml_append_esc+0xb0>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xeb1(%rip),%rdx
jmp    11f0 <xml_append_esc+0xb0>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1060 <pool_append_str@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     120d <xml_append_esc+0xcd>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <xml_append_esc+0x40>
jmp    121d <xml_append_esc+0xdd>
mov    %r14,%rdi
mov    %r15d,%esi
call   1050 <pool_restore@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pool = type { i32 }
@.str = [7 x i8] c"&apos;\00"
@.str.1 = [7 x i8] c"&quot;\00"
@.str.2 = [6 x i8] c"&amp;\00"
@.str.3 = [5 x i8] c"&lt;\00"
@.str.4 = [5 x i8] c"&gt;\00"
define i32 @xml_append_esc(%struct.pool* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.pool*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store %struct.pool* %0, %struct.pool** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = load i32, i32* %6
store i32 %12, i32* %4
br label %63
13: ; preds = %3
%14 = load %struct.pool*, %struct.pool** %5
%15 = call i32 @pool_state(%struct.pool* %14)
store i32 %15, i32* %8
br label %16
16: ; preds = %58, %13
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %61
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %44 [
i32 39, label %24
i32 34, label %28
i32 38, label %32
i32 60, label %36
i32 62, label %40
]
24: ; preds = %20
%25 = load %struct.pool*, %struct.pool** %5
%26 = load i32, i32* %6
%27 = call i32 @pool_append_str(%struct.pool* %25, i32 %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %27, i32* %6
br label %50
28: ; preds = %20
%29 = load %struct.pool*, %struct.pool** %5
%30 = load i32, i32* %6
%31 = call i32 @pool_append_str(%struct.pool* %29, i32 %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %31, i32* %6
br label %50
32: ; preds = %20
%33 = load %struct.pool*, %struct.pool** %5
%34 = load i32, i32* %6
%35 = call i32 @pool_append_str(%struct.pool* %33, i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 %35, i32* %6
br label %50
36: ; preds = %20
%37 = load %struct.pool*, %struct.pool** %5
%38 = load i32, i32* %6
%39 = call i32 @pool_append_str(%struct.pool* %37, i32 %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 %39, i32* %6
br label %50
40: ; preds = %20
%41 = load %struct.pool*, %struct.pool** %5
%42 = load i32, i32* %6
%43 = call i32 @pool_append_str(%struct.pool* %41, i32 %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 %43, i32* %6
br label %50
44: ; preds = %20
%45 = load %struct.pool*, %struct.pool** %5
%46 = load i32, i32* %6
%47 = load i8*, i8** %7
%48 = load i8, i8* %47
%49 = call i32 @pool_append_char(%struct.pool* %45, i32 %46, i8 signext %48)
store i32 %49, i32* %6
br label %50
50: ; preds = %44, %40, %36, %32, %28, %24
%51 = load i32, i32* %6
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = load %struct.pool*, %struct.pool** %5
%55 = load i32, i32* %8
%56 = call i32 @pool_restore(%struct.pool* %54, i32 %55)
br label %61
57: ; preds = %50
br label %58
58: ; preds = %57
%59 = load i8*, i8** %7
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %7
br label %16
61: ; preds = %53, %16
%62 = load i32, i32* %6
store i32 %62, i32* %4
br label %63
63: ; preds = %61, %11
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
%struct.pool = type { i32 }
@.str = [7 x i8] c"&apos;\00"
@.str.1 = [7 x i8] c"&quot;\00"
@.str.2 = [6 x i8] c"&amp;\00"
@.str.3 = [5 x i8] c"&lt;\00"
@.str.4 = [5 x i8] c"&gt;\00"
define i32 @xml_append_esc(%struct.pool* %0, i32 %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %35, label %5
5: ; preds = %3
%6 = tail call i32 @pool_state(%struct.pool* %0)
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %35, label %12
9: ; preds = %29
%10 = load i8, i8* %32
%11 = icmp eq i8 %10, 0
br i1 %11, label %35, label %12
12: ; preds = %5, %9
%13 = phi i8 [ %10, %9 ], [ %7, %5 ]
%14 = phi i8* [ %32, %9 ], [ %2, %5 ]
%15 = phi i32 [ %30, %9 ], [ %1, %5 ]
%16 = sext i8 %13 to i32
switch i32 %16, label %27 [
i32 39, label %17
i32 34, label %19
i32 38, label %21
i32 60, label %23
i32 62, label %25
]
17: ; preds = %12
%18 = tail call i32 @pool_append_str(%struct.pool* %0, i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %29
19: ; preds = %12
%20 = tail call i32 @pool_append_str(%struct.pool* %0, i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %29
21: ; preds = %12
%22 = tail call i32 @pool_append_str(%struct.pool* %0, i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %29
23: ; preds = %12
%24 = tail call i32 @pool_append_str(%struct.pool* %0, i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %29
25: ; preds = %12
%26 = tail call i32 @pool_append_str(%struct.pool* %0, i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %29
27: ; preds = %12
%28 = tail call i32 @pool_append_char(%struct.pool* %0, i32 %15, i8 signext %13)
br label %29
29: ; preds = %27, %25, %23, %21, %19, %17
%30 = phi i32 [ %28, %27 ], [ %26, %25 ], [ %24, %23 ], [ %22, %21 ], [ %20, %19 ], [ %18, %17 ]
%31 = icmp eq i32 %30, -1
%32 = getelementptr inbounds i8, i8* %14, i64 1
br i1 %31, label %33, label %9
33: ; preds = %29
%34 = tail call i32 @pool_restore(%struct.pool* %0, i32 %6)
br label %35
35: ; preds = %9, %5, %33, %3
%36 = phi i32 [ %1, %3 ], [ -1, %33 ], [ %1, %5 ], [ %30, %9 ]
ret i32 %36
}