#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 */
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
char *strchr(char *, char);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ unescape(char *);
char *unquote(char *buf) {
  char *p;
  unescape(buf);
  p = buf;
  while (p && *p && (p = strchr(p, '&'))) {
    if (strncmp(p, "&lt;", 4) == 0) {
      *p = '<';
      memmove(p + 1, p + 4, strlen(p + 4) + 1);
      continue;
    }
    if (strncmp(p, "&gt;", 4) == 0) {
      *p = '>';
      memmove(p + 1, p + 4, strlen(p + 4) + 1);
      continue;
    }
    if (strncmp(p, "&amp;", 5) == 0) {
      *p = '&';
      memmove(p + 1, p + 5, strlen(p + 5) + 1);
      continue;
    }
    p++;
  }
  return buf;
}


x86 assembly (clang, -O0):
<unquote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <unescape@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     11ae <unquote+0x5e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     11ae <unquote+0x5e>
mov    -0x10(%rbp),%rdi
mov    $0x26,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11be <unquote+0x6e>
jmp    12fb <unquote+0x1ab>
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1222 <unquote+0xd2>
mov    -0x10(%rbp),%rax
movb   $0x3c,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memmove@plt>
jmp    116d <unquote+0x1d>
mov    -0x10(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1286 <unquote+0x136>
mov    -0x10(%rbp),%rax
movb   $0x3e,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memmove@plt>
jmp    116d <unquote+0x1d>
mov    -0x10(%rbp),%rdi
lea    0xd79(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ea <unquote+0x19a>
mov    -0x10(%rbp),%rax
movb   $0x26,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memmove@plt>
jmp    116d <unquote+0x1d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    116d <unquote+0x1d>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unquote>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1060 <unescape@plt>
test   %r13,%r13
je     1265 <unquote+0x115>
cmpb   $0x0,0x0(%r13)
je     1265 <unquote+0x115>
lea    0xe82(%rip),%r14
lea    0xe80(%rip),%r15
mov    %r13,%rbx
jmp    11be <unquote+0x6e>
nopw   0x0(%rax,%rax,1)
movb   $0x3c,(%rbx)
lea    0x1(%rbx),%rbp
mov    %rbx,%r12
add    $0x4,%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <memmove@plt>
cmpb   $0x0,(%rbx)
je     1265 <unquote+0x115>
mov    %rbx,%rdi
mov    $0x26,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1265 <unquote+0x115>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1190 <unquote+0x40>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1230 <unquote+0xe0>
mov    %rbx,%rdi
lea    0xdff(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1240 <unquote+0xf0>
add    $0x1,%rbx
cmpb   $0x0,(%rbx)
jne    11be <unquote+0x6e>
jmp    1265 <unquote+0x115>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x3e,(%rbx)
lea    0x1(%rbx),%r12
mov    %rbx,%rbp
add    $0x4,%rbp
jmp    124e <unquote+0xfe>
movb   $0x26,(%rbx)
lea    0x1(%rbx),%r12
mov    %rbx,%rbp
add    $0x5,%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %rbp,%rsi
jmp    11b0 <unquote+0x60>
mov    %r13,%rax
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 = [6 x i8] c"&amp;\00"
define i8* @unquote(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @unescape(i8* %4)
%6 = load i8*, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %66, %55, %40, %25, %1
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 38)
store i8* %17, i8** %3
%18 = icmp ne i8* %17, null
br label %19
19: ; preds = %15, %10, %7
%20 = phi i1 [ false, %10 ], [ false, %7 ], [ %18, %15 ]
br i1 %20, label %21, label %69
21: ; preds = %19
%22 = load i8*, i8** %3
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i8*, i8** %3
store i8 60, i8* %26
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 4
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 4
%33 = call i64 @strlen(i8* %32)
%34 = add nsw i64 %33, 1
%35 = call i32 @memmove(i8* %28, i8* %30, i64 %34)
br label %7
36: ; preds = %21
%37 = load i8*, i8** %3
%38 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %36
%41 = load i8*, i8** %3
store i8 62, i8* %41
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i64 4
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 4
%48 = call i64 @strlen(i8* %47)
%49 = add nsw i64 %48, 1
%50 = call i32 @memmove(i8* %43, i8* %45, i64 %49)
br label %7
51: ; preds = %36
%52 = load i8*, i8** %3
%53 = call i64 @strncmp(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %51
%56 = load i8*, i8** %3
store i8 38, i8* %56
%57 = load i8*, i8** %3
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = load i8*, i8** %3
%60 = getelementptr inbounds i8, i8* %59, i64 5
%61 = load i8*, i8** %3
%62 = getelementptr inbounds i8, i8* %61, i64 5
%63 = call i64 @strlen(i8* %62)
%64 = add nsw i64 %63, 1
%65 = call i32 @memmove(i8* %58, i8* %60, i64 %64)
br label %7
66: ; preds = %51
%67 = load i8*, i8** %3
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %3
br label %7
69: ; preds = %19
%70 = load i8*, i8** %2
ret i8* %70
}

LLVM IR (-O2):
@.str = [5 x i8] c"&lt;\00"
@.str.1 = [5 x i8] c"&gt;\00"
@.str.2 = [6 x i8] c"&amp;\00"
define i8* @unquote(i8* returned %0) {
%2 = tail call i32 @unescape(i8* %0)
%3 = icmp eq i8* %0, null
br i1 %3, label %44, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %44, label %7
7: ; preds = %4, %20
%8 = phi i8* [ %21, %20 ], [ %0, %4 ]
%9 = tail call i8* @strchr(i8* %8, i8 signext 38)
%10 = icmp eq i8* %9, null
br i1 %10, label %44, label %11
11: ; preds = %7
%12 = tail call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
store i8 60, i8* %9
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = getelementptr inbounds i8, i8* %9, i64 4
%17 = tail call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = tail call i32 @memmove(i8* %15, i8* %16, i64 %18)
br label %20
20: ; preds = %14, %27, %36, %42
%21 = phi i8* [ %9, %14 ], [ %9, %27 ], [ %9, %36 ], [ %43, %42 ]
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %44, label %7
24: ; preds = %11
%25 = tail call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
store i8 62, i8* %9
%28 = getelementptr inbounds i8, i8* %9, i64 1
%29 = getelementptr inbounds i8, i8* %9, i64 4
%30 = tail call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = tail call i32 @memmove(i8* %28, i8* %29, i64 %31)
br label %20
33: ; preds = %24
%34 = tail call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
store i8 38, i8* %9
%37 = getelementptr inbounds i8, i8* %9, i64 1
%38 = getelementptr inbounds i8, i8* %9, i64 5
%39 = tail call i64 @strlen(i8* %38)
%40 = add nsw i64 %39, 1
%41 = tail call i32 @memmove(i8* %37, i8* %38, i64 %40)
br label %20
42: ; preds = %33
%43 = getelementptr inbounds i8, i8* %9, i64 1
br label %20
44: ; preds = %20, %7, %4, %1
ret i8* %0
}