#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 */
int /*<<< orphan*/ S_ISDIR(int);
int S_IWOTH;
int /*<<< orphan*/ err(int, char *, char const *);
int /*<<< orphan*/ errx(int, char *, char const *);
scalar_t__ lstat(char const *, struct stat *);
void check_sockdir(const char *path) {
  struct stat st;
  if (lstat(path, &st) < 0)
    err(110, "stat(\"%s\")", path);
  if (!S_ISDIR(st.st_mode))
    errx(111, "%s is not a directory", path);
  if (st.st_mode & S_IWOTH)
    errx(112, "%s is world-writable", path);
}


x86 assembly (clang, -O0):
<check_sockdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
jge    1178 <check_sockdir+0x38>
mov    -0x8(%rbp),%rdx
mov    $0x6e,%edi
lea    0xe8d(%rip),%rsi
call   1060 <err@plt>
mov    -0x10(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    119e <check_sockdir+0x5e>
mov    -0x8(%rbp),%rdx
mov    $0x6f,%edi
lea    0xe72(%rip),%rsi
call   1030 <errx@plt>
mov    -0x10(%rbp),%eax
mov    0x2e30(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11c8 <check_sockdir+0x88>
mov    -0x8(%rbp),%rdx
mov    $0x70,%edi
lea    0xe5e(%rip),%rsi
call   1030 <errx@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_sockdir>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <lstat@plt>
test   %rax,%rax
jns    1167 <check_sockdir+0x27>
lea    0xea6(%rip),%rsi
mov    $0x6e,%edi
mov    %rbx,%rdx
call   1060 <err@plt>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
jne    1189 <check_sockdir+0x49>
lea    0xe8f(%rip),%rsi
mov    $0x6f,%edi
mov    %rbx,%rdx
call   1030 <errx@plt>
mov    0x2e48(%rip),%rax
test   %ebp,(%rax)
je     11ae <check_sockdir+0x6e>
lea    0xe86(%rip),%rsi
mov    $0x70,%edi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <errx@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [11 x i8] c"stat(\22%s\22)\00"
@.str.1 = [22 x i8] c"%s is not a directory\00"
@S_IWOTH = global i32 0
@.str.2 = [21 x i8] c"%s is world-writable\00"
define void @check_sockdir(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @lstat(i8* %4, %struct.stat* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @err(i32 110, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %7, %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @S_ISDIR(i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = call i32 @errx(i32 111, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %10
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @S_IWOTH
%22 = and i32 %20, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i8*, i8** %2
%26 = call i32 @errx(i32 112, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %18
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [11 x i8] c"stat(\22%s\22)\00"
@.str.1 = [22 x i8] c"%s is not a directory\00"
@S_IWOTH = global i32 0
@.str.2 = [21 x i8] c"%s is world-writable\00"
define void @check_sockdir(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @err(i32 110, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @S_ISDIR(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @errx(i32 111, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %8
%16 = load i32, i32* @S_IWOTH
%17 = and i32 %16, %10
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @errx(i32 112, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %21
21: ; preds = %19, %15
ret void
}