#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 st_mode;
};

/* Variables and functions */
int S_IFDIR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int isdirectory(char *filename) {
  struct stat buf;
  if (lstat(filename, &buf) == -1) {
    fprintf(stderr, "warning: cannot stat() %s\n", filename);
    return 1;
  }
  if (buf.st_mode & S_IFDIR)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<isdirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <lstat@plt>
cmp    $0xffffffff,%eax
jne    1167 <isdirectory+0x47>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xeaa(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    118f <isdirectory+0x6f>
mov    -0x18(%rbp),%eax
mov    0x2e5f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1188 <isdirectory+0x68>
movl   $0x1,-0x4(%rbp)
jmp    118f <isdirectory+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isdirectory>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <lstat@plt>
cmp    $0xffffffff,%eax
je     114b <isdirectory+0x2b>
mov    0x2e92(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
test   %ecx,0x8(%rsp)
setne  %al
jmp    1168 <isdirectory+0x48>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"warning: cannot stat() %s\0A\00"
@S_IFDIR = global i32 0
define i32 @isdirectory(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 @lstat(i8* %5, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %3
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %10)
store i32 1, i32* %2
br label %20
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @S_IFDIR
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 1, i32* %2
br label %20
19: ; preds = %12
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 }
@stderr = global i32 0
@.str = [27 x i8] c"warning: cannot stat() %s\0A\00"
@S_IFDIR = global i32 0
define i32 @isdirectory(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @S_IFDIR
%13 = and i32 %12, %11
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %9, %6
%17 = phi i32 [ 1, %6 ], [ %15, %9 ]
ret i32 %17
}