#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 {
  scalar_t__ st_uid;
  scalar_t__ st_gid;
  int st_mode;
};

/* Variables and functions */
scalar_t__ S_ISBLK(int);
scalar_t__ S_ISCHR(int);
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISSOCK(int);
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
scalar_t__ getegid();
scalar_t__ geteuid();
int get_attrib(char *name, struct stat *info) {
  int attrib = 0, mask;
  if (info->st_uid == geteuid())
    mask = S_IWUSR;
  else if (info->st_gid == getegid())
    mask = S_IWGRP;
  else
    mask = S_IWOTH;
  if ((info->st_mode & mask) == 0)
    attrib |= 0x1;
  if (name[0] == '.')
    attrib |= 0x2;
  if (S_ISCHR(info->st_mode) || S_ISBLK(info->st_mode) ||
      S_ISFIFO(info->st_mode) || S_ISSOCK(info->st_mode))
    attrib |= 0x4;
  if (S_ISDIR(info->st_mode))
    attrib |= 0x10;
  else
    attrib |= 0x20;
  return attrib;
}


x86 assembly (clang, -O0):
<get_attrib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    11ba <get_attrib+0x4a>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11ff <get_attrib+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1080 <getegid@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    11ee <get_attrib+0x7e>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11fa <get_attrib+0x8a>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11ff <get_attrib+0x8f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%eax
and    -0x18(%rbp),%eax
cmp    $0x0,%eax
jne    121b <get_attrib+0xab>
mov    -0x14(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1234 <get_attrib+0xc4>
mov    -0x14(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
call   1070 <S_ISCHR@plt>
cmp    $0x0,%rax
jne    128c <get_attrib+0x11c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
jne    128c <get_attrib+0x11c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%rax
jne    128c <get_attrib+0x11c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
call   1040 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     1295 <get_attrib+0x125>
mov    -0x14(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12b9 <get_attrib+0x149>
mov    -0x14(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x14(%rbp)
jmp    12c2 <get_attrib+0x152>
mov    -0x14(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_attrib>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%rbx
xor    %eax,%eax
call   1060 <geteuid@plt>
cmp    %rax,%rbx
jne    1193 <get_attrib+0x23>
mov    0x2e4f(%rip),%rax
jmp    11b3 <get_attrib+0x43>
mov    0x8(%r15),%rbx
xor    %eax,%eax
call   1080 <getegid@plt>
cmp    %rax,%rbx
jne    11ac <get_attrib+0x3c>
mov    0x2e3e(%rip),%rax
jmp    11b3 <get_attrib+0x43>
mov    0x2e15(%rip),%rax
mov    0x10(%r15),%edi
xor    %ecx,%ecx
mov    (%rax),%eax
and    %edi,%eax
sete   %cl
lea    0x2(%rcx),%ebx
cmpb   $0x2e,(%r14)
cmovne %ecx,%ebx
call   1070 <S_ISCHR@plt>
test   %rax,%rax
jne    11fe <get_attrib+0x8e>
mov    0x10(%r15),%edi
call   1090 <S_ISBLK@plt>
test   %rax,%rax
jne    11fe <get_attrib+0x8e>
mov    0x10(%r15),%edi
call   1030 <S_ISFIFO@plt>
test   %rax,%rax
jne    11fe <get_attrib+0x8e>
mov    0x10(%r15),%edi
call   1040 <S_ISSOCK@plt>
test   %rax,%rax
je     1201 <get_attrib+0x91>
or     $0x4,%ebx
mov    0x10(%r15),%edi
call   1050 <S_ISDIR@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
shl    $0x4,%ecx
lea    (%rcx,%rbx,1),%eax
add    $0x10,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.stat = type { i64, i64, i32 }
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
define i32 @get_attrib(i8* nocapture %0, %struct.stat* nocapture %1) {
%3 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%4 = load i64, i64* %3
%5 = tail call i64 (...) @geteuid()
%6 = icmp eq i64 %4, %5
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = tail call i64 (...) @getegid()
%11 = icmp eq i64 %9, %10
%12 = select i1 %11, i32* @S_IWGRP, i32* @S_IWOTH
br label %13
13: ; preds = %7, %2
%14 = phi i32* [ @S_IWUSR, %2 ], [ %12, %7 ]
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 2
%17 = load i32, i32* %16
%18 = and i32 %17, %15
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = load i8, i8* %0
%22 = icmp eq i8 %21, 46
%23 = or i32 %20, 2
%24 = select i1 %22, i32 %23, i32 %20
%25 = tail call i64 @S_ISCHR(i32 %17)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %13
%28 = load i32, i32* %16
%29 = tail call i64 @S_ISBLK(i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i32, i32* %16
%33 = tail call i64 @S_ISFIFO(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* %16
%37 = tail call i64 @S_ISSOCK(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %35, %31, %27, %13
%40 = or i32 %24, 4
br label %41
41: ; preds = %39, %35
%42 = phi i32 [ %40, %39 ], [ %24, %35 ]
%43 = load i32, i32* %16
%44 = tail call i64 @S_ISDIR(i32 %43)
%45 = icmp eq i64 %44, 0
%46 = select i1 %45, i32 32, i32 16
%47 = or i32 %46, %42
ret i32 %47
}