#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*/);
int /*<<< orphan*/ stat(char const *, struct stat *);
int /*<<< orphan*/ strcmp(char const *, char *);
int is_pipe(const char *str) {
  struct stat st;
  if (!strcmp(str, "-"))
    return 1;
  if (!stat(str, &st) && S_ISFIFO(st.st_mode))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<is_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1161 <is_pipe+0x31>
movl   $0x1,-0x4(%rbp)
jmp    119c <is_pipe+0x6c>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%eax
jne    1195 <is_pipe+0x65>
mov    -0x18(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     1195 <is_pipe+0x65>
movl   $0x1,-0x4(%rbp)
jmp    119c <is_pipe+0x6c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_pipe>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rsi
call   1040 <strcmp@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     1169 <is_pipe+0x39>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %eax,%eax
jne    1167 <is_pipe+0x37>
mov    (%rsp),%edi
call   1030 <S_ISFIFO@plt>
test   %rax,%rax
jne    1169 <is_pipe+0x39>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"-\00"
define i32 @is_pipe(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = call i32 @stat(i8* %0, %struct.stat* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i64 @S_ISFIFO(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9, %6
br label %15
15: ; preds = %9, %1, %14
%16 = phi i32 [ 0, %14 ], [ 1, %1 ], [ 1, %9 ]
ret i32 %16
}