#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;
  scalar_t__ st_uid;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int);
scalar_t__ geteuid();
int lstat(char const *, struct stat *);
int checkruntimedir(const char *sockdir) {
  struct stat st;
  int r = lstat(sockdir, &st);
  if (r < 0)
    return 0;
  if (!S_ISDIR(st.st_mode))
    return 0;
  return st.st_uid == geteuid() && (st.st_mode & 0777) == 0700;
}


x86 assembly (clang, -O0):
<checkruntimedir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <lstat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1162 <checkruntimedir+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <checkruntimedir+0x91>
mov    -0x20(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    117f <checkruntimedir+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <checkruntimedir+0x91>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x25(%rbp)
jne    11b6 <checkruntimedir+0x86>
mov    -0x20(%rbp),%eax
and    $0x1ff,%eax
cmp    $0x1c0,%eax
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkruntimedir>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
xor    %ebp,%ebp
test   %eax,%eax
js     117b <checkruntimedir+0x4b>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
je     117b <checkruntimedir+0x4b>
mov    0x10(%rsp),%rbp
xor    %eax,%eax
call   1040 <geteuid@plt>
cmp    %rax,%rbp
sete   %al
and    $0x1ff,%ebx
cmp    $0x1c0,%ebx
sete   %cl
and    %al,%cl
movzbl %cl,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
define i32 @checkruntimedir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @lstat(i8* %6, %struct.stat* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %30
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @S_ISDIR(i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %11
store i32 0, i32* %2
br label %30
17: ; preds = %11
%18 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%19 = load i64, i64* %18
%20 = call i64 (...) @geteuid()
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, 511
%26 = icmp eq i32 %25, 448
br label %27
27: ; preds = %22, %17
%28 = phi i1 [ false, %17 ], [ %26, %22 ]
%29 = zext i1 %28 to i32
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %16, %10
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
define i32 @checkruntimedir(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 slt i32 %4, 0
br i1 %5, label %20, 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 i32 @S_ISDIR(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%13 = load i64, i64* %12
%14 = tail call i64 (...) @geteuid()
%15 = icmp eq i64 %13, %14
%16 = and i32 %8, 511
%17 = icmp eq i32 %16, 448
%18 = and i1 %17, %15
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %6, %1, %11
%21 = phi i32 [ %19, %11 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %21
}