main(argc, argv) char **argv;
{
  register char *p;
  p = ttyname(0);
  if (argc == 2 && !strcmp(argv[1], "-s"))
    ;
  else
    printf("%s\n", (p ? p : "not a tty"));
  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
mov    $0x0,%al
call   1050 <ttyname@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1191 <main+0x51>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe82(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1191 <main+0x51>
jmp    11cb <main+0x8b>
cmpq   $0x0,-0x18(%rbp)
je     11a9 <main+0x69>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11b9 <main+0x79>
lea    0xe57(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11b9 <main+0x79>
mov    -0x20(%rbp),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rcx
mov    $0x1,%edi
xor    %eax,%eax
cmp    $0x0,%rcx
cmovne %eax,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %edi,%edi
xor    %eax,%eax
call   1050 <ttyname@plt>
mov    %eax,%ebx
cmp    $0x2,%ebp
jne    116d <main+0x2d>
mov    0x8(%r14),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1182 <main+0x42>
movslq %ebx,%rax
test   %eax,%eax
lea    0xe8a(%rip),%rdi
cmovne %rax,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
test   %ebx,%ebx
sete   %dil
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (i32, ...) bitcast (i32 (...)* @ttyname to i32 (i32, ...)*)(i32 0)
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %12
br label %28
19: ; preds = %12, %2
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i8*, i8** %6
br label %25
24: ; preds = %19
br label %25
25: ; preds = %24, %22
%26 = phi i8* [ %23, %22 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %24 ]
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %18
%29 = load i8*, i8** %6
%30 = icmp ne i8* %29, null
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 0, i32 1
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"-s\00"
@.str.2 = [10 x i8] c"not a tty\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @ttyname to i32 (i32, ...)*)(i32 0)
%4 = sext i32 %3 to i64
%5 = inttoptr i64 %4 to i8*
%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, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7, %2
%13 = icmp eq i32 %3, 0
%14 = select i1 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %5
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
br label %16
16: ; preds = %7, %12
%17 = icmp eq i32 %3, 0
%18 = zext i1 %17 to i32
tail call void @exit(i32 %18)
unreachable
}