#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 S_IRUSR;
int /*<<< orphan*/ S_ISDIR(int);
int S_IWUSR;
int S_IXUSR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int stat(char *, struct stat *);
int main(void) {
  struct stat buf;
  if (stat("/home/linkerist", &buf) == -1) {
    perror("fail to stat");
    exit(1);
  }
  if (!S_ISDIR(buf.st_mode)) {
    printf("this is not a directory file\n");
    exit(1);
  }
  if (S_IRUSR & buf.st_mode)
    printf("user can read the dir\n");
  if (S_IWUSR & buf.st_mode)
    printf("user can write the dir\n");
  if (S_IXUSR & buf.st_mode)
    printf("user can through the dir\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    118e <main+0x3e>
lea    0xe91(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11b5 <main+0x65>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
and    -0x8(%rbp),%eax
cmp    $0x0,%eax
je     11d6 <main+0x86>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
and    -0x8(%rbp),%eax
cmp    $0x0,%eax
je     11f7 <main+0xa7>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
and    -0x8(%rbp),%eax
cmp    $0x0,%eax
je     1218 <main+0xc8>
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     11c7 <main+0x77>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
je     11dd <main+0x8d>
mov    0x2e4f(%rip),%rax
test   %ebx,(%rax)
je     1191 <main+0x41>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e48(%rip),%rax
test   %ebx,(%rax)
je     11a8 <main+0x58>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e39(%rip),%rax
test   %ebx,(%rax)
je     11bf <main+0x6f>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe42(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/home/linkerist\00"
@.str.1 = [13 x i8] c"fail to stat\00"
@.str.2 = [30 x i8] c"this is not a directory file\0A\00"
@S_IRUSR = global i32 0
@.str.3 = [23 x i8] c"user can read the dir\0A\00"
@S_IWUSR = global i32 0
@.str.4 = [24 x i8] c"user can write the dir\0A\00"
@S_IXUSR = global i32 0
@.str.5 = [26 x i8] c"user can through the dir\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
store i32 0, i32* %1
%3 = call i32 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @S_ISDIR(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = load i32, i32* @S_IRUSR
%18 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* @S_IWUSR
%26 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%27 = load i32, i32* %26
%28 = and i32 %25, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = load i32, i32* @S_IXUSR
%34 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%35 = load i32, i32* %34
%36 = and i32 %33, %35
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %40
40: ; preds = %38, %32
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/home/linkerist\00"
@.str.1 = [13 x i8] c"fail to stat\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@str = [29 x i8] c"this is not a directory file\00"
@str.6 = [25 x i8] c"user can through the dir\00"
@str.7 = [23 x i8] c"user can write the dir\00"
@str.8 = [22 x i8] c"user can read the dir\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.stat, %struct.stat* %1, 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 %16
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = load i32, i32* @S_IRUSR
%18 = and i32 %17, %10
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* @S_IWUSR
%24 = and i32 %23, %10
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* @S_IXUSR
%30 = and i32 %29, %10
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
ret i32 0
}