#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 {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISFIFO(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ S_ISSOCK(int /*<<< orphan*/);
scalar_t__ fstat(int, struct stat *);
int is_fd_pipe(int fd) {
  struct stat st;
  if (fstat(fd, &st))
    return -1;
  if (S_ISREG(st.st_mode))
    return 0;
  if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode))
    return 1;
  return -1;
}


x86 assembly (clang, -O0):
<is_fd_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <fstat@plt>
cmp    $0x0,%rax
je     116d <is_fd_pipe+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <is_fd_pipe+0x82>
mov    -0x10(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     118b <is_fd_pipe+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <is_fd_pipe+0x82>
mov    -0x10(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%rax
jne    11af <is_fd_pipe+0x6f>
mov    -0x10(%rbp),%edi
call   1040 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     11bb <is_fd_pipe+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    11c2 <is_fd_pipe+0x82>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_fd_pipe>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
call   1060 <fstat@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1195 <is_fd_pipe+0x55>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1195 <is_fd_pipe+0x55>
mov    %ebx,%edi
call   1030 <S_ISFIFO@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1195 <is_fd_pipe+0x55>
mov    %ebx,%edi
call   1040 <S_ISSOCK@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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