#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 */
struct stat {
  scalar_t__ st_rdev;
};

/* Variables and functions */
scalar_t__ fstat(int /*<<< orphan*/, struct stat *);
scalar_t__ stat(char const *, struct stat *);
int is_my_tty(const char *tty) {
  struct stat by_name, by_fd;
  if (stat(tty, &by_name) || fstat(0, &by_fd))
    return 0;
  if (by_name.st_rdev != by_fd.st_rdev)
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<is_my_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jne    1158 <is_my_tty+0x38>
xor    %edi,%edi
lea    -0x20(%rbp),%rsi
call   1040 <fstat@plt>
cmp    $0x0,%rax
je     1164 <is_my_tty+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1185 <is_my_tty+0x65>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     117e <is_my_tty+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    1185 <is_my_tty+0x65>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_my_tty>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1155 <is_my_tty+0x35>
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
call   1040 <fstat@plt>
test   %rax,%rax
jne    1155 <is_my_tty+0x35>
mov    0x8(%rsp),%rax
xor    %ebx,%ebx
cmp    (%rsp),%rax
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
define i32 @is_my_tty(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @stat(i8* %6, %struct.stat* %4)
%8 = icmp ne i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i64 @fstat(i32 0, %struct.stat* %5)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %1
store i32 0, i32* %2
br label %21
13: ; preds = %9
%14 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%17 = load i64, i64* %16
%18 = icmp ne i64 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %2
br label %21
20: ; preds = %13
store i32 1, i32* %2
br label %21
21: ; preds = %20, %19, %12
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i32 @is_my_tty(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %2 to i8*
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i64 @stat(i8* %0, %struct.stat* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = call i64 @fstat(i32 0, %struct.stat* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i64, i64* %14
%16 = icmp eq i64 %13, %15
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %11, %1, %8
%19 = phi i32 [ 0, %8 ], [ 0, %1 ], [ %17, %11 ]
ret i32 %19
}