#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 */
scalar_t__ EINVAL;
scalar_t__ ENOTTY;
scalar_t__ errno;
scalar_t__ isatty(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
void checktty(int fd, const char *name) {
  if (isatty(fd) == 0) {
    if (errno == EINVAL || errno == ENOTTY)
      printf("%s is not a terminal.\n", name);
    else {
      printf("%s\n", name);
      perror("isatty");
    }
  } else
    printf("%s is a terminal.\n", name);
}


x86 assembly (clang, -O0):
<checktty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
jne    11bb <checktty+0x8b>
mov    0x2e80(%rip),%rax
mov    (%rax),%rax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
je     1185 <checktty+0x55>
mov    0x2e66(%rip),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
jne    119a <checktty+0x6a>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
jmp    11b6 <checktty+0x86>
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
jmp    11cb <checktty+0x9b>
mov    -0x10(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checktty>:
push   %rbx
mov    %rsi,%rbx
call   1030 <isatty@plt>
test   %rax,%rax
je     1147 <checktty+0x17>
lea    0xedd(%rip),%rdi
jmp    1170 <checktty+0x40>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%rax
je     1169 <checktty+0x39>
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
jne    1179 <checktty+0x49>
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1040 <printf@plt>
lea    0xe97(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
pop    %rbx
jmp    1050 <perror@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
@ENOTTY = global i64 0
@.str = [23 x i8] c"%s is not a terminal.\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [7 x i8] c"isatty\00"
@.str.3 = [19 x i8] c"%s is a terminal.\0A\00"
define void @checktty(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = call i64 @isatty(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %2
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINVAL
%11 = icmp eq i64 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i64, i64* @errno
%14 = load i64, i64* @ENOTTY
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12, %8
%17 = load i8*, i8** %4
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %23
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %19, %16
br label %27
24: ; preds = %2
%25 = load i8*, i8** %4
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %23
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@ENOTTY = global i64 0
@.str = [23 x i8] c"%s is not a terminal.\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [7 x i8] c"isatty\00"
@.str.3 = [19 x i8] c"%s is a terminal.\0A\00"
define void @checktty(i32 %0, i8* %1) {
%3 = tail call i64 @isatty(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINVAL
%8 = icmp eq i64 %6, %7
%9 = load i64, i64* @ENOTTY
%10 = icmp eq i64 %6, %9
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %19
14: ; preds = %5
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %2
%18 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %19
19: ; preds = %12, %14, %17
ret void
}