#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*/ strncmp(char *, char *, int);
char *ttyname(int);
int is_pseudo_tty(int fd) {
  char *tty = ttyname(fd);
  if (!strncmp(tty, "/dev/pts/", 9))
    return 1;
  if (!strncmp(tty, "/dev/tty", 8) && tty[8] >= 'a' && tty[8] <= 'z')
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<is_pseudo_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <ttyname@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xebe(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1161 <is_pseudo_tty+0x41>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <is_pseudo_tty+0x94>
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ad <is_pseudo_tty+0x8d>
mov    -0x10(%rbp),%rax
movsbl 0x8(%rax),%eax
cmp    $0x61,%eax
jl     11ad <is_pseudo_tty+0x8d>
mov    -0x10(%rbp),%rax
movsbl 0x8(%rax),%eax
cmp    $0x7a,%eax
jg     11ad <is_pseudo_tty+0x8d>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <is_pseudo_tty+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_pseudo_tty>:
push   %rbp
push   %rbx
push   %rax
call   1040 <ttyname@plt>
mov    %rax,%rbx
lea    0xece(%rip),%rsi
mov    %rax,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     116b <is_pseudo_tty+0x4b>
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1169 <is_pseudo_tty+0x49>
mov    0x8(%rbx),%al
add    $0x9f,%al
cmp    $0x1a,%al
jb     116b <is_pseudo_tty+0x4b>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/pts/\00"
@.str.1 = [9 x i8] c"/dev/tty\00"
define i32 @is_pseudo_tty(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i8* @ttyname(i32 %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 1, i32* %2
br label %29
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i32 @strncmp(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%14 = icmp ne i32 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 8
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp sge i32 %19, 97
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 8
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp sle i32 %25, 122
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 1, i32* %2
br label %29
28: ; preds = %21, %15, %11
store i32 0, i32* %2
br label %29
29: ; preds = %28, %27, %10
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/pts/\00"
@.str.1 = [9 x i8] c"/dev/tty\00"
define i32 @is_pseudo_tty(i32 %0) {
%2 = tail call i8* @ttyname(i32 %0)
%3 = tail call i32 @strncmp(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%4 = icmp eq i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = tail call i32 @strncmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %2, i64 8
%10 = load i8, i8* %9
%11 = add i8 %10, -97
%12 = icmp ult i8 %11, 26
br i1 %12, label %14, label %13
13: ; preds = %8, %5
br label %14
14: ; preds = %8, %1, %13
%15 = phi i32 [ 0, %13 ], [ 1, %1 ], [ 1, %8 ]
ret i32 %15
}