#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_putchar(char);
int /*<<< orphan*/ ft_putstr(char *);
int /*<<< orphan*/ ft_strsub(char *, int, int);
int /*<<< orphan*/ print_quote(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int quote_it(char *cmd, int i) {
  int v;
  v = i;
  while (cmd[i] != '"' && cmd[i]) {
    if (cmd[i] == '\\')
      ++i;
    ++i;
  }
  if (cmd[i]) {
    ft_putstr("\033[1;33m");
    ++i;
    ft_putchar('"');
    print_quote(ft_strsub(cmd, v, (i - v)), 0);
  } else {
    ft_putstr("\033[1;31m");
    ft_putchar('"');
    write(1, &cmd[v], (i - v));
  }
  ft_putstr("\033[0m");
  return (i);
}


x86 assembly (clang, -O0):
<quote_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x22,%ecx
mov    %al,-0x11(%rbp)
je     1194 <quote_it+0x44>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11a4 <quote_it+0x54>
jmp    11d0 <quote_it+0x80>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    11c2 <quote_it+0x72>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <quote_it+0x15>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1221 <quote_it+0xd1>
lea    0xe17(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0x22,%edi
call   1060 <ft_putchar@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    -0x10(%rbp),%edx
call   1040 <ft_strsub@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1050 <print_quote@plt>
jmp    1252 <quote_it+0x102>
lea    0xde0(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    $0x22,%edi
call   1060 <ft_putchar@plt>
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    -0xc(%rbp),%edx
sub    -0x10(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
lea    0xdb7(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote_it>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%ebx
jmp    1166 <quote_it+0x16>
nopl   (%rax)
add    $0x1,%ebx
add    $0x1,%ebx
movslq %ebx,%rax
movzbl (%r14,%rax,1),%eax
cmp    $0x5c,%al
je     1160 <quote_it+0x10>
test   %al,%al
je     11ac <quote_it+0x5c>
cmp    $0x22,%al
jne    1163 <quote_it+0x13>
lea    0xe7f(%rip),%rdi
call   1070 <ft_putstr@plt>
add    $0x1,%ebx
mov    $0x22,%edi
call   1060 <ft_putchar@plt>
mov    %ebx,%edx
sub    %ebp,%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <ft_strsub@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1050 <print_quote@plt>
jmp    11d9 <quote_it+0x89>
lea    0xe55(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    $0x22,%edi
call   1060 <ft_putchar@plt>
movslq %ebp,%rax
add    %rax,%r14
mov    %ebx,%edx
sub    %ebp,%edx
mov    $0x1,%edi
mov    %r14,%rsi
call   1030 <write@plt>
lea    0xe30(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"\1B[1;33m\00"
@.str.1 = [8 x i8] c"\1B[1;31m\00"
@.str.2 = [5 x i8] c"\1B[0m\00"
define i32 @quote_it(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
store i32 %6, i32* %5
br label %7
7: ; preds = %36, %2
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 34
br i1 %14, label %15, label %23
15: ; preds = %7
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %15, %7
%24 = phi i1 [ false, %7 ], [ %22, %15 ]
br i1 %24, label %25, label %39
25: ; preds = %23
%26 = load i8*, i8** %3
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 92
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %36
36: ; preds = %33, %25
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %7
39: ; preds = %23
%40 = load i8*, i8** %3
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %58
46: ; preds = %39
%47 = call i32 @ft_putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
%50 = call i32 @ft_putchar(i8 signext 34)
%51 = load i8*, i8** %3
%52 = load i32, i32* %5
%53 = load i32, i32* %4
%54 = load i32, i32* %5
%55 = sub nsw i32 %53, %54
%56 = call i32 @ft_strsub(i8* %51, i32 %52, i32 %55)
%57 = call i32 @print_quote(i32 %56, i32 0)
br label %69
58: ; preds = %39
%59 = call i32 @ft_putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%60 = call i32 @ft_putchar(i8 signext 34)
%61 = load i8*, i8** %3
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i32, i32* %4
%66 = load i32, i32* %5
%67 = sub nsw i32 %65, %66
%68 = call i32 @write(i32 1, i8* %64, i32 %67)
br label %69
69: ; preds = %58, %46
%70 = call i32 @ft_putstr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [8 x i8] c"\1B[1;33m\00"
@.str.1 = [8 x i8] c"\1B[1;31m\00"
@.str.2 = [5 x i8] c"\1B[0m\00"
define i32 @quote_it(i8* %0, i32 %1) {
br label %3
3: ; preds = %10, %2
%4 = phi i32 [ %1, %2 ], [ %12, %10 ]
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %10 [
i8 92, label %8
i8 0, label %20
i8 34, label %13
]
8: ; preds = %3
%9 = add nsw i32 %4, 1
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ %9, %8 ], [ %4, %3 ]
%12 = add nsw i32 %11, 1
br label %3
13: ; preds = %3
%14 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = add nsw i32 %4, 1
%16 = tail call i32 @ft_putchar(i8 signext 34)
%17 = sub nsw i32 %15, %1
%18 = tail call i32 @ft_strsub(i8* %0, i32 %1, i32 %17)
%19 = tail call i32 @print_quote(i32 %18, i32 0)
br label %27
20: ; preds = %3
%21 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @ft_putchar(i8 signext 34)
%23 = sext i32 %1 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = sub nsw i32 %4, %1
%26 = tail call i32 @write(i32 1, i8* %24, i32 %25)
br label %27
27: ; preds = %20, %13
%28 = phi i32 [ %15, %13 ], [ %4, %20 ]
%29 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret i32 %28
}