#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 getopt(int, char **, char *);
int /*<<< orphan*/ puts(char *);
char *ttyname(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int ch, sflag;
  char *t;
  sflag = 0;
  while ((ch = getopt(argc, argv, "s")) != -1)
    switch (ch) {
    case 's':
      sflag = 1;
      break;
    case '?':
    default:
      usage();
    }
  t = ttyname(0);
  if (!sflag)
    puts(t ? t : "not a tty");
  exit(t ? 0 : 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11ce <main+0x7e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x3f,%eax
je     11bd <main+0x6d>
jmp    11a0 <main+0x50>
mov    -0x24(%rbp),%eax
sub    $0x73,%eax
jne    11c2 <main+0x72>
jmp    11b1 <main+0x61>
movl   $0x1,-0x18(%rbp)
jmp    11c9 <main+0x79>
jmp    11c2 <main+0x72>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    116d <main+0x1d>
xor    %edi,%edi
call   1040 <ttyname@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1214 <main+0xc4>
cmpq   $0x0,-0x20(%rbp)
je     11fb <main+0xab>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    120b <main+0xbb>
lea    0xe00(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    120b <main+0xbb>
mov    -0x30(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x20(%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   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%r15b
lea    0xe9a(%rip),%r14
jmp    1170 <main+0x20>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
cmp    $0x73,%eax
je     1168 <main+0x18>
cmp    $0xffffffff,%eax
je     1190 <main+0x40>
xor    %eax,%eax
call   1050 <usage@plt>
jmp    1170 <main+0x20>
xor    %edi,%edi
call   1040 <ttyname@plt>
mov    %rax,%rbx
test   $0x1,%r15b
je     11b3 <main+0x63>
test   %rbx,%rbx
lea    0xe58(%rip),%rdi
cmovne %rbx,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
test   %rbx,%rbx
sete   %dil
call   1070 <exit@plt>

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

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