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


x86 assembly (clang, -O0):
<printColoredVar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
je     115b <printColoredVar+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    1222 <printColoredVar+0xf2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    $0x1,%edi
lea    0xe8d(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1206 <printColoredVar+0xd6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%eax
jne    11cf <printColoredVar+0x9f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     11cf <printColoredVar+0x9f>
jmp    1206 <printColoredVar+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%esi
lea    0xe1e(%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)
jmp    119b <printColoredVar+0x6b>
mov    $0x1,%edi
lea    0xdf7(%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):
<printColoredVar>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
cmpb   $0x24,(%rdi)
jne    11c2 <printColoredVar+0x92>
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeb4(%rip),%rsi
mov    $0x1,%r14d
mov    $0x1,%edi
mov    $0x3,%edx
call   1040 <write@plt>
mov    $0x24,%edi
call   1030 <putchar@plt>
cmp    $0x1,%ebp
je     11ac <printColoredVar+0x7c>
mov    %ebp,%r14d
mov    $0x1,%ebp
jmp    1191 <printColoredVar+0x61>
nopw   0x0(%rax,%rax,1)
movsbl %cl,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %ebp,%r14d
je     11ac <printColoredVar+0x7c>
movsbl (%rbx,%rbp,1),%edi
call   1050 <isalnum@plt>
movzbl (%rbx,%rbp,1),%ecx
test   %eax,%eax
jne    1180 <printColoredVar+0x50>
cmp    $0x5f,%cl
mov    $0x5f,%cl
je     1180 <printColoredVar+0x50>
mov    %ebp,%r14d
lea    0xe51(%rip),%rsi
mov    $0x1,%edi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\1B\22\06\00"
@.str.1 = [2 x i8] c"$\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [4 x i8] c"\1B\22\07\00"
define i32 @printColoredVar(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 36
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %46
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%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 i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
store i32 1, i32* %6
br label %19
19: ; preds = %33, %12
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = call i32 @isalnum(i8 signext %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 95
br i1 %31, label %32, label %33
32: ; preds = %27
br label %43
33: ; preds = %27, %22
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
%36 = load i8, i8* %34
%37 = sext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %5
%40 = add nsw i32 %39, -1
store i32 %40, i32* %5
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %19
43: ; preds = %32, %19
%44 = call i32 @write(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%45 = load i32, i32* %6
store i32 %45, i32* %3
br label %46
46: ; preds = %43, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [4 x i8] c"\1B\22\06\00"
@.str.3 = [4 x i8] c"\1B\22\07\00"
define i32 @printColoredVar(i8* nocapture %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 36
br i1 %4, label %5, label %31
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 36)
%8 = add nsw i32 %1, -1
%9 = icmp eq i32 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %5, %21
%11 = phi i32 [ %26, %21 ], [ %8, %5 ]
%12 = phi i8* [ %14, %21 ], [ %0, %5 ]
%13 = phi i32 [ %25, %21 ], [ 1, %5 ]
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = load i8, i8* %14
%16 = tail call i32 @isalnum(i8 signext %15)
%17 = icmp eq i32 %16, 0
%18 = load i8, i8* %14
br i1 %17, label %19, label %21
19: ; preds = %10
%20 = icmp eq i8 %18, 95
br i1 %20, label %21, label %28
21: ; preds = %10, %19
%22 = phi i8 [ 95, %19 ], [ %18, %10 ]
%23 = sext i8 %22 to i32
%24 = tail call i32 @putchar(i32 %23)
%25 = add nuw nsw i32 %13, 1
%26 = add nsw i32 %11, -1
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %10
28: ; preds = %21, %19, %5
%29 = phi i32 [ 1, %5 ], [ %13, %19 ], [ %1, %21 ]
%30 = 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 %31
31: ; preds = %2, %28
%32 = phi i32 [ %29, %28 ], [ 0, %2 ]
ret i32 %32
}