#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ isatty(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stop();
int test_isatty() {
  int fd;
  printf("isatty 1: stdin %s\n", isatty(0) ? "yes OK" : "no");
  stop();
  printf("isatty 2: stdout %s\n", isatty(1) ? "yes OK" : "no");
  stop();
  printf("isatty 3: stderr %s\n", isatty(2) ? "yes OK" : "no");
  stop();
  printf("isatty 4: invalid %s\n", isatty(999) ? "yes" : "no OK");
  stop();
  fd = open("foo.fileio.test", O_RDONLY);
  if (fd >= 0) {
    printf("isatty 5: file %s\n", isatty(fd) ? "yes" : "no OK");
    close(fd);
  } else
    printf("isatty 5: file couldn't open\n");
  stop();
}


x86 assembly (clang, -O0):
<test_isatty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xeb2(%rip),%rsi
lea    0xea4(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xe7a(%rip),%rsi
lea    0xe6c(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
mov    $0x2,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xe42(%rip),%rsi
lea    0xe34(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
mov    $0x3e7,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xe51(%rip),%rsi
lea    0xe46(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1293 <test_isatty+0x143>
mov    -0x8(%rbp),%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xdf9(%rip),%rsi
lea    0xdee(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
jmp    12a1 <test_isatty+0x151>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_isatty>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1040 <isatty@plt>
test   %rax,%rax
lea    0xea6(%rip),%rbp
lea    0xe98(%rip),%rbx
mov    %rbx,%rsi
cmove  %rbp,%rsi
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
mov    $0x1,%edi
call   1040 <isatty@plt>
test   %rax,%rax
mov    %rbx,%rsi
cmove  %rbp,%rsi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
mov    $0x2,%edi
call   1040 <isatty@plt>
test   %rax,%rax
cmove  %rbp,%rbx
lea    0xe5a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
mov    $0x3e7,%edi
call   1040 <isatty@plt>
test   %rax,%rax
lea    0xe64(%rip),%r14
lea    0xe59(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1264 <test_isatty+0x104>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <isatty@plt>
test   %rax,%rax
cmove  %r14,%rbx
lea    0xe27(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    1270 <test_isatty+0x110>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <stop@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"isatty 1: stdin %s\0A\00"
@.str.1 = [7 x i8] c"yes OK\00"
@.str.2 = [3 x i8] c"no\00"
@.str.3 = [21 x i8] c"isatty 2: stdout %s\0A\00"
@.str.4 = [21 x i8] c"isatty 3: stderr %s\0A\00"
@.str.5 = [22 x i8] c"isatty 4: invalid %s\0A\00"
@.str.6 = [4 x i8] c"yes\00"
@.str.7 = [6 x i8] c"no OK\00"
@.str.8 = [16 x i8] c"foo.fileio.test\00"
@O_RDONLY = global i32 0
@.str.9 = [19 x i8] c"isatty 5: file %s\0A\00"
@.str.10 = [30 x i8] c"isatty 5: file couldn't open\0A\00"
define i32 @test_isatty() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 @isatty(i32 0)
%4 = icmp ne i64 %3, 0
%5 = zext i1 %4 to i64
%6 = select i1 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32 (...) @stop()
%9 = call i64 @isatty(i32 1)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i64
%12 = select i1 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = call i32 (...) @stop()
%15 = call i64 @isatty(i32 2)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = call i32 (...) @stop()
%21 = call i64 @isatty(i32 999)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %24)
%26 = call i32 (...) @stop()
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %27)
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %0
%32 = load i32, i32* %2
%33 = call i64 @isatty(i32 %32)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %2
%39 = call i32 @close(i32 %38)
br label %42
40: ; preds = %0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
br label %42
42: ; preds = %40, %31
%43 = call i32 (...) @stop()
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [20 x i8] c"isatty 1: stdin %s\0A\00"
@.str.1 = [7 x i8] c"yes OK\00"
@.str.2 = [3 x i8] c"no\00"
@.str.3 = [21 x i8] c"isatty 2: stdout %s\0A\00"
@.str.4 = [21 x i8] c"isatty 3: stderr %s\0A\00"
@.str.5 = [22 x i8] c"isatty 4: invalid %s\0A\00"
@.str.6 = [4 x i8] c"yes\00"
@.str.7 = [6 x i8] c"no OK\00"
@.str.8 = [16 x i8] c"foo.fileio.test\00"
@O_RDONLY = global i32 0
@.str.9 = [19 x i8] c"isatty 5: file %s\0A\00"
@str = [29 x i8] c"isatty 5: file couldn't open\00"
define i32 @test_isatty() {
%1 = tail call i64 @isatty(i32 0)
%2 = icmp eq i64 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i32 (...) @stop()
%6 = tail call i64 @isatty(i32 1)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%10 = tail call i32 (...) @stop()
%11 = tail call i64 @isatty(i32 2)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = tail call i32 (...) @stop()
%16 = tail call i64 @isatty(i32 999)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %18)
%20 = tail call i32 (...) @stop()
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %21)
%23 = icmp sgt i32 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %0
%25 = tail call i64 @isatty(i32 %22)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %27)
%29 = tail call i32 @close(i32 %22)
br label %32
30: ; preds = %0
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = tail call i32 (...) @stop()
ret i32 undef
}