#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*/ fileno(int /*<<< orphan*/ *);
char *getenv(char *);
int isatty(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int use_colors(FILE *stream) {
  int tty = isatty(fileno(stream));
  if (0 == tty)
    return 0;
  char *colors = getenv("DEBUG_COLORS");
  if (!colors)
    return 1;
  if (0 == strcmp("0", colors))
    return 0;
  if (0 == strncmp("no", colors, 2))
    return 0;
  if (0 == strncmp("false", colors, 5))
    return 0;
  if (0 == strncmp("disabled", colors, 8))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<use_colors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1050 <isatty@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1186 <use_colors+0x36>
movl   $0x0,-0x4(%rbp)
jmp    126b <use_colors+0x11b>
lea    0xe73(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ad <use_colors+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    126b <use_colors+0x11b>
mov    -0x20(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d7 <use_colors+0x87>
movl   $0x0,-0x4(%rbp)
jmp    126b <use_colors+0x11b>
mov    -0x20(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1206 <use_colors+0xb6>
movl   $0x0,-0x4(%rbp)
jmp    126b <use_colors+0x11b>
mov    -0x20(%rbp),%rsi
lea    0xe01(%rip),%rdi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1235 <use_colors+0xe5>
movl   $0x0,-0x4(%rbp)
jmp    126b <use_colors+0x11b>
mov    -0x20(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1264 <use_colors+0x114>
movl   $0x0,-0x4(%rbp)
jmp    126b <use_colors+0x11b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<use_colors>:
push   %rbp
push   %rbx
push   %rax
call   1070 <fileno@plt>
mov    %eax,%edi
call   1050 <isatty@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11e3 <use_colors+0x93>
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11de <use_colors+0x8e>
mov    %rax,%rbx
lea    0xe8d(%rip),%rdi
mov    %rax,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e3 <use_colors+0x93>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11e3 <use_colors+0x93>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11e3 <use_colors+0x93>
lea    0xe52(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    11e3 <use_colors+0x93>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"DEBUG_COLORS\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c"no\00"
@.str.3 = [6 x i8] c"false\00"
@.str.4 = [9 x i8] c"disabled\00"
define i32 @use_colors(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @fileno(i32* %6)
%8 = call i32 @isatty(i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 0, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %38
12: ; preds = %1
%13 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %12
store i32 1, i32* %2
br label %38
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = icmp eq i64 0, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 0, i32* %2
br label %38
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 2)
%25 = icmp eq i64 0, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %2
br label %38
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32 5)
%30 = icmp eq i64 0, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 0, i32* %2
br label %38
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %33, i32 8)
%35 = icmp eq i64 0, %34
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 0, i32* %2
br label %38
37: ; preds = %32
store i32 1, i32* %2
br label %38
38: ; preds = %37, %36, %31, %26, %21, %16, %11
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [13 x i8] c"DEBUG_COLORS\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c"no\00"
@.str.3 = [6 x i8] c"false\00"
@.str.4 = [9 x i8] c"disabled\00"
define i32 @use_colors(i32* nocapture %0) {
%2 = tail call i32 @fileno(i32* %0)
%3 = tail call i32 @isatty(i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %1
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %21, label %8
8: ; preds = %5
%9 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = tail call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = tail call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = tail call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32 8)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %5, %8, %11, %14, %17, %1
%22 = phi i32 [ 0, %1 ], [ 1, %5 ], [ 0, %8 ], [ 0, %11 ], [ 0, %14 ], [ %20, %17 ]
ret i32 %22
}