#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ EPERM;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ EXIT_SUCCESS;
scalar_t__ WEXITSTATUS(int);
scalar_t__ errno;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, char *, int, char *, char *);
char *strdup(char const *);
char *strerror(scalar_t__);
int waitpid(scalar_t__, int *, int /*<<< orphan*/);
int test_file_exe_access(const char *path) {
  int status;
  char *args[2];
  pid_t pid = fork();
  if (pid < 0)
    do {
      printf("\x1b[31m"
             "%s:%d: %s: %s\n"
             "\x1b[0m",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Havner/ltp/refs/heads/smack-ns/"
             "testcases/kernel/security/smack/ns/smack_ns_tc_file_access.c",
             104, "fork", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (pid == 0) {
    args[0] = strdup(path);
    args[1] = NULL;
    execv(args[0], args);
    exit(EXIT_FAILURE);
  }
  if (waitpid(pid, &status, 0) == -1)
    do {
      printf("\x1b[31m"
             "%s:%d: %s: %s\n"
             "\x1b[0m",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Havner/ltp/refs/heads/smack-ns/"
             "testcases/kernel/security/smack/ns/smack_ns_tc_file_access.c",
             114, "waitpid", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (WEXITSTATUS(status) != EXIT_SUCCESS) {
    errno = EPERM;
    return -1;
  }
  errno = 0;
  return 0;
}


x86 assembly (clang, -O0):
<test_file_exe_access>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    11e6 <test_file_exe_access+0x66>
jmp    11a7 <test_file_exe_access+0x27>
mov    0x2e32(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    %rax,%r8
lea    0xe40(%rip),%rdi
lea    0xe51(%rip),%rsi
mov    $0x68,%edx
lea    0xefb(%rip),%rcx
call   1030 <printf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
jne    1221 <test_file_exe_access+0xa1>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <execv@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x38(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    127d <test_file_exe_access+0xfd>
jmp    123e <test_file_exe_access+0xbe>
mov    0x2d9b(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    %rax,%r8
lea    0xda9(%rip),%rdi
lea    0xdba(%rip),%rsi
mov    $0x72,%edx
lea    0xe69(%rip),%rcx
call   1030 <printf@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    0x2d44(%rip),%rcx
cmp    (%rcx),%rax
je     12b5 <test_file_exe_access+0x135>
mov    0x2d24(%rip),%rax
mov    (%rax),%rcx
mov    0x2d3a(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12ca <test_file_exe_access+0x14a>
mov    0x2d24(%rip),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file_exe_access>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     11ea <test_file_exe_access+0x6a>
je     1215 <test_file_exe_access+0x95>
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
je     1237 <test_file_exe_access+0xb7>
mov    (%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %rax,%rcx
mov    0x2e12(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
setne  %cl
je     11d4 <test_file_exe_access+0x54>
mov    0x2df1(%rip),%rdx
mov    (%rdx),%rdx
jmp    11d6 <test_file_exe_access+0x56>
xor    %edx,%edx
mov    %cl,%al
neg    %eax
mov    0x2dff(%rip),%rcx
mov    %rdx,(%rcx)
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2def(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xe00(%rip),%rdi
lea    0xe11(%rip),%rsi
lea    0xec0(%rip),%rcx
mov    $0x68,%edx
jmp    1260 <test_file_exe_access+0xe0>
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
mov    %rax,%rdi
call   1090 <execv@plt>
jmp    1268 <test_file_exe_access+0xe8>
mov    0x2da2(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xdb3(%rip),%rdi
lea    0xdc4(%rip),%rsi
lea    0xe78(%rip),%rcx
mov    $0x72,%edx
mov    %rax,%r8
call   1030 <printf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"\1B[31m%s:%d: %s: %s\0A\1B[0m\00"
@.str.1 = [182 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Havner/ltp/refs/heads/smack-ns/testcases/kernel/security/smack/ns/smack_ns_tc_file_access.c\00"
@.str.2 = [5 x i8] c"fork\00"
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str.3 = [8 x i8] c"waitpid\00"
@EXIT_SUCCESS = global i64 0
@EPERM = global i64 0
define i32 @test_file_exe_access(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [2 x i8*]
%6 = alloca i64
store i8* %0, i8** %3
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %1
br label %11
11: ; preds = %10
%12 = load i64, i64* @errno
%13 = call i8* @strerror(i64 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; No predecessors!
br label %18
18: ; preds = %17, %1
%19 = load i64, i64* %6
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = call i8* @strdup(i8* %22)
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
store i8* %23, i8** %24
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 1
store i8* null, i8** %25
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%29 = call i32 @execv(i8* %27, i8** %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %18
%33 = load i64, i64* %6
%34 = call i32 @waitpid(i64 %33, i32* %4, i32 0)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %44
36: ; preds = %32
br label %37
37: ; preds = %36
%38 = load i64, i64* @errno
%39 = call i8* @strerror(i64 %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 114, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; No predecessors!
br label %44
44: ; preds = %43, %32
%45 = load i32, i32* %4
%46 = call i64 @WEXITSTATUS(i32 %45)
%47 = load i64, i64* @EXIT_SUCCESS
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = load i64, i64* @EPERM
store i64 %50, i64* @errno
store i32 -1, i32* %2
br label %52
51: ; preds = %44
store i64 0, i64* @errno
store i32 0, i32* %2
br label %52
52: ; preds = %51, %49
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [24 x i8] c"\1B[31m%s:%d: %s: %s\0A\1B[0m\00"
@.str.1 = [182 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Havner/ltp/refs/heads/smack-ns/testcases/kernel/security/smack/ns/smack_ns_tc_file_access.c\00"
@.str.2 = [5 x i8] c"fork\00"
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str.3 = [8 x i8] c"waitpid\00"
@EXIT_SUCCESS = global i64 0
@EPERM = global i64 0
define i32 @test_file_exe_access(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca [2 x i8*]
%4 = bitcast i32* %2 to i8*
%5 = bitcast [2 x i8*]* %3 to i8*
%6 = tail call i64 (...) @fork()
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = tail call i8* @strerror(i64 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = icmp eq i64 %6, 0
br i1 %15, label %16, label %23
16: ; preds = %14
%17 = tail call i8* @strdup(i8* %0)
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* %17, i8** %18
%19 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* null, i8** %19
%20 = call i32 @execv(i8* %17, i8** %18)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = call i32 @waitpid(i64 %6, i32* %2, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = call i8* @strerror(i64 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 114, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %23
%33 = load i32, i32* %2
%34 = call i64 @WEXITSTATUS(i32 %33)
%35 = load i64, i64* @EXIT_SUCCESS
%36 = icmp eq i64 %34, %35
%37 = load i64, i64* @EPERM
%38 = select i1 %36, i64 0, i64 %37
%39 = xor i1 %36, true
%40 = sext i1 %39 to i32
store i64 %38, i64* @errno
ret i32 %40
}