#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 */
scalar_t__ S_ISDIR(int);
int /*<<< orphan*/ ft_bzero(struct stat *, int);
scalar_t__ lstat(char *, struct stat *);
int is_directory(char *file) {
  struct stat buf;
  ft_bzero(&buf, sizeof(struct stat));
  if (lstat(file, &buf) < 0)
    return (-1);
  if (S_ISDIR(buf.st_mode)) {
    if (buf.st_mode < 16448)
      return (2);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<is_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1030 <ft_bzero@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
jge    116d <is_directory+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <is_directory+0x7b>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11a4 <is_directory+0x74>
cmpl   $0x4040,-0x18(%rbp)
jge    1198 <is_directory+0x68>
movl   $0x2,-0x4(%rbp)
jmp    11ab <is_directory+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    11ab <is_directory+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_directory>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <ft_bzero@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <lstat@plt>
test   %rax,%rax
js     1175 <is_directory+0x45>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     117c <is_directory+0x4c>
xor    %eax,%eax
cmpl   $0x4040,(%rsp)
setl   %al
add    $0x1,%eax
jmp    117e <is_directory+0x4e>
mov    $0xffffffff,%eax
jmp    117e <is_directory+0x4e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @is_directory(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @ft_bzero(%struct.stat* %2, i32 4)
%5 = call i64 @lstat(i8* %0, %struct.stat* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i64 @S_ISDIR(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 16448
%15 = select i1 %14, i32 2, i32 1
br label %16
16: ; preds = %7, %12, %1
%17 = phi i32 [ -1, %1 ], [ %15, %12 ], [ 0, %7 ]
ret i32 %17
}