#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*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcmp(char *, char *);
int path_state(char *path) {
  struct stat fs;
  if (!strcmp(path, ".") || !strcmp(path, "..")) {
    return 2;
  }
  if (stat(path, &fs) < 0) {
    return -1;
  }
  if (S_ISDIR(fs.st_mode)) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<path_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     116e <path_state+0x3e>
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    117a <path_state+0x4a>
movl   $0x2,-0x4(%rbp)
jmp    11c2 <path_state+0x92>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    119d <path_state+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <path_state+0x92>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11bb <path_state+0x8b>
movl   $0x1,-0x4(%rbp)
jmp    11c2 <path_state+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_state>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec4(%rip),%rsi
call   1040 <strcmp@plt>
mov    $0x2,%ebp
test   %eax,%eax
je     1186 <path_state+0x56>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1186 <path_state+0x56>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     1181 <path_state+0x51>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    1186 <path_state+0x56>
mov    $0xffffffff,%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"
@.str.1 = [3 x i8] c"..\00"
define i32 @path_state(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 %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8, %1
store i32 2, i32* %2
br label %25
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i64 @stat(i8* %14, %struct.stat* %4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %2
br label %25
18: ; preds = %13
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @S_ISDIR(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %2
br label %25
24: ; preds = %18
store i32 0, i32* %2
br label %25
25: ; preds = %24, %23, %17, %12
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32 @path_state(i8* %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 %18, label %6
6: ; preds = %1
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = call i64 @stat(i8* %0, %struct.stat* %2)
%11 = icmp slt i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %12, %9, %1, %6
%19 = phi i32 [ 2, %6 ], [ 2, %1 ], [ -1, %9 ], [ %17, %12 ]
ret i32 %19
}