#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*/ _who_error(char *, int);
scalar_t__ strncmp(char *, char *, int);
char *ttyname(int /*<<< orphan*/);
char *_who_tty(void) {
  char *tty;
  if ((tty = ttyname(0)) == NULL) {
    _who_error("ttyname", 1);
    return NULL;
  }
  if (strncmp(tty, "/dev/", 5) != 0)
    return tty;
  return tty + 5;
}


x86 assembly (clang, -O0):
<_who_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <ttyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    116b <_who_tty+0x3b>
lea    0xeac(%rip),%rdi
mov    $0x1,%esi
call   1040 <_who_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a3 <_who_tty+0x73>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1197 <_who_tty+0x67>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <_who_tty+0x73>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_who_tty>:
push   %rbx
xor    %edi,%edi
call   1050 <ttyname@plt>
test   %rax,%rax
je     1165 <_who_tty+0x35>
mov    %rax,%rbx
lea    0xec1(%rip),%rsi
mov    %rax,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,4),%rax
add    %rbx,%rax
pop    %rbx
ret
lea    0xe94(%rip),%rdi
mov    $0x1,%esi
call   1040 <_who_error@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"ttyname\00"
@.str.1 = [6 x i8] c"/dev/\00"
define i8* @_who_tty() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @ttyname(i32 0)
store i8* %3, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @_who_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 1)
store i8* null, i8** %1
br label %16
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = load i8*, i8** %2
store i8* %12, i8** %1
br label %16
13: ; preds = %7
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 5
store i8* %15, i8** %1
br label %16
16: ; preds = %13, %11, %5
%17 = load i8*, i8** %1
ret i8* %17
}

LLVM IR (-O2):
@.str = [8 x i8] c"ttyname\00"
@.str.1 = [6 x i8] c"/dev/\00"
define i8* @_who_tty() {
%1 = tail call i8* @ttyname(i32 0)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @_who_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 1)
br label %10
5: ; preds = %0
%6 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i64 5, i64 0
%9 = getelementptr i8, i8* %1, i64 %8
br label %10
10: ; preds = %5, %3
%11 = phi i8* [ null, %3 ], [ %9, %5 ]
ret i8* %11
}