#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ isatty(int);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  printf("fd 0: %s\n", isatty(0) ? "tty" : "not a tty");
  printf("fd 1: %s\n", isatty(1) ? "tty" : "not a tty");
  printf("fd 2: %s\n", isatty(2) ? "tty" : "not a tty");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xeba(%rip),%rsi
lea    0xeb9(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xe8b(%rip),%rsi
lea    0xe8a(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xe5c(%rip),%rsi
lea    0xe5b(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1030 <isatty@plt>
test   %rax,%rax
lea    0xec5(%rip),%r14
lea    0xec4(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
test   %rax,%rax
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1030 <isatty@plt>
test   %rax,%rax
cmove  %r14,%rbx
lea    0xe87(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"fd 0: %s\0A\00"
@.str.1 = [4 x i8] c"tty\00"
@.str.2 = [10 x i8] c"not a tty\00"
@.str.3 = [10 x i8] c"fd 1: %s\0A\00"
@.str.4 = [10 x i8] c"fd 2: %s\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 @isatty(i32 0)
%3 = icmp ne i64 %2, 0
%4 = zext i1 %3 to i64
%5 = select i1 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%6 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i64 @isatty(i32 1)
%8 = icmp ne i64 %7, 0
%9 = zext i1 %8 to i64
%10 = select i1 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = call i64 @isatty(i32 2)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"fd 0: %s\0A\00"
@.str.1 = [4 x i8] c"tty\00"
@.str.2 = [10 x i8] c"not a tty\00"
@.str.3 = [10 x i8] c"fd 1: %s\0A\00"
@.str.4 = [10 x i8] c"fd 2: %s\0A\00"
define i32 @main() {
%1 = tail call i64 @isatty(i32 0)
%2 = icmp eq i64 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i64 @isatty(i32 1)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = tail call i64 @isatty(i32 2)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 0)
unreachable
}