#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*/ STDIN_FILENO;
int /*<<< orphan*/ bu_extra_argument(char *);
scalar_t__ bu_handle_version(int, char **);
int has_arg(int, char **, char *);
scalar_t__ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
char *ttyname(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (has_arg(argc, argv, "-h") || has_arg(argc, argv, "--help")) {
    puts("Usage: tty [-s]");
    puts("Print the file name of the terminal connected to standard input.\n");
    puts("Options:");
    puts("  -s    Don't print anything, only return an exit status.");
    return 1;
  }
  int dash_s = has_arg(argc, argv, "-s");
  if (bu_handle_version(argc, argv)) {
    return 0;
  }
  if ((argc > 2) || ((argc > 1) && !dash_s)) {
    bu_extra_argument(argv[0]);
    return 1;
  }
  if (isatty(STDIN_FILENO)) {
    if (!dash_s) {
      puts(ttyname(STDIN_FILENO));
    }
    return 0;
  }
  return 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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7c(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%eax
jne    11ae <main+0x4e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe63(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%eax
je     11ea <main+0x8a>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a3 <main+0x143>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea7(%rip),%rdx
call   1050 <has_arg@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <bu_handle_version@plt>
cmp    $0x0,%rax
je     1222 <main+0xc2>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <main+0x143>
cmpl   $0x2,-0x8(%rbp)
jg     1240 <main+0xe0>
cmpl   $0x1,-0x8(%rbp)
jle    1258 <main+0xf8>
cmpl   $0x0,-0x14(%rbp)
jne    1258 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <bu_extra_argument@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a3 <main+0x143>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   1040 <isatty@plt>
cmp    $0x0,%rax
je     129c <main+0x13c>
cmpl   $0x0,-0x14(%rbp)
jne    1290 <main+0x130>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1060 <ttyname@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <main+0x143>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe90(%rip),%rdx
call   1050 <has_arg@plt>
test   %eax,%eax
jne    118e <main+0x2e>
lea    0xe83(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <has_arg@plt>
test   %eax,%eax
je     11c8 <main+0x68>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xed0(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <has_arg@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <bu_handle_version@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11c3 <main+0x63>
cmp    $0x2,%ebp
jg     11fc <main+0x9c>
jne    1206 <main+0xa6>
test   %r14d,%r14d
jne    1206 <main+0xa6>
mov    (%rbx),%rdi
call   1070 <bu_extra_argument@plt>
jmp    11be <main+0x5e>
mov    0x2dd3(%rip),%rbx
mov    (%rbx),%edi
call   1040 <isatty@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
je     11c3 <main+0x63>
test   %r14d,%r14d
jne    11c3 <main+0x63>
mov    (%rbx),%edi
call   1060 <ttyname@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11c3 <main+0x63>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [16 x i8] c"Usage: tty [-s]\00"
@.str.3 = [66 x i8] c"Print the file name of the terminal connected to standard input.\0A\00"
@.str.4 = [9 x i8] c"Options:\00"
@.str.5 = [58 x i8] c" -s Don't print anything, only return an exit status.\00"
@.str.6 = [3 x i8] c"-s\00"
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = load i8**, i8*** %5
%9 = call i32 @has_arg(i32 %7, i8** %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @has_arg(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11, %2
%17 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @puts(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %57
21: ; preds = %11
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @has_arg(i32 %22, i8** %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32 %24, i32* %6
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = call i64 @bu_handle_version(i32 %25, i8** %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 0, i32* %3
br label %57
30: ; preds = %21
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 2
br i1 %32, label %39, label %33
33: ; preds = %30
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 1
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %36, %30
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @bu_extra_argument(i8* %42)
store i32 1, i32* %3
br label %57
44: ; preds = %36, %33
%45 = load i32, i32* @STDIN_FILENO
%46 = call i64 @isatty(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = load i32, i32* @STDIN_FILENO
%53 = call i8* @ttyname(i32 %52)
%54 = call i32 @puts(i8* %53)
br label %55
55: ; preds = %51, %48
store i32 0, i32* %3
br label %57
56: ; preds = %44
store i32 1, i32* %3
br label %57
57: ; preds = %56, %55, %39, %29, %16
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [16 x i8] c"Usage: tty [-s]\00"
@.str.3 = [66 x i8] c"Print the file name of the terminal connected to standard input.\0A\00"
@.str.4 = [9 x i8] c"Options:\00"
@.str.5 = [58 x i8] c" -s Don't print anything, only return an exit status.\00"
@.str.6 = [3 x i8] c"-s\00"
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0))
br label %36
13: ; preds = %5
%14 = tail call i32 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%15 = tail call i64 @bu_handle_version(i32 %0, i8** %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = icmp sgt i32 %0, 2
br i1 %18, label %23, label %19
19: ; preds = %17
%20 = icmp ne i32 %0, 2
%21 = icmp ne i32 %14, 0
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %26, label %23
23: ; preds = %19, %17
%24 = load i8*, i8** %1
%25 = tail call i32 @bu_extra_argument(i8* %24)
br label %36
26: ; preds = %19
%27 = load i32, i32* @STDIN_FILENO
%28 = tail call i64 @isatty(i32 %27)
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i1 true, i1 %21
%31 = zext i1 %29 to i32
br i1 %30, label %36, label %32
32: ; preds = %26
%33 = load i32, i32* @STDIN_FILENO
%34 = tail call i8* @ttyname(i32 %33)
%35 = tail call i32 @puts(i8* dereferenceable(1) %34)
br label %36
36: ; preds = %26, %23, %13, %32, %8
%37 = phi i32 [ 1, %8 ], [ 1, %23 ], [ 0, %13 ], [ 0, %32 ], [ %31, %26 ]
ret i32 %37
}