#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*/ buf;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int PATH_MAX;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char const *, int);
scalar_t__ stat(char const *, struct stat *);
char *strchr(char const *, char);
int verify_document_root(const char *root) {
  const char *p, *path;
  char buf[PATH_MAX];
  struct stat st;
  path = root;
  if ((p = strchr(root, ',')) != NULL && (size_t)(p - root) < sizeof(buf)) {
    memcpy(buf, root, p - root);
    buf[p - root] = '\0';
    path = buf;
  }
  if (stat(path, &st) != 0 || !S_ISDIR(st.st_mode)) {
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<verify_document_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11e9 <verify_document_root+0xa9>
mov    -0x50(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rdx
sub    %rdx,%rax
cmp    %rcx,%rax
jae    11e9 <verify_document_root+0xa9>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    1211 <verify_document_root+0xd1>
mov    -0x38(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1229 <verify_document_root+0xe9>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    123c <verify_document_root+0xfc>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_document_root>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e97(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%r15
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     119c <verify_document_root+0x5c>
mov    %rax,%rbx
sub    %r14,%rbx
cmp    %r12,%rbx
jae    119c <verify_document_root+0x5c>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
jmp    119f <verify_document_root+0x5f>
mov    %r14,%r15
lea    -0x28(%rbp),%rsi
mov    %r15,%rdi
call   1050 <stat@plt>
test   %rax,%rax
jne    11bc <verify_document_root+0x7c>
mov    -0x28(%rbp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
jne    11c5 <verify_document_root+0x85>
mov    0x2e15(%rip),%rax
jmp    11cc <verify_document_root+0x8c>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @verify_document_root(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.stat
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i8*, i8** %3
store i8* %14, i8** %5
%15 = load i8*, i8** %3
%16 = call i8* @strchr(i8* %15, i8 signext 44)
store i8* %16, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %40
18: ; preds = %1
%19 = load i8*, i8** %4
%20 = load i8*, i8** %3
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = icmp ult i64 %23, %11
br i1 %24, label %25, label %40
25: ; preds = %18
%26 = load i8*, i8** %3
%27 = load i8*, i8** %4
%28 = load i8*, i8** %3
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
%33 = call i32 @memcpy(i8* %13, i8* %26, i32 %32)
%34 = load i8*, i8** %4
%35 = load i8*, i8** %3
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = getelementptr inbounds i8, i8* %13, i64 %38
store i8 0, i8* %39
store i8* %13, i8** %5
br label %40
40: ; preds = %25, %18, %1
%41 = load i8*, i8** %5
%42 = call i64 @stat(i8* %41, %struct.stat* %8)
%43 = icmp ne i64 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %40
%45 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @S_ISDIR(i32 %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %44, %40
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %2
store i32 1, i32* %9
br label %53
51: ; preds = %44
%52 = load i32, i32* @EXIT_SUCCESS
store i32 %52, i32* %2
store i32 1, i32* %9
br label %53
53: ; preds = %51, %49
%54 = load i8*, i8** %6
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @verify_document_root(i8* %0) {
%2 = alloca %struct.stat
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast %struct.stat* %2 to i8*
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 44)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = ptrtoint i8* %7 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = icmp ult i64 %12, %4
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = trunc i64 %12 to i32
%16 = call i32 @memcpy(i8* %5, i8* %0, i32 %15)
%17 = getelementptr inbounds i8, i8* %5, i64 %12
store i8 0, i8* %17
br label %18
18: ; preds = %14, %9, %1
%19 = phi i8* [ %5, %14 ], [ %0, %9 ], [ %0, %1 ]
%20 = call i64 @stat(i8* %19, %struct.stat* %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @S_ISDIR(i32 %24)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %28
28: ; preds = %22, %18
%29 = phi i32* [ @EXIT_FAILURE, %18 ], [ %27, %22 ]
%30 = load i32, i32* %29
ret i32 %30
}