#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
scalar_t__ optind;
int puts(char *);
int /*<<< orphan*/ stderr;
char *ttyname(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int opt, sflag = 0, err;
  char *tty;
  while ((opt = getopt(argc, argv, "s")) != -1)
    switch (opt) {
    case 's':
      sflag = 1;
      break;
    case '?':
    default:
      usage();
      break;
    }
  argc -= optind;
  argv += optind;
  if (argc > 0)
    fprintf(stderr, "tty: extra operand `%s'\n", argv[0]);
  tty = ttyname(0);
  if (!sflag) {
    err = puts(tty ? tty : "not a tty");
    if (err == EOF)
      exit(3);
  }
  exit(tty ? 0 : 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    0xe75(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11de <main+0x7e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x3f,%eax
je     11cd <main+0x6d>
jmp    11b0 <main+0x50>
mov    -0x2c(%rbp),%eax
sub    $0x73,%eax
jne    11d2 <main+0x72>
jmp    11c1 <main+0x61>
movl   $0x1,-0x18(%rbp)
jmp    11d9 <main+0x79>
jmp    11d2 <main+0x72>
mov    $0x0,%al
call   1060 <usage@plt>
jmp    117d <main+0x1d>
mov    0x2dfb(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    122e <main+0xce>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd9(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <ttyname@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1298 <main+0x138>
cmpq   $0x0,-0x28(%rbp)
je     125b <main+0xfb>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    126b <main+0x10b>
lea    0xdb9(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    126b <main+0x10b>
mov    -0x38(%rbp),%rdi
call   1030 <puts@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d67(%rip),%rcx
cmp    (%rcx),%eax
jne    1293 <main+0x133>
mov    $0x3,%edi
call   1080 <exit@plt>
jmp    1298 <main+0x138>
mov    -0x28(%rbp),%rcx
mov    $0x1,%edi
xor    %eax,%eax
cmp    $0x0,%rcx
cmovne %eax,%edi
call   1080 <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    0xe8a(%rip),%r14
jmp    1180 <main+0x20>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    $0x73,%eax
je     1178 <main+0x18>
cmp    $0xffffffff,%eax
je     11a0 <main+0x40>
xor    %eax,%eax
call   1060 <usage@plt>
jmp    1180 <main+0x20>
mov    0x2e39(%rip),%rax
mov    (%rax),%rax
sub    %eax,%ebp
test   %ebp,%ebp
jle    11c9 <main+0x69>
mov    0x2e19(%rip),%rcx
mov    (%rcx),%edi
mov    (%rbx,%rax,8),%rdx
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <ttyname@plt>
mov    %rax,%rbx
test   $0x1,%r15b
je     1201 <main+0xa1>
test   %rbx,%rbx
lea    0xe38(%rip),%rdi
cmovne %rbx,%rdi
call   1030 <puts@plt>
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <main+0xa1>
mov    $0x3,%edi
call   1080 <exit@plt>
xor    %edi,%edi
test   %rbx,%rbx
sete   %dil
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"s\00"
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"tty: extra operand `%s'\0A\00"
@.str.2 = [10 x i8] c"not a tty\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %19 [
i32 115, label %17
i32 63, label %18
]
17: ; preds = %15
store i32 1, i32* %7
br label %21
18: ; preds = %15
br label %19
19: ; preds = %15, %18
%20 = call i32 (...) @usage()
br label %21
21: ; preds = %19, %17
br label %10
22: ; preds = %10
%23 = load i64, i64* @optind
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = sub nsw i64 %25, %23
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
%28 = load i64, i64* @optind
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 %28
store i8** %30, i8*** %5
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %22
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %33, %22
%40 = call i8* @ttyname(i32 0)
store i8* %40, i8** %9
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %58, label %43
43: ; preds = %39
%44 = load i8*, i8** %9
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = load i8*, i8** %9
br label %49
48: ; preds = %43
br label %49
49: ; preds = %48, %46
%50 = phi i8* [ %47, %46 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %48 ]
%51 = call i32 @puts(i8* %50)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %49
%56 = call i32 @exit(i32 3)
unreachable
57: ; preds = %49
br label %58
58: ; preds = %57, %39
%59 = load i8*, i8** %9
%60 = icmp ne i8* %59, null
%61 = zext i1 %60 to i64
%62 = select i1 %60, i32 0, i32 1
%63 = call i32 @exit(i32 %62)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"s\00"
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"tty: extra operand `%s'\0A\00"
@.str.2 = [10 x i8] c"not a tty\00"
@EOF = global i32 0
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 = load i64, i64* @optind
%11 = trunc i64 %10 to i32
%12 = sub i32 %0, %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %15
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %14, %9
%20 = tail call i8* @ttyname(i32 0)
br i1 %4, label %21, label %29
21: ; preds = %19
%22 = icmp eq i8* %20, null
%23 = select i1 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %20
%24 = tail call i32 @puts(i8* dereferenceable(1) %23)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i32 @exit(i32 3)
unreachable
29: ; preds = %21, %19
%30 = icmp eq i8* %20, null
%31 = zext i1 %30 to i32
%32 = tail call i32 @exit(i32 %31)
unreachable
}