#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 printColoredVar(char const *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int printColoredDoubleString(const char *linbuff, int numChars) {
  if (*linbuff != '"')
    return 0;
  write(1, "\e\"\x02", 3);
  printf("\"");
  linbuff++;
  numChars--;
  int result = 1;
  while (numChars) {
    int count;
    if ((count = printColoredVar(linbuff, numChars)) != 0) {
      numChars -= count;
      linbuff += count;
      result += count;
    } else {
      char c = *linbuff;
      write(1, "\e\"\x02", 3);
      printf("%c", c);
      numChars--;
      result++;
      linbuff++;
      if (c == '"')
        break;
    };
  };
  write(1, "\e\"\x07", 3);
  return result;
}


x86 assembly (clang, -O0):
<printColoredDoubleString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     115b <printColoredDoubleString+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    126e <printColoredDoubleString+0x13e>
mov    $0x1,%edi
lea    0xe99(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1252 <printColoredDoubleString+0x122>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <printColoredVar@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11e7 <printColoredDoubleString+0xb7>
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    124d <printColoredDoubleString+0x11d>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    $0x1,%edi
lea    0xe04(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
movsbl -0x1d(%rbp),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x22,%eax
jne    1248 <printColoredDoubleString+0x118>
jmp    1252 <printColoredDoubleString+0x122>
jmp    124d <printColoredDoubleString+0x11d>
jmp    119b <printColoredDoubleString+0x6b>
mov    $0x1,%edi
lea    0xdab(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printColoredDoubleString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
cmpb   $0x22,(%rdi)
jne    11f6 <printColoredDoubleString+0xc6>
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeb0(%rip),%rsi
mov    $0x1,%r14d
mov    $0x1,%edi
mov    $0x3,%edx
call   1040 <write@plt>
mov    $0x22,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
je     11e0 <printColoredDoubleString+0xb0>
add    $0x1,%rbx
mov    $0x1,%r14d
lea    0xe7b(%rip),%r15
jmp    119f <printColoredDoubleString+0x6f>
nopw   0x0(%rax,%rax,1)
sub    %eax,%ebp
movslq %eax,%rcx
add    %rcx,%rbx
add    %eax,%r14d
test   %ebp,%ebp
je     11e0 <printColoredDoubleString+0xb0>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <printColoredVar@plt>
test   %eax,%eax
jne    1190 <printColoredDoubleString+0x60>
movsbl (%rbx),%r12d
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %r12d,%edi
call   1030 <putchar@plt>
add    $0x1,%r14d
cmp    $0x22,%r12d
je     11e0 <printColoredDoubleString+0xb0>
add    $0xffffffff,%ebp
add    $0x1,%rbx
test   %ebp,%ebp
jne    119f <printColoredDoubleString+0x6f>
lea    0xe1d(%rip),%rsi
mov    $0x1,%edi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"\1B\22\02\00"
@.str.3 = [4 x i8] c"\1B\22\07\00"
define i32 @printColoredDoubleString(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 34
br i1 %4, label %5, label %40
5: ; preds = %2
%6 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%7 = tail call i32 @putchar(i32 34)
%8 = add nsw i32 %1, -1
%9 = icmp eq i32 %8, 0
br i1 %9, label %37, label %10
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %0, i64 1
br label %12
12: ; preds = %10, %32
%13 = phi i8* [ %11, %10 ], [ %35, %32 ]
%14 = phi i32 [ 1, %10 ], [ %34, %32 ]
%15 = phi i32 [ %8, %10 ], [ %33, %32 ]
%16 = tail call i32 @printColoredVar(i8* %13, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %12
%19 = sub nsw i32 %15, %16
%20 = sext i32 %16 to i64
%21 = getelementptr inbounds i8, i8* %13, i64 %20
%22 = add nsw i32 %16, %14
br label %32
23: ; preds = %12
%24 = load i8, i8* %13
%25 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%26 = sext i8 %24 to i32
%27 = tail call i32 @putchar(i32 %26)
%28 = add nsw i32 %15, -1
%29 = add nsw i32 %14, 1
%30 = getelementptr inbounds i8, i8* %13, i64 1
%31 = icmp eq i8 %24, 34
br i1 %31, label %37, label %32
32: ; preds = %18, %23
%33 = phi i32 [ %19, %18 ], [ %28, %23 ]
%34 = phi i32 [ %22, %18 ], [ %29, %23 ]
%35 = phi i8* [ %21, %18 ], [ %30, %23 ]
%36 = icmp eq i32 %33, 0
br i1 %36, label %37, label %12
37: ; preds = %32, %23, %5
%38 = phi i32 [ 1, %5 ], [ %34, %32 ], [ %29, %23 ]
%39 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
br label %40
40: ; preds = %2, %37
%41 = phi i32 [ %38, %37 ], [ 0, %2 ]
ret i32 %41
}