#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 /*<<< orphan*/ ft_memmove(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ ft_strlen(char *);
char *ft_strnew(int /*<<< orphan*/);
char *ft_echap_cmd(char *cmd) {
  char *echap;
  size_t len;
  echap = ft_strnew(ft_strlen(cmd));
  len = -1;
  while (cmd[++len]) {
    if (cmd[len] == '\\' && cmd[len + 1]) {
      echap[len] = 1;
      ft_memmove(cmd + len, cmd + len + 1, ft_strlen(cmd + len));
    } else
      echap[len] = -1;
  }
  echap[len] = '\0';
  return (echap);
}


x86 assembly (clang, -O0):
<ft_echap_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%edi
call   1040 <ft_strnew@plt>
mov    %rax,-0x10(%rbp)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
cmpb   $0x0,0x1(%rax,%rcx,1)
je     11fb <ft_echap_cmd+0xcb>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    11ea <ft_echap_cmd+0xba>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ea <ft_echap_cmd+0xba>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x18(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1050 <ft_memmove@plt>
jmp    11f6 <ft_echap_cmd+0xc6>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
jmp    1158 <ft_echap_cmd+0x28>
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):
<ft_echap_cmd>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <ft_strlen@plt>
mov    %eax,%edi
call   1040 <ft_strnew@plt>
mov    %rax,%r14
add    $0x1,%rbx
mov    %rax,%r12
jmp    118b <ft_echap_cmd+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x0,(%rbx)
je     1197 <ft_echap_cmd+0x67>
lea    -0x1(%rbx),%r15
movb   $0x1,(%r12)
mov    %r15,%rdi
call   1030 <ft_strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <ft_memmove@plt>
add    $0x1,%rbx
add    $0x1,%r12
movzbl -0x1(%rbx),%eax
cmp    $0x5c,%al
je     1160 <ft_echap_cmd+0x30>
test   %al,%al
je     119e <ft_echap_cmd+0x6e>
movb   $0xff,(%r12)
jmp    1183 <ft_echap_cmd+0x53>
movb   $0x0,(%r12)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @ft_echap_cmd(i8* %0) {
%2 = tail call i32 @ft_strlen(i8* %0)
%3 = tail call i8* @ft_strnew(i32 %2)
br label %4
4: ; preds = %21, %1
%5 = phi i64 [ -1, %1 ], [ %6, %21 ]
%6 = add i64 %5, 1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %19 [
i8 0, label %22
i8 92, label %9
]
9: ; preds = %4
%10 = add i64 %5, 2
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %3, i64 %6
store i8 1, i8* %15
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = tail call i32 @ft_strlen(i8* %7)
%18 = tail call i32 @ft_memmove(i8* %7, i8* %16, i32 %17)
br label %21
19: ; preds = %4, %9
%20 = getelementptr inbounds i8, i8* %3, i64 %6
store i8 -1, i8* %20
br label %21
21: ; preds = %19, %14
br label %4
22: ; preds = %4
%23 = getelementptr inbounds i8, i8* %3, i64 %6
store i8 0, i8* %23
ret i8* %3
}