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

/* Variables and functions */
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ aaip_cleanout_st_mode(char *, int *, int);
int iso_local_get_acl_text(char *, char **, int);
int lstat(char *, struct stat *);
int stat(char *, struct stat *);
int iso_local_get_perms_wo_acl(char *disk_path, mode_t *st_mode, int flag) {
  struct stat stbuf;
  int ret;
  char *a_text = NULL;
  if (flag & 32)
    ret = stat(disk_path, &stbuf);
  else
    ret = lstat(disk_path, &stbuf);
  if (ret == -1)
    return -1;
  *st_mode = stbuf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
  ret = iso_local_get_acl_text(disk_path, &a_text, 16 | (flag & 32));
  if (a_text != NULL) {
    aaip_cleanout_st_mode(a_text, st_mode, 4 | 16);
    iso_local_get_acl_text(disk_path, &a_text, 1 << 15);
  }
  return 1;
}


x86 assembly (clang, -O0):
<iso_local_get_perms_wo_acl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     117f <iso_local_get_perms_wo_acl+0x3f>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,-0x24(%rbp)
jmp    118f <iso_local_get_perms_wo_acl+0x4f>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11a5 <iso_local_get_perms_wo_acl+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <iso_local_get_perms_wo_acl+0xda>
mov    -0x20(%rbp),%ecx
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    0x2e20(%rip),%rdx
or     (%rdx),%eax
mov    0x2e2f(%rip),%rdx
or     (%rdx),%eax
and    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
and    $0x20,%edx
or     $0x10,%edx
lea    -0x30(%rbp),%rsi
call   1030 <iso_local_get_acl_text@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1213 <iso_local_get_perms_wo_acl+0xd3>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x14,%edx
call   1050 <aaip_cleanout_st_mode@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x8000,%edx
call   1030 <iso_local_get_acl_text@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_local_get_perms_wo_acl>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
and    $0x20,%ebp
jne    11ce <iso_local_get_perms_wo_acl+0x8e>
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
je     11d8 <iso_local_get_perms_wo_acl+0x98>
mov    0x2e6e(%rip),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e6c(%rip),%rax
or     (%rax),%ecx
and    (%rsp),%ecx
mov    %ecx,(%r14)
or     $0x10,%ebp
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <iso_local_get_acl_text@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%ebp
test   %rdi,%rdi
je     11dd <iso_local_get_perms_wo_acl+0x9d>
mov    %r14,%rsi
mov    $0x14,%edx
call   1050 <aaip_cleanout_st_mode@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8000,%edx
call   1030 <iso_local_get_acl_text@plt>
jmp    11dd <iso_local_get_perms_wo_acl+0x9d>
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    116b <iso_local_get_perms_wo_acl+0x2b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
define i32 @iso_local_get_perms_wo_acl(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i8* null, i8** %10
%11 = load i32, i32* %7
%12 = and i32 %11, 32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @stat(i8* %15, %struct.stat* %8)
store i32 %16, i32* %9
br label %20
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i32 @lstat(i8* %18, %struct.stat* %8)
store i32 %19, i32* %9
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 -1, i32* %4
br label %48
24: ; preds = %20
%25 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @S_IRWXU
%28 = load i32, i32* @S_IRWXG
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRWXO
%31 = or i32 %29, %30
%32 = and i32 %26, %31
%33 = load i32*, i32** %6
store i32 %32, i32* %33
%34 = load i8*, i8** %5
%35 = load i32, i32* %7
%36 = and i32 %35, 32
%37 = or i32 16, %36
%38 = call i32 @iso_local_get_acl_text(i8* %34, i8** %10, i32 %37)
store i32 %38, i32* %9
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %47
41: ; preds = %24
%42 = load i8*, i8** %10
%43 = load i32*, i32** %6
%44 = call i32 @aaip_cleanout_st_mode(i8* %42, i32* %43, i32 20)
%45 = load i8*, i8** %5
%46 = call i32 @iso_local_get_acl_text(i8* %45, i8** %10, i32 32768)
br label %47
47: ; preds = %41, %24
store i32 1, i32* %4
br label %48
48: ; preds = %47, %23
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
define i32 @iso_local_get_perms_wo_acl(i8* %0, i32* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = alloca i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = and i32 %2, 32
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = call i32 @stat(i8* %0, %struct.stat* %4)
br label %14
12: ; preds = %3
%13 = call i32 @lstat(i8* %0, %struct.stat* %4)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %11, %10 ], [ %13, %12 ]
%16 = icmp eq i32 %15, -1
br i1 %16, label %33, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* @S_IRWXU
%21 = load i32, i32* @S_IRWXG
%22 = or i32 %21, %20
%23 = load i32, i32* @S_IRWXO
%24 = or i32 %22, %23
%25 = and i32 %24, %19
store i32 %25, i32* %1
%26 = or i32 %8, 16
%27 = call i32 @iso_local_get_acl_text(i8* %0, i8** %5, i32 %26)
%28 = load i8*, i8** %5
%29 = icmp eq i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %17
%31 = call i32 @aaip_cleanout_st_mode(i8* %28, i32* %1, i32 20)
%32 = call i32 @iso_local_get_acl_text(i8* %0, i8** %5, i32 32768)
br label %33
33: ; preds = %17, %30, %14
%34 = phi i32 [ -1, %14 ], [ 1, %30 ], [ 1, %17 ]
ret i32 %34
}