#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 parse_char_constant(char *, int *);
char *convert_escape_sequences(char *string) {
  char *read, *write;
  int actual_read, val;
  write = read = string;
  while (*read != 0) {
    if (*read == '\\') {
      val = parse_char_constant(read, &actual_read);
      if (val < 0) {
        *write++ = 'X';
      } else {
        *write++ = (char)val;
      }
      read += actual_read;
    } else {
      *write++ = *read++;
    }
  }
  *write = 0;
  return (string);
}


x86 assembly (clang, -O0):
<convert_escape_sequences>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cc <convert_escape_sequences+0xbc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11a5 <convert_escape_sequences+0x95>
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <parse_char_constant@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1179 <convert_escape_sequences+0x69>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x58,(%rax)
jmp    118f <convert_escape_sequences+0x7f>
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11c7 <convert_escape_sequences+0xb7>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1128 <convert_escape_sequences+0x18>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_escape_sequences>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xc(%rsp),%r15
mov    $0x58,%ebp
mov    %rdi,%r12
mov    %rdi,%rbx
jmp    1160 <convert_escape_sequences+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <parse_char_constant@plt>
test   %eax,%eax
cmovs  %ebp,%eax
mov    %al,(%r12)
movslq 0xc(%rsp),%rax
add    %rax,%rbx
add    $0x1,%r12
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1140 <convert_escape_sequences+0x30>
test   %al,%al
je     1179 <convert_escape_sequences+0x69>
add    $0x1,%rbx
mov    %al,(%r12)
add    $0x1,%r12
jmp    1160 <convert_escape_sequences+0x50>
movb   $0x0,(%r12)
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @convert_escape_sequences(i8* returned %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %18, %1
%5 = phi i8* [ %0, %1 ], [ %20, %18 ]
%6 = phi i8* [ %0, %1 ], [ %19, %18 ]
%7 = load i8, i8* %6
switch i8 %7, label %16 [
i8 0, label %21
i8 92, label %8
]
8: ; preds = %4
%9 = call i32 @parse_char_constant(i8* %6, i32* %2)
%10 = icmp slt i32 %9, 0
%11 = trunc i32 %9 to i8
%12 = select i1 %10, i8 88, i8 %11
store i8 %12, i8* %5
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %6, i64 %14
br label %18
16: ; preds = %4
%17 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %7, i8* %5
br label %18
18: ; preds = %16, %8
%19 = phi i8* [ %15, %8 ], [ %17, %16 ]
%20 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
21: ; preds = %4
store i8 0, i8* %5
ret i8* %0
}