#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 magic_set {
  int dummy;
};
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ W_OK;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int file_printf(struct magic_set *, char *);
int unreadable_info(struct magic_set *ms, mode_t md, const char *file) {
  if (access(file, W_OK) == 0)
    if (file_printf(ms, "writable, ") == -1)
      return -1;
  if (access(file, X_OK) == 0)
    if (file_printf(ms, "executable, ") == -1)
      return -1;
  if (S_ISREG(md))
    if (file_printf(ms, "regular file, ") == -1)
      return -1;
  if (file_printf(ms, "no read permission") == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<unreadable_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    1189 <unreadable_info+0x59>
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1050 <file_printf@plt>
cmp    $0xffffffff,%eax
jne    1184 <unreadable_info+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <unreadable_info+0x107>
jmp    1189 <unreadable_info+0x59>
mov    -0x20(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    11cf <unreadable_info+0x9f>
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1050 <file_printf@plt>
cmp    $0xffffffff,%eax
jne    11ca <unreadable_info+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <unreadable_info+0x107>
jmp    11cf <unreadable_info+0x9f>
mov    -0x14(%rbp),%edi
call   1030 <S_ISREG@plt>
cmp    $0x0,%rax
je     120b <unreadable_info+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1050 <file_printf@plt>
cmp    $0xffffffff,%eax
jne    1206 <unreadable_info+0xd6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <unreadable_info+0x107>
jmp    120b <unreadable_info+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1050 <file_printf@plt>
cmp    $0xffffffff,%eax
jne    1230 <unreadable_info+0x100>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <unreadable_info+0x107>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unreadable_info>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    %rdx,%rdi
call   1040 <access@plt>
test   %rax,%rax
jne    1167 <unreadable_info+0x37>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <file_printf@plt>
cmp    $0xffffffff,%eax
je     11cf <unreadable_info+0x9f>
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1040 <access@plt>
test   %rax,%rax
jne    1191 <unreadable_info+0x61>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1050 <file_printf@plt>
cmp    $0xffffffff,%eax
je     11cf <unreadable_info+0x9f>
mov    %r14d,%edi
call   1030 <S_ISREG@plt>
test   %rax,%rax
je     11b2 <unreadable_info+0x82>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1050 <file_printf@plt>
cmp    $0xffffffff,%eax
je     11cf <unreadable_info+0x9f>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <file_printf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
jmp    11d4 <unreadable_info+0xa4>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.magic_set = type { i32 }
@W_OK = global i32 0
@.str = [11 x i8] c"writable, \00"
@X_OK = global i32 0
@.str.1 = [13 x i8] c"executable, \00"
@.str.2 = [15 x i8] c"regular file, \00"
@.str.3 = [19 x i8] c"no read permission\00"
define i32 @unreadable_info(%struct.magic_set* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.magic_set*
%6 = alloca i32
%7 = alloca i8*
store %struct.magic_set* %0, %struct.magic_set** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%8 = load i8*, i8** %7
%9 = load i32, i32* @W_OK
%10 = call i64 @access(i8* %8, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load %struct.magic_set*, %struct.magic_set** %5
%14 = call i32 @file_printf(%struct.magic_set* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %4
br label %45
17: ; preds = %12
br label %18
18: ; preds = %17, %3
%19 = load i8*, i8** %7
%20 = load i32, i32* @X_OK
%21 = call i64 @access(i8* %19, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load %struct.magic_set*, %struct.magic_set** %5
%25 = call i32 @file_printf(%struct.magic_set* %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %4
br label %45
28: ; preds = %23
br label %29
29: ; preds = %28, %18
%30 = load i32, i32* %6
%31 = call i64 @S_ISREG(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load %struct.magic_set*, %struct.magic_set** %5
%35 = call i32 @file_printf(%struct.magic_set* %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 -1, i32* %4
br label %45
38: ; preds = %33
br label %39
39: ; preds = %38, %29
%40 = load %struct.magic_set*, %struct.magic_set** %5
%41 = call i32 @file_printf(%struct.magic_set* %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 -1, i32* %4
br label %45
44: ; preds = %39
store i32 0, i32* %4
br label %45
45: ; preds = %44, %43, %37, %27, %16
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
%struct.magic_set = type { i32 }
@W_OK = global i32 0
@.str = [11 x i8] c"writable, \00"
@X_OK = global i32 0
@.str.1 = [13 x i8] c"executable, \00"
@.str.2 = [15 x i8] c"regular file, \00"
@.str.3 = [19 x i8] c"no read permission\00"
define i32 @unreadable_info(%struct.magic_set* %0, i32 %1, i8* nocapture %2) {
%4 = load i32, i32* @W_OK
%5 = tail call i64 @access(i8* %2, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @file_printf(%struct.magic_set* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %27, label %10
10: ; preds = %7, %3
%11 = load i32, i32* @X_OK
%12 = tail call i64 @access(i8* %2, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @file_printf(%struct.magic_set* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32 %15, -1
br i1 %16, label %27, label %17
17: ; preds = %14, %10
%18 = tail call i64 @S_ISREG(i32 %1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i32 @file_printf(%struct.magic_set* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32 %21, -1
br i1 %22, label %27, label %23
23: ; preds = %20, %17
%24 = tail call i32 @file_printf(%struct.magic_set* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32 %24, -1
%26 = sext i1 %25 to i32
br label %27
27: ; preds = %23, %20, %14, %7
%28 = phi i32 [ -1, %7 ], [ -1, %14 ], [ -1, %20 ], [ %26, %23 ]
ret i32 %28
}