#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);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char const *);
int /*<<< orphan*/ strcmp(char *, char *);
char *ttyname(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  const char *p;
  p = ttyname(0);
  if (p == NULL)
    p = "not a tty";
  if (argc == 2 && !strcmp(argv[1], "-s"))
    ;
  else {
    puts(p);
    putchar('\n');
  }
  exit(p ? 0 : 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1060 <ttyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <main+0x37>
lea    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11b3 <main+0x63>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b3 <main+0x63>
jmp    11c6 <main+0x76>
mov    -0x18(%rbp),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rcx
mov    $0x1,%edi
xor    %eax,%eax
cmp    $0x0,%rcx
cmovne %eax,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %edi,%edi
call   1060 <ttyname@plt>
test   %rax,%rax
lea    0xe96(%rip),%rbx
cmovne %rax,%rbx
cmp    $0x2,%ebp
jne    1187 <main+0x37>
mov    0x8(%r14),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1199 <main+0x49>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"not a tty\00"
@.str.1 = [3 x i8] c"-s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i8* @ttyname(i32 0)
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
br label %11
11: ; preds = %10, %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %14
br label %25
21: ; preds = %14, %11
%22 = load i8*, i8** %6
%23 = call i32 @puts(i8* %22)
%24 = call i32 @putchar(i8 signext 10)
br label %25
25: ; preds = %21, %20
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 0, i32 1
%30 = call i32 @exit(i32 %29)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"not a tty\00"
@.str.1 = [3 x i8] c"-s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i8* @ttyname(i32 0)
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7, %2
%13 = tail call i32 @puts(i8* dereferenceable(1) %5)
%14 = tail call i32 @putchar(i8 signext 10)
br label %15
15: ; preds = %7, %12
%16 = tail call i32 @exit(i32 0)
unreachable
}