#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 */
typedef int mode_t;

/* Variables and functions */
scalar_t__ S_ISDIR(int);
int /*<<< orphan*/ S_ISREG(int);
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int get_attributes(mode_t md) {
  int r = 0;
  if (S_ISDIR(md))
    r |= 1 << 4;
  else if (!S_ISREG(md))
    r |= 1 << 2;
  else
    r |= 1 << 5;
  if (0 == (md & (S_IWOTH | S_IWGRP | S_IWUSR)))
    r |= 1 << 0;
  return r;
}


x86 assembly (clang, -O0):
<get_attributes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1152 <get_attributes+0x32>
mov    -0x8(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x8(%rbp)
jmp    117f <get_attributes+0x5f>
mov    -0x4(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1171 <get_attributes+0x51>
mov    -0x8(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x8(%rbp)
jmp    117a <get_attributes+0x5a>
mov    -0x8(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x8(%rbp)
jmp    117f <get_attributes+0x5f>
mov    -0x4(%rbp),%ecx
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    0x2e56(%rip),%rdx
or     (%rdx),%eax
mov    0x2e45(%rip),%rdx
or     (%rdx),%eax
and    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11b2 <get_attributes+0x92>
mov    -0x8(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_attributes>:
push   %rbx
mov    %edi,%ebx
call   1030 <S_ISDIR@plt>
mov    $0x10,%ecx
test   %rax,%rax
jne    1148 <get_attributes+0x28>
mov    %ebx,%edi
call   1040 <S_ISREG@plt>
test   %eax,%eax
mov    $0x4,%eax
mov    $0x20,%ecx
cmove  %eax,%ecx
mov    0x2e79(%rip),%rax
mov    0x2e92(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2e7f(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
test   %ebx,%edx
sete   %al
or     %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@S_IWOTH = global i32 0
@S_IWGRP = global i32 0
@S_IWUSR = global i32 0
define i32 @get_attributes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = call i64 @S_ISDIR(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %3
%9 = or i32 %8, 16
store i32 %9, i32* %3
br label %21
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i32 @S_ISREG(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = or i32 %15, 4
store i32 %16, i32* %3
br label %20
17: ; preds = %10
%18 = load i32, i32* %3
%19 = or i32 %18, 32
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %14
br label %21
21: ; preds = %20, %7
%22 = load i32, i32* %2
%23 = load i32, i32* @S_IWOTH
%24 = load i32, i32* @S_IWGRP
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IWUSR
%27 = or i32 %25, %26
%28 = and i32 %22, %27
%29 = icmp eq i32 0, %28
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* %3
%32 = or i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %30, %21
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@S_IWOTH = global i32 0
@S_IWGRP = global i32 0
@S_IWUSR = global i32 0
define i32 @get_attributes(i32 %0) {
%2 = tail call i64 @S_ISDIR(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @S_ISREG(i32 %0)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i32 4, i32 32
br label %8
8: ; preds = %4, %1
%9 = phi i32 [ 16, %1 ], [ %7, %4 ]
%10 = load i32, i32* @S_IWOTH
%11 = load i32, i32* @S_IWGRP
%12 = or i32 %11, %10
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = and i32 %14, %0
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = or i32 %9, %17
ret i32 %18
}