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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int open(char *, int /*<<< orphan*/);
int stat(char *, struct stat *);
int /*<<< orphan*/ test_execv();
int /*<<< orphan*/ test_spawn();
int /*<<< orphan*/ test_subprocess();
int /*<<< orphan*/ test_system();
int main(int argc, char *argv[]) {
  FILE *testfp;
  int testfd;
  struct stat testsb;
  testfp = fopen("/foo/bar/test", "r");
  assert(testfp != NULL);
  fclose(testfp);
  testfd = open("/foo/bar/test", O_RDONLY);
  assert(testfd != -1);
  close(testfd);
  assert(access("/foo/bar/test", X_OK) == 0);
  assert(stat("/foo/bar/test", &testsb) != -1);
  test_spawn();
  test_system();
  if (argc == 1) {
    test_subprocess();
  }
  test_execv();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe33(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xdf8(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    0xdc7(%rip),%rdi
call   10c0 <access@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xdaa(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1080 <test_spawn@plt>
mov    $0x0,%al
call   1090 <test_system@plt>
cmpl   $0x1,-0x8(%rbp)
jne    128e <main+0xde>
mov    $0x0,%al
call   1070 <test_subprocess@plt>
mov    $0x0,%al
call   10a0 <test_execv@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0xe3e(%rip),%rbx
lea    0xe45(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1050 <assert@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <access@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1050 <assert@plt>
xor    %eax,%eax
call   1080 <test_spawn@plt>
xor    %eax,%eax
call   1090 <test_system@plt>
cmp    $0x1,%r14d
jne    1267 <main+0xb7>
xor    %eax,%eax
call   1070 <test_subprocess@plt>
xor    %eax,%eax
call   10a0 <test_execv@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [14 x i8] c"/foo/bar/test\00"
@.str.1 = [2 x i8] c"r\00"
@O_RDONLY = global i32 0
@X_OK = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32*, i32** %6
%15 = call i32 @fclose(i32* %14)
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, -1
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %7
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* @X_OK
%25 = call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.stat* %8)
%30 = icmp ne i32 %29, -1
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 (...) @test_spawn()
%34 = call i32 (...) @test_system()
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %2
%38 = call i32 (...) @test_subprocess()
br label %39
39: ; preds = %37, %2
%40 = call i32 (...) @test_execv()
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [14 x i8] c"/foo/bar/test\00"
@.str.1 = [2 x i8] c"r\00"
@O_RDONLY = global i32 0
@X_OK = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp ne i32* %5, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @fclose(i32* %5)
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp ne i32 %11, -1
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @close(i32 %11)
%16 = load i32, i32* @X_OK
%17 = tail call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = call i32 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%22 = icmp ne i32 %21, -1
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 (...) @test_spawn()
%26 = tail call i32 (...) @test_system()
%27 = icmp eq i32 %0, 1
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = tail call i32 (...) @test_subprocess()
br label %30
30: ; preds = %28, %2
%31 = tail call i32 (...) @test_execv()
ret i32 0
}