#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ *strstr(int /*<<< orphan*/ *, char *);
void log_highlight(FILE *outf, const int turn_highlight_on) {
  if (getenv("TERM") == NULL)
    return;
  if (strstr(getenv("TERM"), "color") == NULL)
    return;
  if (turn_highlight_on)
    fprintf(outf, "\x1b[32m");
  else
    fprintf(outf, "\x1b[0m");
}


x86 assembly (clang, -O0):
<log_highlight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    115a <log_highlight+0x2a>
jmp    11b3 <log_highlight+0x83>
lea    0xe9f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xe95(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    1184 <log_highlight+0x54>
jmp    11b3 <log_highlight+0x83>
cmpl   $0x0,-0xc(%rbp)
je     11a3 <log_highlight+0x73>
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11b3 <log_highlight+0x83>
mov    -0x8(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_highlight>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116f <log_highlight+0x3f>
lea    0xeb5(%rip),%rsi
mov    %rax,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     116f <log_highlight+0x3f>
test   %ebp,%ebp
je     1176 <log_highlight+0x46>
lea    0xea3(%rip),%rdi
mov    $0x5,%esi
jmp    1182 <log_highlight+0x52>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe94(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fwrite@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"TERM\00"
@.str.1 = [6 x i8] c"color\00"
@.str.2 = [6 x i8] c"\1B[32m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
define void @log_highlight(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %2
br label %22
8: ; preds = %2
%9 = call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @strstr(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %8
br label %22
13: ; preds = %8
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32*, i32** %3
%18 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %22
19: ; preds = %13
%20 = load i32*, i32** %3
%21 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %7, %12, %19, %16
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"TERM\00"
@.str.1 = [6 x i8] c"color\00"
@.str.2 = [6 x i8] c"\1B[32m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
define void @log_highlight(i32* nocapture %0, i32 %1) {
%3 = tail call i32* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i32* @strstr(i32* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = icmp eq i32 %1, 0
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5, i64 1, i32* %0)
br label %14
12: ; preds = %8
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %14
14: ; preds = %5, %2, %12, %10
ret void
}