#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 *gdbwire_strdup(char *);
size_t strlen(char *);
char *gdbwire_mi_unescape_cstring(char *str) {
  char *result;
  size_t r, s, length;
  result = gdbwire_strdup(str);
  length = strlen(str);
  for (r = 0, s = 1; s < length - 1; ++s) {
    if (str[s] == '\\') {
      switch (str[s + 1]) {
      case 'n':
        result[r++] = '\n';
        ++s;
        break;
      case 'r':
        result[r++] = '\r';
        ++s;
        break;
      case 't':
        result[r++] = '\t';
        ++s;
        break;
      case '"':
        result[r++] = '\"';
        ++s;
        break;
      case '\\':
        result[r++] = '\\';
        ++s;
        break;
      default:
        result[r++] = str[s];
        break;
      }
    } else {
      result[r++] = str[s];
    }
  }
  result[r] = 0;
  return result;
}


x86 assembly (clang, -O0):
<gdbwire_mi_unescape_cstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <gdbwire_strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1307 <gdbwire_mi_unescape_cstring+0x1e7>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    12d0 <gdbwire_mi_unescape_cstring+0x1b0>
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x22,%eax
je     125a <gdbwire_mi_unescape_cstring+0x13a>
jmp    119e <gdbwire_mi_unescape_cstring+0x7e>
mov    -0x2c(%rbp),%eax
sub    $0x5c,%eax
je     1282 <gdbwire_mi_unescape_cstring+0x162>
jmp    11af <gdbwire_mi_unescape_cstring+0x8f>
mov    -0x2c(%rbp),%eax
sub    $0x6e,%eax
je     11e2 <gdbwire_mi_unescape_cstring+0xc2>
jmp    11c0 <gdbwire_mi_unescape_cstring+0xa0>
mov    -0x2c(%rbp),%eax
sub    $0x72,%eax
je     120a <gdbwire_mi_unescape_cstring+0xea>
jmp    11d1 <gdbwire_mi_unescape_cstring+0xb1>
mov    -0x2c(%rbp),%eax
sub    $0x74,%eax
je     1232 <gdbwire_mi_unescape_cstring+0x112>
jmp    12aa <gdbwire_mi_unescape_cstring+0x18a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0xa,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12cb <gdbwire_mi_unescape_cstring+0x1ab>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0xd,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12cb <gdbwire_mi_unescape_cstring+0x1ab>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x9,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12cb <gdbwire_mi_unescape_cstring+0x1ab>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x22,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12cb <gdbwire_mi_unescape_cstring+0x1ab>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x5c,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12cb <gdbwire_mi_unescape_cstring+0x1ab>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    12f1 <gdbwire_mi_unescape_cstring+0x1d1>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    12f6 <gdbwire_mi_unescape_cstring+0x1d6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1156 <gdbwire_mi_unescape_cstring+0x36>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdbwire_mi_unescape_cstring>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <gdbwire_strdup@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
jb     11b3 <gdbwire_mi_unescape_cstring+0x93>
mov    $0x1,%edi
xor    %ecx,%ecx
lea    0xeb0(%rip),%r8
jmp    1177 <gdbwire_mi_unescape_cstring+0x57>
mov    $0x5c,%dl
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rdi,%rsi
mov    %dl,(%r14,%rcx,1)
add    $0x1,%rcx
add    $0x1,%rsi
mov    %rsi,%rdi
cmp    %rax,%rsi
jae    11b5 <gdbwire_mi_unescape_cstring+0x95>
movzbl (%r15,%rdi,1),%edx
cmp    $0x5c,%dl
jne    1160 <gdbwire_mi_unescape_cstring+0x40>
lea    0x1(%rdi),%rsi
movsbl 0x1(%r15,%rdi,1),%edx
lea    -0x5c(%rdx),%ebx
cmp    $0x18,%ebx
ja     11a2 <gdbwire_mi_unescape_cstring+0x82>
mov    $0xa,%dl
movslq (%r8,%rbx,4),%rbx
add    %r8,%rbx
jmp    *%rbx
mov    $0x5c,%dl
jmp    1163 <gdbwire_mi_unescape_cstring+0x43>
cmp    $0x22,%edx
jne    1152 <gdbwire_mi_unescape_cstring+0x32>
mov    $0x22,%dl
jmp    1163 <gdbwire_mi_unescape_cstring+0x43>
mov    $0xd,%dl
jmp    1163 <gdbwire_mi_unescape_cstring+0x43>
mov    $0x9,%dl
jmp    1163 <gdbwire_mi_unescape_cstring+0x43>
xor    %ecx,%ecx
movb   $0x0,(%r14,%rcx,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @gdbwire_mi_unescape_cstring(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @gdbwire_strdup(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
store i64 0, i64* %4
store i64 1, i64* %5
br label %11
11: ; preds = %85, %1
%12 = load i64, i64* %5
%13 = load i64, i64* %6
%14 = sub i64 %13, 1
%15 = icmp ult i64 %12, %14
br i1 %15, label %16, label %88
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i64, i64* %5
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 92
br i1 %22, label %23, label %75
23: ; preds = %16
%24 = load i8*, i8** %2
%25 = load i64, i64* %5
%26 = add i64 %25, 1
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
switch i32 %29, label %65 [
i32 110, label %30
i32 114, label %37
i32 116, label %44
i32 34, label %51
i32 92, label %58
]
30: ; preds = %23
%31 = load i8*, i8** %3
%32 = load i64, i64* %4
%33 = add i64 %32, 1
store i64 %33, i64* %4
%34 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 10, i8* %34
%35 = load i64, i64* %5
%36 = add i64 %35, 1
store i64 %36, i64* %5
br label %74
37: ; preds = %23
%38 = load i8*, i8** %3
%39 = load i64, i64* %4
%40 = add i64 %39, 1
store i64 %40, i64* %4
%41 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 13, i8* %41
%42 = load i64, i64* %5
%43 = add i64 %42, 1
store i64 %43, i64* %5
br label %74
44: ; preds = %23
%45 = load i8*, i8** %3
%46 = load i64, i64* %4
%47 = add i64 %46, 1
store i64 %47, i64* %4
%48 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 9, i8* %48
%49 = load i64, i64* %5
%50 = add i64 %49, 1
store i64 %50, i64* %5
br label %74
51: ; preds = %23
%52 = load i8*, i8** %3
%53 = load i64, i64* %4
%54 = add i64 %53, 1
store i64 %54, i64* %4
%55 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 34, i8* %55
%56 = load i64, i64* %5
%57 = add i64 %56, 1
store i64 %57, i64* %5
br label %74
58: ; preds = %23
%59 = load i8*, i8** %3
%60 = load i64, i64* %4
%61 = add i64 %60, 1
store i64 %61, i64* %4
%62 = getelementptr inbounds i8, i8* %59, i64 %60
store i8 92, i8* %62
%63 = load i64, i64* %5
%64 = add i64 %63, 1
store i64 %64, i64* %5
br label %74
65: ; preds = %23
%66 = load i8*, i8** %2
%67 = load i64, i64* %5
%68 = getelementptr inbounds i8, i8* %66, i64 %67
%69 = load i8, i8* %68
%70 = load i8*, i8** %3
%71 = load i64, i64* %4
%72 = add i64 %71, 1
store i64 %72, i64* %4
%73 = getelementptr inbounds i8, i8* %70, i64 %71
store i8 %69, i8* %73
br label %74
74: ; preds = %65, %58, %51, %44, %37, %30
br label %84
75: ; preds = %16
%76 = load i8*, i8** %2
%77 = load i64, i64* %5
%78 = getelementptr inbounds i8, i8* %76, i64 %77
%79 = load i8, i8* %78
%80 = load i8*, i8** %3
%81 = load i64, i64* %4
%82 = add i64 %81, 1
store i64 %82, i64* %4
%83 = getelementptr inbounds i8, i8* %80, i64 %81
store i8 %79, i8* %83
br label %84
84: ; preds = %75, %74
br label %85
85: ; preds = %84
%86 = load i64, i64* %5
%87 = add i64 %86, 1
store i64 %87, i64* %5
br label %11
88: ; preds = %11
%89 = load i8*, i8** %3
%90 = load i64, i64* %4
%91 = getelementptr inbounds i8, i8* %89, i64 %90
store i8 0, i8* %91
%92 = load i8*, i8** %3
ret i8* %92
}

LLVM IR (-O2):
define i8* @gdbwire_mi_unescape_cstring(i8* %0) {
%2 = tail call i8* @gdbwire_strdup(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, -1
%5 = icmp ugt i64 %4, 1
br i1 %5, label %6, label %29
6: ; preds = %1, %22
%7 = phi i64 [ %26, %22 ], [ 0, %1 ]
%8 = phi i64 [ %27, %22 ], [ 1, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 92
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = add nuw i64 %8, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %21 [
i32 110, label %22
i32 114, label %17
i32 116, label %18
i32 34, label %19
i32 92, label %20
]
17: ; preds = %12
br label %22
18: ; preds = %12
br label %22
19: ; preds = %12
br label %22
20: ; preds = %12
br label %22
21: ; preds = %12
br label %22
22: ; preds = %6, %12, %21, %20, %19, %18, %17
%23 = phi i8 [ 92, %21 ], [ 92, %20 ], [ 34, %19 ], [ 9, %18 ], [ 13, %17 ], [ 10, %12 ], [ %10, %6 ]
%24 = phi i64 [ %8, %21 ], [ %13, %20 ], [ %13, %19 ], [ %13, %18 ], [ %13, %17 ], [ %13, %12 ], [ %8, %6 ]
%25 = getelementptr inbounds i8, i8* %2, i64 %7
store i8 %23, i8* %25
%26 = add i64 %7, 1
%27 = add i64 %24, 1
%28 = icmp ult i64 %27, %4
br i1 %28, label %6, label %29
29: ; preds = %22, %1
%30 = phi i64 [ 0, %1 ], [ %26, %22 ]
%31 = getelementptr inbounds i8, i8* %2, i64 %30
store i8 0, i8* %31
ret i8* %2
}