#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 *);
int /*<<< orphan*/ isatty(int);
scalar_t__ strcasecmp(char const *, char *);
char ansi_terminal(void) {
  const char *term = getenv("TERM");
  if (!isatty(1) || !isatty(2))
    return 0;
  if (!term)
    return 0;
  if (strcasecmp(term, "ansi") == 0)
    return 1;
  if (strcasecmp(term, "console") == 0 || strcasecmp(term, "con80x25") == 0 ||
      strcasecmp(term, "linux") == 0 || strcasecmp(term, "linux-80x25") == 0)
    return 1;
  if (strcasecmp(term, "screen") == 0)
    return 1;
  if (strcasecmp(term, "xterm") == 0 || strcasecmp(term, "xterm-color") == 0 ||
      strcasecmp(term, "xterm-256color") == 0 ||
      strcasecmp(term, "xterm-16color") == 0)
    return 1;
  if (strcasecmp(term, "rxvt") == 0 || strcasecmp(term, "konsole") == 0 ||
      strcasecmp(term, "linux") == 0 || strcasecmp(term, "linux-80x25") == 0 ||
      strcasecmp(term, "konsole-16color") == 0 ||
      strcasecmp(term, "rxvt-16color") == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<ansi_terminal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%edi
call   1050 <isatty@plt>
cmp    $0x0,%eax
je     116e <ansi_terminal+0x3e>
mov    $0x2,%edi
call   1050 <isatty@plt>
cmp    $0x0,%eax
jne    1177 <ansi_terminal+0x47>
movb   $0x0,-0x1(%rbp)
jmp    135c <ansi_terminal+0x22c>
cmpq   $0x0,-0x10(%rbp)
jne    118b <ansi_terminal+0x5b>
movb   $0x0,-0x1(%rbp)
jmp    135c <ansi_terminal+0x22c>
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11ae <ansi_terminal+0x7e>
movb   $0x1,-0x1(%rbp)
jmp    135c <ansi_terminal+0x22c>
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1216 <ansi_terminal+0xe6>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1216 <ansi_terminal+0xe6>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1216 <ansi_terminal+0xe6>
mov    -0x10(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    121f <ansi_terminal+0xef>
movb   $0x1,-0x1(%rbp)
jmp    135c <ansi_terminal+0x22c>
mov    -0x10(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1242 <ansi_terminal+0x112>
movb   $0x1,-0x1(%rbp)
jmp    135c <ansi_terminal+0x22c>
mov    -0x10(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     12aa <ansi_terminal+0x17a>
mov    -0x10(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     12aa <ansi_terminal+0x17a>
mov    -0x10(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     12aa <ansi_terminal+0x17a>
mov    -0x10(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12b3 <ansi_terminal+0x183>
movb   $0x1,-0x1(%rbp)
jmp    135c <ansi_terminal+0x22c>
mov    -0x10(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     134f <ansi_terminal+0x21f>
mov    -0x10(%rbp),%rdi
lea    0xd90(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     134f <ansi_terminal+0x21f>
mov    -0x10(%rbp),%rdi
lea    0xd29(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     134f <ansi_terminal+0x21f>
mov    -0x10(%rbp),%rdi
lea    0xd15(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     134f <ansi_terminal+0x21f>
mov    -0x10(%rbp),%rdi
lea    0xd4a(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     134f <ansi_terminal+0x21f>
mov    -0x10(%rbp),%rdi
lea    0xd40(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1358 <ansi_terminal+0x228>
movb   $0x1,-0x1(%rbp)
jmp    135c <ansi_terminal+0x22c>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ansi_terminal>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1050 <isatty@plt>
test   %eax,%eax
je     12ac <ansi_terminal+0x17c>
mov    $0x2,%edi
call   1050 <isatty@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
je     12ae <ansi_terminal+0x17e>
test   %eax,%eax
je     12ae <ansi_terminal+0x17e>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
mov    $0x1,%bpl
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe17(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe0f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe0a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xe04(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xde9(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ae <ansi_terminal+0x17e>
lea    0xde5(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
sete   %bpl
jmp    12ae <ansi_terminal+0x17e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"TERM\00"
@.str.1 = [5 x i8] c"ansi\00"
@.str.2 = [8 x i8] c"console\00"
@.str.3 = [9 x i8] c"con80x25\00"
@.str.4 = [6 x i8] c"linux\00"
@.str.5 = [12 x i8] c"linux-80x25\00"
@.str.6 = [7 x i8] c"screen\00"
@.str.7 = [6 x i8] c"xterm\00"
@.str.8 = [12 x i8] c"xterm-color\00"
@.str.9 = [15 x i8] c"xterm-256color\00"
@.str.10 = [14 x i8] c"xterm-16color\00"
@.str.11 = [5 x i8] c"rxvt\00"
@.str.12 = [8 x i8] c"konsole\00"
@.str.13 = [16 x i8] c"konsole-16color\00"
@.str.14 = [13 x i8] c"rxvt-16color\00"
define signext i8 @ansi_terminal() {
%1 = alloca i8
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = call i32 @isatty(i32 1)
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @isatty(i32 2)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %6, %0
store i8 0, i8* %1
br label %84
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 0, i8* %1
br label %84
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i8 1, i8* %1
br label %84
19: ; preds = %14
%20 = load i8*, i8** %2
%21 = call i64 @strcasecmp(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = call i64 @strcasecmp(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = call i64 @strcasecmp(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8*, i8** %2
%33 = call i64 @strcasecmp(i8* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31, %27, %23, %19
store i8 1, i8* %1
br label %84
36: ; preds = %31
%37 = load i8*, i8** %2
%38 = call i64 @strcasecmp(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
store i8 1, i8* %1
br label %84
41: ; preds = %36
%42 = load i8*, i8** %2
%43 = call i64 @strcasecmp(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %57, label %45
45: ; preds = %41
%46 = load i8*, i8** %2
%47 = call i64 @strcasecmp(i8* %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %57, label %49
49: ; preds = %45
%50 = load i8*, i8** %2
%51 = call i64 @strcasecmp(i8* %50, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %49
%54 = load i8*, i8** %2
%55 = call i64 @strcasecmp(i8* %54, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %53, %49, %45, %41
store i8 1, i8* %1
br label %84
58: ; preds = %53
%59 = load i8*, i8** %2
%60 = call i64 @strcasecmp(i8* %59, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %82, label %62
62: ; preds = %58
%63 = load i8*, i8** %2
%64 = call i64 @strcasecmp(i8* %63, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %82, label %66
66: ; preds = %62
%67 = load i8*, i8** %2
%68 = call i64 @strcasecmp(i8* %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %82, label %70
70: ; preds = %66
%71 = load i8*, i8** %2
%72 = call i64 @strcasecmp(i8* %71, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %82, label %74
74: ; preds = %70
%75 = load i8*, i8** %2
%76 = call i64 @strcasecmp(i8* %75, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %82, label %78
78: ; preds = %74
%79 = load i8*, i8** %2
%80 = call i64 @strcasecmp(i8* %79, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %78, %74, %70, %66, %62, %58
store i8 1, i8* %1
br label %84
83: ; preds = %78
store i8 0, i8* %1
br label %84
84: ; preds = %83, %82, %57, %40, %35, %18, %13, %9
%85 = load i8, i8* %1
ret i8 %85
}

LLVM IR (-O2):
@.str = [5 x i8] c"TERM\00"
@.str.1 = [5 x i8] c"ansi\00"
@.str.2 = [8 x i8] c"console\00"
@.str.3 = [9 x i8] c"con80x25\00"
@.str.4 = [6 x i8] c"linux\00"
@.str.5 = [12 x i8] c"linux-80x25\00"
@.str.6 = [7 x i8] c"screen\00"
@.str.7 = [6 x i8] c"xterm\00"
@.str.8 = [12 x i8] c"xterm-color\00"
@.str.9 = [15 x i8] c"xterm-256color\00"
@.str.10 = [14 x i8] c"xterm-16color\00"
@.str.11 = [5 x i8] c"rxvt\00"
@.str.12 = [8 x i8] c"konsole\00"
@.str.13 = [16 x i8] c"konsole-16color\00"
@.str.14 = [13 x i8] c"rxvt-16color\00"
define signext i8 @ansi_terminal() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @isatty(i32 1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %52, label %4
4: ; preds = %0
%5 = tail call i32 @isatty(i32 2)
%6 = icmp eq i32 %5, 0
%7 = icmp eq i8* %1, null
%8 = or i1 %7, %6
br i1 %8, label %52, label %9
9: ; preds = %4
%10 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %52, label %12
12: ; preds = %9
%13 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %52, label %15
15: ; preds = %12
%16 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %52, label %18
18: ; preds = %15
%19 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %52, label %21
21: ; preds = %18
%22 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %52, label %24
24: ; preds = %21
%25 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %52, label %27
27: ; preds = %24
%28 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %52, label %30
30: ; preds = %27
%31 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %52, label %33
33: ; preds = %30
%34 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %52, label %36
36: ; preds = %33
%37 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %52, label %39
39: ; preds = %36
%40 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %52, label %42
42: ; preds = %39
%43 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %42
%46 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %45
%49 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
%51 = zext i1 %50 to i8
br label %52
52: ; preds = %48, %39, %42, %45, %27, %30, %33, %36, %24, %12, %15, %18, %21, %9, %0, %4
%53 = phi i8 [ 0, %4 ], [ 0, %0 ], [ 1, %9 ], [ 1, %21 ], [ 1, %18 ], [ 1, %15 ], [ 1, %12 ], [ 1, %24 ], [ 1, %36 ], [ 1, %33 ], [ 1, %30 ], [ 1, %27 ], [ 1, %45 ], [ 1, %42 ], [ 1, %39 ], [ %51, %48 ]
ret i8 %53
}