#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;
  int st_uid;
  int /*<<< orphan*/ st_gid;
};
typedef scalar_t__ bits;

/* Variables and functions */
scalar_t__ S_ISDIR(int);
int geteuid();
scalar_t__ group_member(int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int file_status(const char *name) {
  struct stat finfo;
  static int user_id = -1;
  if (stat(name, &finfo) < 0)
    return (0);
  if (S_ISDIR(finfo.st_mode))
    return (0x1);
  if (user_id == -1)
    user_id = geteuid();
  if (user_id == 0) {
    int bits;
    bits = ((((finfo.st_mode) & 0000700) >> 6) |
            (((finfo.st_mode) & 0000070) >> 3) |
            (((finfo.st_mode) & 0000007) >> 0));
    if (((bits)&1))
      return (0x1 | 0x2);
  }
  if (user_id == finfo.st_uid)
    return (((((finfo.st_mode) & 0000700) >> 6)) & 1) ? (0x1 | 0x2) : 0x1;
  if (group_member(finfo.st_gid))
    return (((((finfo.st_mode) & 0000070) >> 3)) & 1) ? (0x1 | 0x2) : 0x1;
  return (((((finfo.st_mode) & 0000007) >> 0)) & 1) ? (0x1 | 0x2) : 0x1;
}


x86 assembly (clang, -O0):
<file_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    116f <file_status+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1283 <file_status+0x143>
mov    -0x20(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     118d <file_status+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    1283 <file_status+0x143>
cmpl   $0xffffffff,0x2eac(%rip)
jne    11a7 <file_status+0x67>
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,0x2e99(%rip)
cmpl   $0x0,0x2e92(%rip)
jne    11f8 <file_status+0xb8>
mov    -0x20(%rbp),%eax
and    $0x1c0,%eax
sar    $0x6,%eax
mov    -0x20(%rbp),%ecx
and    $0x38,%ecx
sar    $0x3,%ecx
or     %ecx,%eax
mov    -0x20(%rbp),%ecx
and    $0x7,%ecx
sar    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11f3 <file_status+0xb3>
movl   $0x3,-0x4(%rbp)
jmp    1283 <file_status+0x143>
jmp    11f8 <file_status+0xb8>
mov    0x2e42(%rip),%eax
cmp    -0x1c(%rbp),%eax
jne    122e <file_status+0xee>
mov    -0x20(%rbp),%edx
and    $0x1c0,%edx
sar    $0x6,%edx
and    $0x1,%edx
mov    $0x1,%eax
mov    $0x3,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <file_status+0x143>
mov    -0x18(%rbp),%edi
call   1030 <group_member@plt>
cmp    $0x0,%rax
je     1264 <file_status+0x124>
mov    -0x20(%rbp),%edx
and    $0x38,%edx
sar    $0x3,%edx
and    $0x1,%edx
mov    $0x1,%eax
mov    $0x3,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <file_status+0x143>
mov    -0x20(%rbp),%edx
and    $0x7,%edx
sar    $0x0,%edx
and    $0x1,%edx
mov    $0x1,%eax
mov    $0x3,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_status>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     116e <file_status+0x2e>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     1175 <file_status+0x35>
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0x2ec5(%rip),%ecx
cmp    $0xffffffff,%ecx
je     1186 <file_status+0x46>
test   %ecx,%ecx
jne    11b3 <file_status+0x73>
jmp    1199 <file_status+0x59>
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,%ecx
mov    %eax,0x2eab(%rip)
test   %ecx,%ecx
jne    11b3 <file_status+0x73>
mov    0x8(%rsp),%eax
mov    %eax,%edx
shr    $0x3,%edx
or     %eax,%edx
shr    $0x6,%eax
or     %eax,%edx
mov    $0x3,%eax
test   $0x1,%dl
jne    1169 <file_status+0x29>
cmp    0xc(%rsp),%ecx
jne    11c7 <file_status+0x87>
mov    0x8(%rsp),%al
and    $0x40,%al
shr    $0x6,%al
movzbl %al,%eax
jmp    11ed <file_status+0xad>
mov    0x10(%rsp),%edi
call   1030 <group_member@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%eax
test   %rcx,%rcx
je     11ea <file_status+0xaa>
and    $0x8,%eax
shr    $0x2,%eax
or     $0x1,%eax
add    $0x18,%rsp
ret
and    $0x1,%eax
add    %eax,%eax
add    $0x1,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
@file_status.user_id = internal global i32 -1
define i32 @file_status(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 i64 @stat(i8* %6, %struct.stat* %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %81
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISDIR(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 1, i32* %2
br label %81
16: ; preds = %10
%17 = load i32, i32* @file_status.user_id
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (...) @geteuid()
store i32 %20, i32* @file_status.user_id
br label %21
21: ; preds = %19, %16
%22 = load i32, i32* @file_status.user_id
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %44
24: ; preds = %21
%25 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%26 = load i32, i32* %25
%27 = and i32 %26, 448
%28 = ashr i32 %27, 6
%29 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, 56
%32 = ashr i32 %31, 3
%33 = or i32 %28, %32
%34 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%35 = load i32, i32* %34
%36 = and i32 %35, 7
%37 = ashr i32 %36, 0
%38 = or i32 %33, %37
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = and i32 %39, 1
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %24
store i32 3, i32* %2
br label %81
43: ; preds = %24
br label %44
44: ; preds = %43, %21
%45 = load i32, i32* @file_status.user_id
%46 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%47 = load i32, i32* %46
%48 = icmp eq i32 %45, %47
br i1 %48, label %49, label %58
49: ; preds = %44
%50 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%51 = load i32, i32* %50
%52 = and i32 %51, 448
%53 = ashr i32 %52, 6
%54 = and i32 %53, 1
%55 = icmp ne i32 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i32 3, i32 1
store i32 %57, i32* %2
br label %81
58: ; preds = %44
%59 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 2
%60 = load i32, i32* %59
%61 = call i64 @group_member(i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %72
63: ; preds = %58
%64 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%65 = load i32, i32* %64
%66 = and i32 %65, 56
%67 = ashr i32 %66, 3
%68 = and i32 %67, 1
%69 = icmp ne i32 %68, 0
%70 = zext i1 %69 to i64
%71 = select i1 %69, i32 3, i32 1
store i32 %71, i32* %2
br label %81
72: ; preds = %58
%73 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%74 = load i32, i32* %73
%75 = and i32 %74, 7
%76 = ashr i32 %75, 0
%77 = and i32 %76, 1
%78 = icmp ne i32 %77, 0
%79 = zext i1 %78 to i64
%80 = select i1 %78, i32 3, i32 1
store i32 %80, i32* %2
br label %81
81: ; preds = %72, %63, %49, %42, %15, %9
%82 = load i32, i32* %2
ret i32 %82
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
@file_status.user_id = internal unnamed_addr global i32 -1
define i32 @file_status(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %50, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @S_ISDIR(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %50
11: ; preds = %6
%12 = load i32, i32* @file_status.user_id
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (...) @geteuid()
store i32 %15, i32* @file_status.user_id
br label %16
16: ; preds = %14, %11
%17 = phi i32 [ %15, %14 ], [ %12, %11 ]
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i32, i32* %7
%21 = lshr i32 %20, 6
%22 = lshr i32 %20, 3
%23 = or i32 %22, %20
%24 = or i32 %23, %21
%25 = and i32 %24, 1
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %50
27: ; preds = %19, %16
%28 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%29 = load i32, i32* %28
%30 = icmp eq i32 %17, %29
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* %7
%33 = and i32 %32, 64
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i32 1, i32 3
br label %50
36: ; preds = %27
%37 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 2
%38 = load i32, i32* %37
%39 = call i64 @group_member(i32 %38)
%40 = icmp eq i64 %39, 0
%41 = load i32, i32* %7
br i1 %40, label %46, label %42
42: ; preds = %36
%43 = and i32 %41, 8
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 1, i32 3
br label %50
46: ; preds = %36
%47 = and i32 %41, 1
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i32 1, i32 3
br label %50
50: ; preds = %6, %1, %19, %46, %42, %31
%51 = phi i32 [ %35, %31 ], [ %45, %42 ], [ %49, %46 ], [ 3, %19 ], [ 0, %1 ], [ 1, %6 ]
ret i32 %51
}