#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 */

/* Variables and functions */
char *malloc(scalar_t__);
char *realloc(char *, int);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
char *xml_deserialize_(const char *str, int inplace) {
  char *out = inplace ? (char *)str : malloc(strlen(str) + 1);
  const char *s = str;
  char *o = out;
  for (; *s; ++s, ++o) {
    switch (*s) {
    case '&':
      if (strncmp(s, "&amp;", 5) == 0)
        *o = '&', s += 4;
      else if (strncmp(s, "&lt;", 4) == 0)
        *o = '<', s += 3;
      else if (strncmp(s, "&gt;", 4) == 0)
        *o = '>', s += 3;
      else if (strncmp(s, "&apos;", 6) == 0)
        *o = '\'', s += 5;
      else if (strncmp(s, "&quot;", 6) == 0)
        *o = '"', s += 5;
      else
        *o = *s;
      break;
    default:
      *o = *s;
      break;
    }
  }
  *o = 0;
  if (inplace)
    out = realloc((char *)str, o - out + 1);
  return out;
}


x86 assembly (clang, -O0):
<xml_deserialize_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1166 <xml_deserialize_+0x26>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    117f <xml_deserialize_+0x3f>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1318 <xml_deserialize_+0x1d8>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
sub    $0x26,%al
jne    12ea <xml_deserialize_+0x1aa>
jmp    11b7 <xml_deserialize_+0x77>
mov    -0x20(%rbp),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ed <xml_deserialize_+0xad>
mov    -0x28(%rbp),%rax
movb   $0x26,(%rax)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    12e5 <xml_deserialize_+0x1a5>
mov    -0x20(%rbp),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1223 <xml_deserialize_+0xe3>
mov    -0x28(%rbp),%rax
movb   $0x3c,(%rax)
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    12e0 <xml_deserialize_+0x1a0>
mov    -0x20(%rbp),%rdi
lea    0xddd(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1259 <xml_deserialize_+0x119>
mov    -0x28(%rbp),%rax
movb   $0x3e,(%rax)
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    12db <xml_deserialize_+0x19b>
mov    -0x20(%rbp),%rdi
lea    0xdac(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    128f <xml_deserialize_+0x14f>
mov    -0x28(%rbp),%rax
movb   $0x27,(%rax)
mov    -0x20(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
jmp    12d6 <xml_deserialize_+0x196>
mov    -0x20(%rbp),%rdi
lea    0xd7d(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12c5 <xml_deserialize_+0x185>
mov    -0x28(%rbp),%rax
movb   $0x22,(%rax)
mov    -0x20(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
jmp    12d1 <xml_deserialize_+0x191>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
jmp    12d6 <xml_deserialize_+0x196>
jmp    12db <xml_deserialize_+0x19b>
jmp    12e0 <xml_deserialize_+0x1a0>
jmp    12e5 <xml_deserialize_+0x1a5>
jmp    12f6 <xml_deserialize_+0x1b6>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
jmp    12fb <xml_deserialize_+0x1bb>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1197 <xml_deserialize_+0x57>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
je     1347 <xml_deserialize_+0x207>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xml_deserialize_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    %rdi,%rbx
mov    %esi,0xc(%rsp)
test   %esi,%esi
jne    1170 <xml_deserialize_+0x30>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe87(%rip),%r12
lea    0xe86(%rip),%r13
lea    0xe84(%rip),%r14
mov    %r15,0x10(%rsp)
jmp    11a8 <xml_deserialize_+0x68>
movb   $0x26,(%rbx,%rbp,1)
add    $0x4,%r15
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0x1,%rbp
movzbl (%r15),%eax
cmp    $0x26,%al
je     11c0 <xml_deserialize_+0x80>
test   %al,%al
je     1266 <xml_deserialize_+0x126>
mov    %al,(%rbx,%rbp,1)
jmp    11a0 <xml_deserialize_+0x60>
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     118e <xml_deserialize_+0x4e>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1232 <xml_deserialize_+0xf2>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     123f <xml_deserialize_+0xff>
mov    %r15,%rdi
lea    0xe0a(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     124c <xml_deserialize_+0x10c>
mov    %r15,%rdi
lea    0xdf9(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1259 <xml_deserialize_+0x119>
movzbl (%r15),%eax
jmp    11b8 <xml_deserialize_+0x78>
movb   $0x3c,(%rbx,%rbp,1)
add    $0x3,%r15
jmp    11a0 <xml_deserialize_+0x60>
movb   $0x3e,(%rbx,%rbp,1)
add    $0x3,%r15
jmp    11a0 <xml_deserialize_+0x60>
movb   $0x27,(%rbx,%rbp,1)
add    $0x5,%r15
jmp    11a0 <xml_deserialize_+0x60>
movb   $0x22,(%rbx,%rbp,1)
add    $0x5,%r15
jmp    11a0 <xml_deserialize_+0x60>
movb   $0x0,(%rbx,%rbp,1)
cmpl   $0x0,0xc(%rsp)
je     128e <xml_deserialize_+0x14e>
add    $0x1,%ebp
mov    0x10(%rsp),%rdi
mov    %ebp,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <realloc@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"&amp;\00"
@.str.1 = [5 x i8] c"&lt;\00"
@.str.2 = [5 x i8] c"&gt;\00"
@.str.3 = [7 x i8] c"&apos;\00"
@.str.4 = [7 x i8] c"&quot;\00"
define i8* @xml_deserialize_(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i8*, i8** %3
br label %17
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i8* @malloc(i64 %15)
br label %17
17: ; preds = %12, %10
%18 = phi i8* [ %11, %10 ], [ %16, %12 ]
store i8* %18, i8** %5
%19 = load i8*, i8** %3
store i8* %19, i8** %6
%20 = load i8*, i8** %5
store i8* %20, i8** %7
br label %21
21: ; preds = %83, %17
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %88
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
switch i32 %28, label %78 [
i32 38, label %29
]
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = call i32 @strncmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i8*, i8** %7
store i8 38, i8* %34
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 4
store i8* %36, i8** %6
br label %77
37: ; preds = %29
%38 = load i8*, i8** %6
%39 = call i32 @strncmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i8*, i8** %7
store i8 60, i8* %42
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 3
store i8* %44, i8** %6
br label %76
45: ; preds = %37
%46 = load i8*, i8** %6
%47 = call i32 @strncmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i8*, i8** %7
store i8 62, i8* %50
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i64 3
store i8* %52, i8** %6
br label %75
53: ; preds = %45
%54 = load i8*, i8** %6
%55 = call i32 @strncmp(i8* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i8*, i8** %7
store i8 39, i8* %58
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 5
store i8* %60, i8** %6
br label %74
61: ; preds = %53
%62 = load i8*, i8** %6
%63 = call i32 @strncmp(i8* %62, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = load i8*, i8** %7
store i8 34, i8* %66
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i64 5
store i8* %68, i8** %6
br label %73
69: ; preds = %61
%70 = load i8*, i8** %6
%71 = load i8, i8* %70
%72 = load i8*, i8** %7
store i8 %71, i8* %72
br label %73
73: ; preds = %69, %65
br label %74
74: ; preds = %73, %57
br label %75
75: ; preds = %74, %49
br label %76
76: ; preds = %75, %41
br label %77
77: ; preds = %76, %33
br label %82
78: ; preds = %25
%79 = load i8*, i8** %6
%80 = load i8, i8* %79
%81 = load i8*, i8** %7
store i8 %80, i8* %81
br label %82
82: ; preds = %78, %77
br label %83
83: ; preds = %82
%84 = load i8*, i8** %6
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %6
%86 = load i8*, i8** %7
%87 = getelementptr inbounds i8, i8* %86, i32 1
store i8* %87, i8** %7
br label %21
88: ; preds = %21
%89 = load i8*, i8** %7
store i8 0, i8* %89
%90 = load i32, i32* %4
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %102
92: ; preds = %88
%93 = load i8*, i8** %3
%94 = load i8*, i8** %7
%95 = load i8*, i8** %5
%96 = ptrtoint i8* %94 to i64
%97 = ptrtoint i8* %95 to i64
%98 = sub i64 %96, %97
%99 = add nsw i64 %98, 1
%100 = trunc i64 %99 to i32
%101 = call i8* @realloc(i8* %93, i32 %100)
store i8* %101, i8** %5
br label %102
102: ; preds = %92, %88
%103 = load i8*, i8** %5
ret i8* %103
}

LLVM IR (-O2):
@.str = [6 x i8] c"&amp;\00"
@.str.1 = [5 x i8] c"&lt;\00"
@.str.2 = [5 x i8] c"&gt;\00"
@.str.3 = [7 x i8] c"&apos;\00"
@.str.4 = [7 x i8] c"&quot;\00"
define i8* @xml_deserialize_(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = tail call i8* @malloc(i64 %6)
br label %8
8: ; preds = %2, %4
%9 = phi i8* [ %7, %4 ], [ %0, %2 ]
br label %10
10: ; preds = %42, %8
%11 = phi i8* [ %0, %8 ], [ %44, %42 ]
%12 = phi i8* [ %9, %8 ], [ %45, %42 ]
%13 = load i8, i8* %11
switch i8 %13, label %41 [
i8 0, label %46
i8 38, label %14
]
14: ; preds = %10
%15 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
store i8 38, i8* %12
%18 = getelementptr inbounds i8, i8* %11, i64 4
br label %42
19: ; preds = %14
%20 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
store i8 60, i8* %12
%23 = getelementptr inbounds i8, i8* %11, i64 3
br label %42
24: ; preds = %19
%25 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
store i8 62, i8* %12
%28 = getelementptr inbounds i8, i8* %11, i64 3
br label %42
29: ; preds = %24
%30 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
store i8 39, i8* %12
%33 = getelementptr inbounds i8, i8* %11, i64 5
br label %42
34: ; preds = %29
%35 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
store i8 34, i8* %12
%38 = getelementptr inbounds i8, i8* %11, i64 5
br label %42
39: ; preds = %34
%40 = load i8, i8* %11
store i8 %40, i8* %12
br label %42
41: ; preds = %10
store i8 %13, i8* %12
br label %42
42: ; preds = %41, %22, %32, %39, %37, %27, %17
%43 = phi i8* [ %18, %17 ], [ %23, %22 ], [ %28, %27 ], [ %33, %32 ], [ %38, %37 ], [ %11, %39 ], [ %11, %41 ]
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = getelementptr inbounds i8, i8* %12, i64 1
br label %10
46: ; preds = %10
store i8 0, i8* %12
br i1 %3, label %54, label %47
47: ; preds = %46
%48 = ptrtoint i8* %12 to i64
%49 = ptrtoint i8* %9 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i32
%52 = add i32 %51, 1
%53 = tail call i8* @realloc(i8* %0, i32 %52)
br label %54
54: ; preds = %47, %46
%55 = phi i8* [ %53, %47 ], [ %9, %46 ]
ret i8* %55
}