#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;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EISDIR;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int fileno(int /*<<< orphan*/ *);
scalar_t__ fstat(int, struct stat *);
int _do_is_directory(FILE *fp) {
  int fd;
  struct stat st;
  if ((fd = fileno(fp)) == -1)
    return 1;
  if (fstat(fd, &st) != 0)
    return 1;
  if (S_ISDIR(st.st_mode)) {
    errno = EISDIR;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_do_is_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    115d <_do_is_directory+0x2d>
movl   $0x1,-0x4(%rbp)
jmp    11b6 <_do_is_directory+0x86>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%rax
je     117f <_do_is_directory+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    11b6 <_do_is_directory+0x86>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11af <_do_is_directory+0x7f>
mov    0x2e50(%rip),%rax
mov    (%rax),%ecx
mov    0x2e37(%rip),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b6 <_do_is_directory+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_do_is_directory>:
push   %rbx
sub    $0x10,%rsp
call   1040 <fileno@plt>
mov    $0x1,%ebx
cmp    $0xffffffff,%eax
je     1179 <_do_is_directory+0x49>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1050 <fstat@plt>
test   %rax,%rax
jne    1179 <_do_is_directory+0x49>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     1177 <_do_is_directory+0x47>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    0x2e65(%rip),%rcx
mov    %eax,(%rcx)
jmp    1179 <_do_is_directory+0x49>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@EISDIR = global i32 0
@errno = global i32 0
define i32 @_do_is_directory(i32* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32 @fileno(i32* %0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = call i64 @fstat(i32 %4, %struct.stat* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
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_ISDIR(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = load i32, i32* @EISDIR
store i32 %15, i32* @errno
br label %16
16: ; preds = %9, %6, %1, %14
%17 = phi i32 [ 1, %14 ], [ 1, %1 ], [ 1, %6 ], [ 0, %9 ]
ret i32 %17
}