#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 fcitx_utils_unescape_char(char);
int /*<<< orphan*/ memmove(char *, char *, size_t);
size_t strcspn(char *, char *);
__attribute__((visibility("default"))) char *
fcitx_utils_unescape_str_inplace(char *str) {
  char *dest = str;
  char *src = str;
  char *pos;
  size_t len;
  while ((len = strcspn(src, "\\")), *(pos = src + len)) {
    if (dest != src && len)
      memmove(dest, src, len);
    dest += len;
    src = pos + 1;
    *dest = fcitx_utils_unescape_char(*src);
    dest++;
    src++;
  }
  if (dest != src && len)
    memmove(dest, src, len);
  dest[len] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<fcitx_utils_unescape_str_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <strcspn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rax,%rdx
add    %rcx,%rdx
mov    %rdx,-0x20(%rbp)
cmpb   $0x0,(%rax,%rcx,1)
je     11ef <fcitx_utils_unescape_str_inplace+0xbf>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11a6 <fcitx_utils_unescape_str_inplace+0x76>
cmpq   $0x0,-0x28(%rbp)
je     11a6 <fcitx_utils_unescape_str_inplace+0x76>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x28(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <fcitx_utils_unescape_char@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114c <fcitx_utils_unescape_str_inplace+0x1c>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1219 <fcitx_utils_unescape_str_inplace+0xe9>
cmpq   $0x0,-0x28(%rbp)
je     1219 <fcitx_utils_unescape_str_inplace+0xe9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utils_unescape_str_inplace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xebb(%rip),%rsi
call   1030 <strcspn@plt>
mov    %rax,%r15
cmpb   $0x0,(%r14,%rax,1)
je     11d6 <fcitx_utils_unescape_str_inplace+0xa6>
mov    %r15,%rbp
add    %r14,%rbp
lea    0xe9b(%rip),%r12
mov    %r14,%rbx
mov    %r14,%r13
jmp    11a2 <fcitx_utils_unescape_str_inplace+0x72>
nopl   (%rax)
movsbl 0x1(%rbp),%edi
call   1040 <fcitx_utils_unescape_char@plt>
mov    %al,(%rbx,%r15,1)
add    %r15,%rbx
add    $0x1,%rbx
lea    0x2(%rbp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <strcspn@plt>
mov    %rax,%r15
cmpb   $0x0,0x2(%rbp,%rax,1)
lea    0x2(%rbp,%rax,1),%rbp
je     11bc <fcitx_utils_unescape_str_inplace+0x8c>
cmp    %r13,%rbx
je     1170 <fcitx_utils_unescape_str_inplace+0x40>
test   %r15,%r15
je     1170 <fcitx_utils_unescape_str_inplace+0x40>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <memmove@plt>
jmp    1170 <fcitx_utils_unescape_str_inplace+0x40>
cmp    %r13,%rbx
je     11d9 <fcitx_utils_unescape_str_inplace+0xa9>
test   %r15,%r15
je     11d9 <fcitx_utils_unescape_str_inplace+0xa9>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <memmove@plt>
jmp    11d9 <fcitx_utils_unescape_str_inplace+0xa9>
mov    %r14,%rbx
movb   $0x0,(%rbx,%r15,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\\\00"
define i8* @fcitx_utils_unescape_str_inplace(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %3
%8 = load i8*, i8** %2
store i8* %8, i8** %4
br label %9
9: ; preds = %29, %1
%10 = load i8*, i8** %4
%11 = call i64 @strcspn(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %11, i64* %6
%12 = load i8*, i8** %4
%13 = load i64, i64* %6
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8* %14, i8** %5
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %43
17: ; preds = %9
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = icmp ne i8* %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i64, i64* %6
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8*, i8** %3
%26 = load i8*, i8** %4
%27 = load i64, i64* %6
%28 = call i32 @memmove(i8* %25, i8* %26, i64 %27)
br label %29
29: ; preds = %24, %21, %17
%30 = load i64, i64* %6
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 %30
store i8* %32, i8** %3
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %4
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = call signext i8 @fcitx_utils_unescape_char(i8 signext %36)
%38 = load i8*, i8** %3
store i8 %37, i8* %38
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %3
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %4
br label %9
43: ; preds = %9
%44 = load i8*, i8** %3
%45 = load i8*, i8** %4
%46 = icmp ne i8* %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i64, i64* %6
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8*, i8** %3
%52 = load i8*, i8** %4
%53 = load i64, i64* %6
%54 = call i32 @memmove(i8* %51, i8* %52, i64 %53)
br label %55
55: ; preds = %50, %47, %43
%56 = load i8*, i8** %3
%57 = load i64, i64* %6
%58 = getelementptr inbounds i8, i8* %56, i64 %57
store i8 0, i8* %58
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@.str = [2 x i8] c"\\\00"
define i8* @fcitx_utils_unescape_str_inplace(i8* returned %0) {
%2 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds i8, i8* %0, i64 %2
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %1, %16
%7 = phi i8* [ %24, %16 ], [ %3, %1 ]
%8 = phi i64 [ %23, %16 ], [ %2, %1 ]
%9 = phi i8* [ %21, %16 ], [ %0, %1 ]
%10 = phi i8* [ %22, %16 ], [ %0, %1 ]
%11 = icmp ne i8* %9, %10
%12 = icmp ne i64 %8, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @memmove(i8* %9, i8* %10, i64 %8)
br label %16
16: ; preds = %14, %6
%17 = getelementptr inbounds i8, i8* %9, i64 %8
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = load i8, i8* %18
%20 = tail call signext i8 @fcitx_utils_unescape_char(i8 signext %19)
store i8 %20, i8* %17
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = getelementptr inbounds i8, i8* %7, i64 2
%23 = tail call i64 @strcspn(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %6
27: ; preds = %16
%28 = icmp ne i8* %21, %22
%29 = icmp ne i64 %23, 0
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 @memmove(i8* %21, i8* %22, i64 %23)
br label %33
33: ; preds = %1, %31, %27
%34 = phi i64 [ %23, %31 ], [ %23, %27 ], [ %2, %1 ]
%35 = phi i8* [ %21, %31 ], [ %21, %27 ], [ %0, %1 ]
%36 = getelementptr inbounds i8, i8* %35, i64 %34
store i8 0, i8* %36
ret i8* %0
}