#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__ strcmp(char *, char *);
int color_test() {
  static int use_xterm_color = 0;
  char *term;
  if (!use_xterm_color) {
    term = getenv("TERM");
    if (term != NULL) {
      if (strcmp(term, "xterm") == 0) {
        use_xterm_color = 1;
      } else {
        use_xterm_color = -1;
      }
    } else {
      use_xterm_color = -1;
    }
  }
  return use_xterm_color;
}


x86 assembly (clang, -O0):
<color_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f05(%rip)
jne    1197 <color_test+0x77>
lea    0xec4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1188 <color_test+0x68>
mov    -0x8(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1179 <color_test+0x59>
movl   $0x1,0x2ec0(%rip)
jmp    1183 <color_test+0x63>
movl   $0xffffffff,0x2eb1(%rip)
ff ff ff
jmp    1192 <color_test+0x72>
movl   $0xffffffff,0x2ea2(%rip)
ff ff ff
jmp    1197 <color_test+0x77>
mov    0x2e97(%rip),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<color_test>:
push   %rax
mov    0x2f0d(%rip),%eax
test   %eax,%eax
je     112d <color_test+0xd>
pop    %rcx
ret
lea    0xecc(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1157 <color_test+0x37>
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
neg    %rax
sbb    %eax,%eax
or     $0x1,%eax
jmp    115c <color_test+0x3c>
mov    $0xffffffff,%eax
mov    %eax,0x2ed2(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@color_test.use_xterm_color = internal global i32 0
@.str = [5 x i8] c"TERM\00"
@.str.1 = [6 x i8] c"xterm\00"
define i32 @color_test() {
%1 = alloca i8*
%2 = load i32, i32* @color_test.use_xterm_color
%3 = icmp ne i32 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %0
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = load i8*, i8** %1
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 1, i32* @color_test.use_xterm_color
br label %14
13: ; preds = %8
store i32 -1, i32* @color_test.use_xterm_color
br label %14
14: ; preds = %13, %12
br label %16
15: ; preds = %4
store i32 -1, i32* @color_test.use_xterm_color
br label %16
16: ; preds = %15, %14
br label %17
17: ; preds = %16, %0
%18 = load i32, i32* @color_test.use_xterm_color
ret i32 %18
}

LLVM IR (-O2):
@color_test.use_xterm_color = internal unnamed_addr global i32 0
@.str = [5 x i8] c"TERM\00"
@.str.1 = [6 x i8] c"xterm\00"
define i32 @color_test() {
%1 = load i32, i32* @color_test.use_xterm_color
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i32 1, i32 -1
br label %10
10: ; preds = %3, %6
%11 = phi i32 [ %9, %6 ], [ -1, %3 ]
store i32 %11, i32* @color_test.use_xterm_color
br label %12
12: ; preds = %10, %0
%13 = phi i32 [ %1, %0 ], [ %11, %10 ]
ret i32 %13
}