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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int WEXITSTATUS(int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ assert(char const *);
scalar_t__ closeall(int);
scalar_t__ errno;
int /*<<< orphan*/ execl(char const *, char const *, int /*<<< orphan*/ *);
int fork();
int waitpid(int, int *, int /*<<< orphan*/);
int executefile(const char *path) {
  assert(path);
  pid_t pid;
  if ((pid = fork())) {
    if (-1 == pid) {
      return (-1);
    }
    int status;
    while (-1 == waitpid(pid, &status, 0)) {
      if (EINTR != errno) {
        return (-1);
      }
    }
    return (WEXITSTATUS(status));
  }
  if (closeall(1)) {
    _exit(EXIT_FAILURE);
  }
  execl(path, path, NULL);
  _exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<executefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     120f <executefile+0x9f>
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    11b2 <executefile+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <executefile+0xe0>
jmp    11b7 <executefile+0x47>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ff <executefile+0x8f>
mov    0x2df5(%rip),%rax
mov    (%rax),%rax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%rax
je     11fa <executefile+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <executefile+0xe0>
jmp    11b7 <executefile+0x47>
mov    -0x18(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    1250 <executefile+0xe0>
mov    $0x1,%edi
call   1050 <closeall@plt>
cmp    $0x0,%rax
je     1231 <executefile+0xc1>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<executefile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <assert@plt>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11dc <executefile+0x6c>
test   %ebx,%ebx
je     11ea <executefile+0x7a>
lea    0x4(%rsp),%r14
mov    0x2e32(%rip),%r15
mov    0x2e3b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11d1 <executefile+0x61>
mov    (%r15),%rax
cmp    (%r12),%rax
je     11b0 <executefile+0x40>
mov    $0xffffffff,%ebx
jmp    11dc <executefile+0x6c>
mov    0x4(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1050 <closeall@plt>
test   %rax,%rax
jne    1206 <executefile+0x96>
mov    %r14,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@EINTR = global i64 0
@errno = global i64 0
@EXIT_FAILURE = global i32 0
define i32 @executefile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @assert(i8* %6)
%8 = call i32 (...) @fork()
store i32 %8, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp eq i32 -1, %11
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 -1, i32* %2
br label %40
14: ; preds = %10
br label %15
15: ; preds = %24, %14
%16 = load i32, i32* %4
%17 = call i32 @waitpid(i32 %16, i32* %5, i32 0)
%18 = icmp eq i32 -1, %17
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i64, i64* @EINTR
%21 = load i64, i64* @errno
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %2
br label %40
24: ; preds = %19
br label %15
25: ; preds = %15
%26 = load i32, i32* %5
%27 = call i32 @WEXITSTATUS(i32 %26)
store i32 %27, i32* %2
br label %40
28: ; preds = %1
%29 = call i64 @closeall(i32 1)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @_exit(i32 %32)
unreachable
34: ; preds = %28
%35 = load i8*, i8** %3
%36 = load i8*, i8** %3
%37 = call i32 @execl(i8* %35, i8* %36, i32* null)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @_exit(i32 %38)
unreachable
40: ; preds = %25, %23, %13
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@EINTR = global i64 0
@errno = global i64 0
@EXIT_FAILURE = global i32 0
define i32 @executefile(i8* %0) {
%2 = alloca i32
%3 = tail call i32 @assert(i8* %0)
%4 = tail call i32 (...) @fork()
switch i32 %4, label %5 [
i32 0, label %19
i32 -1, label %29
]
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
br label %7
7: ; preds = %10, %5
%8 = call i32 @waitpid(i32 %4, i32* %2, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i64, i64* @EINTR
%12 = load i64, i64* @errno
%13 = icmp eq i64 %11, %12
br i1 %13, label %7, label %17
14: ; preds = %7
%15 = load i32, i32* %2
%16 = call i32 @WEXITSTATUS(i32 %15)
br label %17
17: ; preds = %10, %14
%18 = phi i32 [ %16, %14 ], [ -1, %10 ]
br label %29
19: ; preds = %1
%20 = tail call i64 @closeall(i32 1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @_exit(i32 %23)
unreachable
25: ; preds = %19
%26 = tail call i32 @execl(i8* %0, i8* %0, i32* null)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @_exit(i32 %27)
unreachable
29: ; preds = %1, %17
%30 = phi i32 [ %18, %17 ], [ %4, %1 ]
ret i32 %30
}