#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;
};

/* Variables and functions */
int S_IRUSR;
int S_IWUSR;
int S_IXUSR;
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
void sp(char *filename) {
  char *results = (char *)malloc(sizeof(char) * 1024);
  memset(results, 0, 1024);
  struct stat statRes;
  if (stat(filename, &statRes) < 0) {
    printf("Error, file does not exists\n");
    return;
  }
  if (!((statRes.st_mode & S_IRUSR) == 0))
    strcat(results, "Reading, ");
  else
    strcat(results, "Not reading, ");
  if (!((statRes.st_mode & S_IWUSR) == 0))
    strcat(results, "Writing, ");
  else
    strcat(results, "Not writing, ");
  if (!((statRes.st_mode & S_IXUSR) == 0))
    strcat(results, "Executing");
  else
    strcat(results, "Not executing");
  printf("%s\n", results);
}


x86 assembly (clang, -O0):
<sp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11a4 <sp+0x54>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1264 <sp+0x114>
mov    -0x18(%rbp),%eax
mov    0x2e22(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ce <sp+0x7e>
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <strcat@plt>
jmp    11de <sp+0x8e>
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%eax
mov    0x2df8(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1208 <sp+0xb8>
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1070 <strcat@plt>
jmp    1218 <sp+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%eax
mov    0x2dc6(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1242 <sp+0xf2>
mov    -0x10(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1070 <strcat@plt>
jmp    1252 <sp+0x102>
mov    -0x10(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     11f7 <sp+0xa7>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
lea    0xe74(%rip),%rax
lea    0xe63(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
lea    0xe66(%rip),%rax
lea    0xe55(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
lea    0xe58(%rip),%rax
lea    0xe47(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
jmp    11fe <sp+0xae>
lea    0xe4a(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [29 x i8] c"Error, file does not exists\0A\00"
@S_IRUSR = global i32 0
@.str.1 = [10 x i8] c"Reading, \00"
@.str.2 = [14 x i8] c"Not reading, \00"
@S_IWUSR = global i32 0
@.str.3 = [10 x i8] c"Writing, \00"
@.str.4 = [14 x i8] c"Not writing, \00"
@S_IXUSR = global i32 0
@.str.5 = [10 x i8] c"Executing\00"
@.str.6 = [14 x i8] c"Not executing\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define void @sp(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %2
%5 = call i64 @malloc(i32 1024)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @memset(i8* %7, i32 0, i32 1024)
%9 = load i8*, i8** %2
%10 = call i64 @stat(i8* %9, %struct.stat* %4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %53
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load i32, i32* @S_IRUSR
%18 = and i32 %16, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %26
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %23, %20
%27 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* @S_IWUSR
%30 = and i32 %28, %29
%31 = icmp eq i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %38
35: ; preds = %26
%36 = load i8*, i8** %3
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %35, %32
%39 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load i32, i32* @S_IXUSR
%42 = and i32 %40, %41
%43 = icmp eq i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %38
%45 = load i8*, i8** %3
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %50
47: ; preds = %38
%48 = load i8*, i8** %3
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %47, %44
%51 = load i8*, i8** %3
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %12
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@.str.1 = [10 x i8] c"Reading, \00"
@.str.2 = [14 x i8] c"Not reading, \00"
@S_IWUSR = global i32 0
@.str.3 = [10 x i8] c"Writing, \00"
@.str.4 = [14 x i8] c"Not writing, \00"
@S_IXUSR = global i32 0
@.str.5 = [10 x i8] c"Executing\00"
@.str.6 = [14 x i8] c"Not executing\00"
@str = [28 x i8] c"Error, file does not exists\00"
define void @sp(i8* %0) {
%2 = alloca %struct.stat
%3 = tail call i64 @malloc(i32 1024)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i32 1024)
%6 = bitcast %struct.stat* %2 to i8*
%7 = call i64 @stat(i8* %0, %struct.stat* %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @S_IRUSR
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0)
%16 = call i32 @strcat(i8* %4, i8* %15)
%17 = load i32, i32* %10
%18 = load i32, i32* @S_IWUSR
%19 = and i32 %18, %17
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
%22 = call i32 @strcat(i8* %4, i8* %21)
%23 = load i32, i32* %10
%24 = load i32, i32* @S_IXUSR
%25 = and i32 %24, %23
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0)
%28 = call i32 @strcat(i8* %4, i8* %27)
br label %29
29: ; preds = %1, %9
%30 = phi i8* [ %4, %9 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0), %1 ]
%31 = call i32 @puts(i8* dereferenceable(1) %30)
ret void
}