#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_malloc(size_t);
char *fcitx_utils_realloc(char *, size_t);
char fcitx_utils_unescape_char(char const);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strcspn(char const *, char *);
int strlen(char const *);
__attribute__((visibility("default"))) char *
fcitx_utils_set_unescape_str(char *res, const char *str) {
  size_t len = strlen(str) + 1;
  if (res) {
    res = fcitx_utils_realloc(res, len);
  } else {
    res = fcitx_utils_malloc(len);
  }
  char *dest = res;
  const char *src = str;
  const char *pos;
  while ((len = strcspn(src, "\\")), *(pos = src + len)) {
    memcpy(dest, src, len);
    dest += len;
    src = pos + 1;
    *dest = fcitx_utils_unescape_char(*src);
    dest++;
    src++;
  }
  if (len)
    memcpy(dest, src, len);
  dest[len] = '\0';
  return res;
}


x86 assembly (clang, -O0):
<fcitx_utils_set_unescape_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a3 <fcitx_utils_set_unescape_str+0x43>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <fcitx_utils_realloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11b0 <fcitx_utils_set_unescape_str+0x50>
mov    -0x18(%rbp),%rdi
call   1070 <fcitx_utils_malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rax,%rdx
add    %rcx,%rdx
mov    %rdx,-0x30(%rbp)
cmpb   $0x0,(%rax,%rcx,1)
je     124a <fcitx_utils_set_unescape_str+0xea>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <fcitx_utils_unescape_char@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c0 <fcitx_utils_set_unescape_str+0x60>
cmpq   $0x0,-0x18(%rbp)
je     1266 <fcitx_utils_set_unescape_str+0x106>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utils_set_unescape_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rsi
test   %rbx,%rbx
je     118e <fcitx_utils_set_unescape_str+0x2e>
mov    %rbx,%rdi
call   1080 <fcitx_utils_realloc@plt>
jmp    1196 <fcitx_utils_set_unescape_str+0x36>
mov    %rsi,%rdi
call   1070 <fcitx_utils_malloc@plt>
mov    %rax,%r14
lea    0xe60(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcspn@plt>
mov    %rax,%r12
cmpb   $0x0,(%r15,%rax,1)
je     123a <fcitx_utils_set_unescape_str+0xda>
mov    %r12,%rbp
add    %r15,%rbp
lea    0xe3d(%rip),%r13
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
movsbl 0x1(%rbp),%edi
call   1050 <fcitx_utils_unescape_char@plt>
mov    %al,(%rbx,%r12,1)
add    %r12,%rbx
add    $0x1,%rbx
lea    0x2(%rbp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <strcspn@plt>
mov    %rax,%r12
cmpb   $0x0,0x2(%rbp,%rax,1)
lea    0x2(%rbp,%rax,1),%rbp
jne    11d0 <fcitx_utils_set_unescape_str+0x70>
test   %r12,%r12
je     1223 <fcitx_utils_set_unescape_str+0xc3>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
movb   $0x0,(%rbx,%r12,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rbx
test   %r12,%r12
jne    1215 <fcitx_utils_set_unescape_str+0xb5>
jmp    1223 <fcitx_utils_set_unescape_str+0xc3>

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

LLVM IR (-O2):
@.str = [2 x i8] c"\\\00"
define i8* @fcitx_utils_set_unescape_str(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 1
%5 = sext i32 %4 to i64
%6 = icmp eq i8* %0, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i8* @fcitx_utils_realloc(i8* %0, i64 %5)
br label %11
9: ; preds = %2
%10 = tail call i8* @fcitx_utils_malloc(i64 %5)
br label %11
11: ; preds = %9, %7
%12 = phi i8* [ %8, %7 ], [ %10, %9 ]
%13 = tail call i64 @strcspn(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %33, label %17
17: ; preds = %11, %17
%18 = phi i8* [ %30, %17 ], [ %14, %11 ]
%19 = phi i64 [ %29, %17 ], [ %13, %11 ]
%20 = phi i8* [ %28, %17 ], [ %1, %11 ]
%21 = phi i8* [ %27, %17 ], [ %12, %11 ]
%22 = tail call i32 @memcpy(i8* %21, i8* %20, i64 %19)
%23 = getelementptr inbounds i8, i8* %21, i64 %19
%24 = getelementptr inbounds i8, i8* %18, i64 1
%25 = load i8, i8* %24
%26 = tail call signext i8 @fcitx_utils_unescape_char(i8 signext %25)
store i8 %26, i8* %23
%27 = getelementptr inbounds i8, i8* %23, i64 1
%28 = getelementptr inbounds i8, i8* %18, i64 2
%29 = tail call i64 @strcspn(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %17
33: ; preds = %17, %11
%34 = phi i8* [ %12, %11 ], [ %27, %17 ]
%35 = phi i8* [ %1, %11 ], [ %28, %17 ]
%36 = phi i64 [ %13, %11 ], [ %29, %17 ]
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = tail call i32 @memcpy(i8* %34, i8* %35, i64 %36)
br label %40
40: ; preds = %38, %33
%41 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %41
ret i8* %12
}