#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 */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ fstat(int /*<<< orphan*/, struct stat *);
scalar_t__ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ warnx(char *);
void checkredirect(void) {
  struct stat sb1, sb2;
  if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) &&
      !fstat(STDOUT_FILENO, &sb1) && !fstat(STDERR_FILENO, &sb2) &&
      (sb1.st_rdev != sb2.st_rdev))
    warnx("stdout appears redirected, but stdin is the control descriptor");
}


x86 assembly (clang, -O0):
<checkredirect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
je     11b8 <checkredirect+0x88>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
je     11b8 <checkredirect+0x88>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%eax
jne    11b8 <checkredirect+0x88>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%eax
jne    11b8 <checkredirect+0x88>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11b8 <checkredirect+0x88>
lea    0xe4d(%rip),%rdi
call   1040 <warnx@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkredirect>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2eb2(%rip),%rbx
mov    (%rbx),%edi
call   1030 <isatty@plt>
test   %rax,%rax
je     118b <checkredirect+0x5b>
mov    0x2e87(%rip),%r14
mov    (%r14),%edi
call   1030 <isatty@plt>
test   %rax,%rax
je     118b <checkredirect+0x5b>
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1050 <fstat@plt>
test   %eax,%eax
jne    118b <checkredirect+0x5b>
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1050 <fstat@plt>
test   %eax,%eax
jne    118b <checkredirect+0x5b>
mov    0x10(%rsp),%rax
cmp    0x8(%rsp),%rax
jne    1193 <checkredirect+0x63>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe66(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1040 <warnx@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [63 x i8] c"stdout appears redirected, but stdin is the control descriptor\00"
define void @checkredirect() {
%1 = alloca %struct.stat
%2 = alloca %struct.stat
%3 = load i32, i32* @STDOUT_FILENO
%4 = call i64 @isatty(i32 %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %26
6: ; preds = %0
%7 = load i32, i32* @STDERR_FILENO
%8 = call i64 @isatty(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %6
%11 = load i32, i32* @STDOUT_FILENO
%12 = call i32 @fstat(i32 %11, %struct.stat* %1)
%13 = icmp ne i32 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %10
%15 = load i32, i32* @STDERR_FILENO
%16 = call i32 @fstat(i32 %15, %struct.stat* %2)
%17 = icmp ne i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %14
%19 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 0
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%22 = load i64, i64* %21
%23 = icmp ne i64 %20, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @warnx(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %18, %14, %10, %6, %0
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [63 x i8] c"stdout appears redirected, but stdin is the control descriptor\00"
define void @checkredirect() {
%1 = alloca %struct.stat
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %1 to i8*
%4 = bitcast %struct.stat* %2 to i8*
%5 = load i32, i32* @STDOUT_FILENO
%6 = tail call i64 @isatty(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %0
%9 = load i32, i32* @STDERR_FILENO
%10 = tail call i64 @isatty(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %8
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @fstat(i32 %13, %struct.stat* %1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i32, i32* @STDERR_FILENO
%18 = call i32 @fstat(i32 %17, %struct.stat* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%24 = load i64, i64* %23
%25 = icmp eq i64 %22, %24
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = tail call i32 @warnx(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %20, %16, %12, %8, %0
ret void
}