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

/* Variables and functions */
int S_IRUSR;
scalar_t__ S_ISDIR(int);
int stat(char *, struct stat *);
int /*<<< orphan*/ *strstr(char *, char *);
ssize_t file_attributes(char *filename) {
  struct stat info;
  if (strstr(filename, "..") != NULL || filename[0] == '/') {
    return -3;
  }
  if (stat(filename, &info) == -1) {
    return -1;
  }
  if (!(info.st_mode & S_IRUSR)) {
    return -3;
  }
  if (S_ISDIR(info.st_mode)) {
    return -2;
  }
  return info.st_size;
}


x86 assembly (clang, -O0):
<file_attributes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    1166 <file_attributes+0x36>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1172 <file_attributes+0x42>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11d9 <file_attributes+0xa9>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1194 <file_attributes+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <file_attributes+0xa9>
mov    -0x18(%rbp),%eax
mov    0x2e42(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11b5 <file_attributes+0x85>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11d9 <file_attributes+0xa9>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11d3 <file_attributes+0xa3>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11d9 <file_attributes+0xa9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_attributes>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rsi
call   1050 <strstr@plt>
mov    $0xfffffffd,%ebp
test   %rax,%rax
jne    1189 <file_attributes+0x59>
cmpb   $0x2f,(%rbx)
je     1189 <file_attributes+0x59>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     1184 <file_attributes+0x54>
mov    (%rsp),%edi
mov    0x2e75(%rip),%rax
test   %edi,(%rax)
je     1189 <file_attributes+0x59>
call   1030 <S_ISDIR@plt>
mov    $0xfffffffe,%ebp
test   %rax,%rax
jne    1189 <file_attributes+0x59>
mov    0x4(%rsp),%ebp
jmp    1189 <file_attributes+0x59>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [3 x i8] c"..\00"
@S_IRUSR = global i32 0
define i32 @file_attributes(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32* @strstr(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 47
br i1 %13, label %14, label %15
14: ; preds = %8, %1
store i32 -3, i32* %2
br label %36
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = call i32 @stat(i8* %16, %struct.stat* %4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %2
br label %36
20: ; preds = %15
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i32, i32* @S_IRUSR
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %20
store i32 -3, i32* %2
br label %36
27: ; preds = %20
%28 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @S_ISDIR(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 -2, i32* %2
br label %36
33: ; preds = %27
%34 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%35 = load i32, i32* %34
store i32 %35, i32* %2
br label %36
36: ; preds = %33, %32, %26, %19, %14
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [3 x i8] c"..\00"
@S_IRUSR = global i32 0
define i32 @file_attributes(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %24
6: ; preds = %1
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 47
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = call i32 @stat(i8* %0, %struct.stat* %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @S_IRUSR
%16 = and i32 %15, %14
%17 = icmp eq i32 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = tail call i64 @S_ISDIR(i32 %14)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%23 = load i32, i32* %22
br label %24
24: ; preds = %18, %12, %9, %1, %6, %21
%25 = phi i32 [ %23, %21 ], [ -3, %6 ], [ -3, %1 ], [ -1, %9 ], [ -3, %12 ], [ -2, %18 ]
ret i32 %25
}