#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 */
int detectPresence(char *);
scalar_t__ isatty(int);
scalar_t__ terminalName();
int whiptailPresent() {
  static int lWhiptailPresent = -1;
  if (lWhiptailPresent < 0) {
    lWhiptailPresent = detectPresence("whiptail");
  }
  return lWhiptailPresent && (isatty(1) || terminalName());
}


x86 assembly (clang, -O0):
<whiptailPresent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2ef9(%rip)
jge    1157 <whiptailPresent+0x27>
lea    0xeb4(%rip),%rdi
call   1040 <detectPresence@plt>
mov    %eax,0x2ee1(%rip)
xor    %eax,%eax
cmpl   $0x0,0x2ed8(%rip)
mov    %al,-0x1(%rbp)
je     119c <whiptailPresent+0x6c>
mov    $0x1,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x2(%rbp)
jne    1196 <whiptailPresent+0x66>
mov    $0x0,%al
call   1050 <terminalName@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2(%rbp)
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
mov    -0x1(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<whiptailPresent>:
push   %rbx
mov    0x2f01(%rip),%eax
test   %eax,%eax
js     1164 <whiptailPresent+0x34>
test   %eax,%eax
je     117a <whiptailPresent+0x4a>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1030 <isatty@plt>
test   %rax,%rax
jne    117c <whiptailPresent+0x4c>
xor    %eax,%eax
call   1050 <terminalName@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
jmp    117c <whiptailPresent+0x4c>
lea    0xe95(%rip),%rdi
call   1040 <detectPresence@plt>
mov    %eax,0x2ec2(%rip)
test   %eax,%eax
jne    113f <whiptailPresent+0xf>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@whiptailPresent.lWhiptailPresent = internal global i32 -1
@.str = [9 x i8] c"whiptail\00"
define i32 @whiptailPresent() {
%1 = load i32, i32* @whiptailPresent.lWhiptailPresent
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = call i32 @detectPresence(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %4, i32* @whiptailPresent.lWhiptailPresent
br label %5
5: ; preds = %3, %0
%6 = load i32, i32* @whiptailPresent.lWhiptailPresent
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = call i64 @isatty(i32 1)
%10 = icmp ne i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i64 (...) @terminalName()
%13 = icmp ne i64 %12, 0
br label %14
14: ; preds = %11, %8
%15 = phi i1 [ true, %8 ], [ %13, %11 ]
br label %16
16: ; preds = %14, %5
%17 = phi i1 [ false, %5 ], [ %15, %14 ]
%18 = zext i1 %17 to i32
ret i32 %18
}

LLVM IR (-O2):
@whiptailPresent.lWhiptailPresent = internal unnamed_addr global i32 -1
@.str = [9 x i8] c"whiptail\00"
define i32 @whiptailPresent() {
%1 = load i32, i32* @whiptailPresent.lWhiptailPresent
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @detectPresence(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %4, i32* @whiptailPresent.lWhiptailPresent
br label %5
5: ; preds = %3, %0
%6 = phi i32 [ %4, %3 ], [ %1, %0 ]
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = tail call i64 @isatty(i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = tail call i64 (...) @terminalName()
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %8, %11, %5
%16 = phi i32 [ 0, %5 ], [ 1, %8 ], [ %14, %11 ]
ret i32 %16
}