#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_ISDIR(int /*<<< orphan*/);
int ft_print(char *, int, int /*<<< orphan*/);
int lstat(char const *, struct stat *);
int valid_path(const char *path) {
  struct stat stats;
  if (lstat(path, &stats) == -1)
    return (ft_print("cd :\t"
                     "An error occured.\n",
                     2, 0));
  else {
    if (S_ISDIR(stats.st_mode))
      return (1);
    else
      return (ft_print("cd :\t"
                       "requested path is not a directory.\n",
                       2, 0));
  }
}


x86 assembly (clang, -O0):
<valid_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
jne    116d <valid_path+0x3d>
lea    0xea7(%rip),%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   1050 <ft_print@plt>
mov    %eax,-0x4(%rbp)
jmp    11a1 <valid_path+0x71>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     118b <valid_path+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <valid_path+0x71>
lea    0xe86(%rip),%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   1050 <ft_print@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_path>:
push   %rax
mov    %rsp,%rsi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
je     1152 <valid_path+0x22>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     115b <valid_path+0x2b>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xea7(%rip),%rdi
jmp    1162 <valid_path+0x32>
lea    0xeb6(%rip),%rdi
mov    $0x2,%esi
xor    %edx,%edx
pop    %rax
jmp    1050 <ft_print@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [24 x i8] c"cd :\09An error occured.\0A\00"
@.str.1 = [41 x i8] c"cd :\09requested path is not a directory.\0A\00"
define i32 @valid_path(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 %10
8: ; preds = %1
%9 = call i32 @ft_print(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 2, i32 0)
store i32 %9, i32* %2
br label %18
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 %16
15: ; preds = %10
store i32 1, i32* %2
br label %18
16: ; preds = %10
%17 = call i32 @ft_print(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 0)
store i32 %17, i32* %2
br label %18
18: ; preds = %16, %15, %8
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [24 x i8] c"cd :\09An error occured.\0A\00"
@.str.1 = [41 x i8] c"cd :\09requested path is not a directory.\0A\00"
define i32 @valid_path(i8* nocapture %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 %11, label %6
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_ISDIR(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6, %1
%12 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), %6 ]
%13 = tail call i32 @ft_print(i8* %12, i32 2, i32 0)
br label %14
14: ; preds = %11, %6
%15 = phi i32 [ 1, %6 ], [ %13, %11 ]
ret i32 %15
}