#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 */
char *getenv(char *);
scalar_t__ isatty(int);
int /*<<< orphan*/ strcmp(char *, char *);
int tst_color_enabled(int fd) {
  static int color;
  if (color)
    return color - 1;
  char *env = getenv("LTP_COLORIZE_OUTPUT");
  if (env) {
    if (!strcmp(env, "n") || !strcmp(env, "0"))
      color = 1;
    if (!strcmp(env, "y") || !strcmp(env, "1"))
      color = 2;
    return color - 1;
  }
  if (isatty(fd) == 0)
    color = 1;
  else
    color = 2;
  return color - 1;
}


x86 assembly (clang, -O0):
<tst_color_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,0x2efa(%rip)
je     1159 <tst_color_enabled+0x29>
mov    0x2eee(%rip),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1234 <tst_color_enabled+0x104>
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11fd <tst_color_enabled+0xcd>
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11a6 <tst_color_enabled+0x76>
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b0 <tst_color_enabled+0x80>
movl   $0x1,0x2e8c(%rip)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11e2 <tst_color_enabled+0xb2>
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ec <tst_color_enabled+0xbc>
movl   $0x2,0x2e50(%rip)
mov    0x2e4a(%rip),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1234 <tst_color_enabled+0x104>
mov    -0x8(%rbp),%edi
call   1040 <isatty@plt>
cmp    $0x0,%rax
jne    121e <tst_color_enabled+0xee>
movl   $0x1,0x2e23(%rip)
jmp    1228 <tst_color_enabled+0xf8>
movl   $0x2,0x2e14(%rip)
mov    0x2e0e(%rip),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tst_color_enabled>:
push   %rbp
push   %r14
push   %rbx
mov    0x2f02(%rip),%ebp
test   %ebp,%ebp
jne    11d7 <tst_color_enabled+0xa7>
mov    %edi,%ebx
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11bc <tst_color_enabled+0x8c>
mov    %rax,%r14
lea    0xeb5(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <tst_color_enabled+0x50>
lea    0xea4(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    118f <tst_color_enabled+0x5f>
movl   $0x1,0x2eb2(%rip)
mov    $0x1,%ebp
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
mov    $0x2,%ebx
test   %eax,%eax
je     11cf <tst_color_enabled+0x9f>
lea    0xe6c(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11d7 <tst_color_enabled+0xa7>
jmp    11cf <tst_color_enabled+0x9f>
mov    %ebx,%edi
call   1040 <isatty@plt>
cmp    $0x1,%rax
mov    $0x2,%ebx
sbb    $0x0,%ebx
mov    %ebx,0x2e67(%rip)
mov    %ebx,%ebp
add    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@tst_color_enabled.color = internal global i32 0
@.str = [20 x i8] c"LTP_COLORIZE_OUTPUT\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [2 x i8] c"y\00"
@.str.4 = [2 x i8] c"1\00"
define i32 @tst_color_enabled(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* @tst_color_enabled.color
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @tst_color_enabled.color
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %2
br label %44
10: ; preds = %1
%11 = call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18, %14
store i32 1, i32* @tst_color_enabled.color
br label %23
23: ; preds = %22, %18
%24 = load i8*, i8** %4
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %27, %23
store i32 2, i32* @tst_color_enabled.color
br label %32
32: ; preds = %31, %27
%33 = load i32, i32* @tst_color_enabled.color
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %2
br label %44
35: ; preds = %10
%36 = load i32, i32* %3
%37 = call i64 @isatty(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* @tst_color_enabled.color
br label %41
40: ; preds = %35
store i32 2, i32* @tst_color_enabled.color
br label %41
41: ; preds = %40, %39
%42 = load i32, i32* @tst_color_enabled.color
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %2
br label %44
44: ; preds = %41, %32, %7
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@tst_color_enabled.color = internal unnamed_addr global i32 0
@.str = [20 x i8] c"LTP_COLORIZE_OUTPUT\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [2 x i8] c"y\00"
@.str.4 = [2 x i8] c"1\00"
define i32 @tst_color_enabled(i32 %0) {
%2 = load i32, i32* @tst_color_enabled.color
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %27
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %7
store i32 1, i32* @tst_color_enabled.color
br label %14
14: ; preds = %13, %10
%15 = phi i32 [ 1, %13 ], [ 0, %10 ]
%16 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %14
%19 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %27
21: ; preds = %4
%22 = tail call i64 @isatty(i32 %0)
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i32 1, i32 2
br label %25
25: ; preds = %14, %18, %21
%26 = phi i32 [ %24, %21 ], [ 2, %18 ], [ 2, %14 ]
store i32 %26, i32* @tst_color_enabled.color
br label %27
27: ; preds = %25, %18, %1
%28 = phi i32 [ %2, %1 ], [ %15, %18 ], [ %26, %25 ]
%29 = add nsw i32 %28, -1
ret i32 %29
}