#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 */
scalar_t__ get_esc_seq_val(char **);
int /*<<< orphan*/ memmove(char *, char *, unsigned int);
unsigned int strlen(char *);
void convert_string(char *s) {
  unsigned slen;
  char *src, *dest;
  slen = strlen(s);
  memmove(s, s + 1, slen - 1);
  s[slen - 2] = '\0';
  src = dest = s;
  while (*src != '\0') {
    if (*src == '\\') {
      ++src;
      *dest++ = (char)get_esc_seq_val(&src);
    } else {
      *dest++ = *src++;
    }
  }
  *dest = *src;
}


x86 assembly (clang, -O0):
<convert_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ef <convert_string+0xbf>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11c8 <convert_string+0x98>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <get_esc_seq_val@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11ea <convert_string+0xba>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    117b <convert_string+0x4b>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_string>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
lea    0x1(%rbx),%rsi
lea    -0x1(%r14),%edx
mov    %rbx,%rdi
call   1050 <memmove@plt>
add    $0xfffffffe,%r14d
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %rbx,%r15
jmp    118d <convert_string+0x5d>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
mov    %r14,%rdi
call   1040 <get_esc_seq_val@plt>
mov    0x8(%rsp),%rbx
mov    %al,(%r15)
add    $0x1,%r15
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1170 <convert_string+0x40>
test   %al,%al
je     11a9 <convert_string+0x79>
lea    0x1(%rbx),%rcx
mov    %rcx,0x8(%rsp)
movzbl (%rbx),%eax
mov    %rcx,%rbx
jmp    1186 <convert_string+0x56>
movb   $0x0,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @convert_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i32, i32* %3
%12 = sub i32 %11, 1
%13 = call i32 @memmove(i8* %8, i8* %10, i32 %12)
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sub i32 %15, 2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 0, i8* %18
%19 = load i8*, i8** %2
store i8* %19, i8** %5
store i8* %19, i8** %4
br label %20
20: ; preds = %43, %1
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %44
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 92
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
%33 = call i64 @get_esc_seq_val(i8** %4)
%34 = trunc i64 %33 to i8
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %5
store i8 %34, i8* %35
br label %43
37: ; preds = %25
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %4
%40 = load i8, i8* %38
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
store i8 %40, i8* %41
br label %43
43: ; preds = %37, %30
br label %20
44: ; preds = %20
%45 = load i8*, i8** %4
%46 = load i8, i8* %45
%47 = load i8*, i8** %5
store i8 %46, i8* %47
ret void
}

LLVM IR (-O2):
define void @convert_string(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = add i32 %4, -1
%7 = tail call i32 @memmove(i8* %0, i8* %5, i32 %6)
%8 = add i32 %4, -2
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %10
store i8* %0, i8** %2
br label %11
11: ; preds = %23, %1
%12 = phi i8* [ %0, %1 ], [ %24, %23 ]
%13 = phi i8* [ %0, %1 ], [ %26, %23 ]
%14 = load i8, i8* %12
switch i8 %14, label %20 [
i8 0, label %27
i8 92, label %15
]
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %16, i8** %2
%17 = call i64 @get_esc_seq_val(i8** %2)
%18 = trunc i64 %17 to i8
%19 = load i8*, i8** %2
br label %23
20: ; preds = %11
%21 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %21, i8** %2
%22 = load i8, i8* %12
br label %23
23: ; preds = %20, %15
%24 = phi i8* [ %21, %20 ], [ %19, %15 ]
%25 = phi i8 [ %22, %20 ], [ %18, %15 ]
%26 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %25, i8* %13
br label %11
27: ; preds = %11
store i8 0, i8* %13
ret void
}