#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 /*<<< orphan*/ path;

/* Variables and functions */
int MAXPATHLEN;
int WEXITSTATUS(int);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int waitpid(int, int *, int /*<<< orphan*/);
int run(const char *p1, const char *p2) {
  char path[MAXPATHLEN];
  int rv;
  char *argv[2];
  int status;
  rv = snprintf(path, sizeof(path), "%s/%s", p1, p2);
  assert(rv < sizeof(path));
  argv[0] = path;
  argv[1] = NULL;
  rv = fork();
  if (rv == -1) {
    perror("fork");
    abort();
  }
  if (rv == 0) {
    execvp(argv[0], argv);
    perror("execvp");
    abort();
  } else {
    rv = waitpid(rv, &status, 0);
    if (rv == -1) {
      perror("waitpid");
      abort();
    }
    if (WEXITSTATUS(status) != 0) {
      fprintf(stderr, "Process for \"%s\" exited with %d\n", path,
              WEXITSTATUS(status));
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe1f(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x58(%rbp),%rcx
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    %rcx,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1238 <run+0xa8>
lea    0xdda(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    1262 <run+0xd2>
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <execvp@plt>
lea    0xdb5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x2c(%rbp),%edi
lea    -0x44(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1290 <run+0x100>
lea    0xd8e(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x44(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     12dd <run+0x14d>
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x44(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    -0x5c(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %eax,%ecx
lea    0xd55(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    12f0 <run+0x160>
jmp    12e2 <run+0x152>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r8
mov    %rdi,%rcx
mov    0x2e3e(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r15
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe3c(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <snprintf@plt>
cltq
xor    %edi,%edi
cmp    %rbx,%rax
setb   %dil
call   1050 <assert@plt>
mov    %r15,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1253 <run+0xc3>
cmp    $0xffffffff,%eax
je     1268 <run+0xd8>
lea    -0x1c(%rbp),%rsi
xor    %r14d,%r14d
mov    %eax,%edi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0xffffffff,%eax
je     1271 <run+0xe1>
mov    -0x1c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
test   %eax,%eax
je     1245 <run+0xb5>
mov    0x2db6(%rip),%rax
mov    (%rax),%ebx
mov    -0x1c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
lea    0xde7(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %eax,%ecx
call   1060 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    -0x30(%rbp),%rsi
mov    %r15,%rdi
call   10a0 <execvp@plt>
lea    0xda5(%rip),%rdi
jmp    1278 <run+0xe8>
lea    0xd97(%rip),%rdi
jmp    1278 <run+0xe8>
lea    0xd9a(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [7 x i8] c"execvp\00"
@.str.3 = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"Process for \22%s\22 exited with %d\0A\00"
define i32 @run(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [2 x i8*]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i32, i32* @MAXPATHLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = trunc i64 %13 to i32
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 @snprintf(i8* %15, i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %21, %13
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
store i8* %15, i8** %25
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 1
store i8* null, i8** %26
%27 = call i32 (...) @fork()
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %2
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %2
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
%38 = load i8*, i8** %37
%39 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
%40 = call i32 @execvp(i8* %38, i8** %39)
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 (...) @abort()
unreachable
43: ; preds = %33
%44 = load i32, i32* %8
%45 = call i32 @waitpid(i32 %44, i32* %10, i32 0)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 (...) @abort()
unreachable
51: ; preds = %43
%52 = load i32, i32* %10
%53 = call i32 @WEXITSTATUS(i32 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = load i32, i32* %10
%58 = call i32 @WEXITSTATUS(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %15, i32 %58)
store i32 -1, i32* %3
store i32 1, i32* %11
br label %62
60: ; preds = %51
br label %61
61: ; preds = %60
store i32 0, i32* %3
store i32 1, i32* %11
br label %62
62: ; preds = %61, %55
%63 = load i8*, i8** %6
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [7 x i8] c"execvp\00"
@.str.3 = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"Process for \22%s\22 exited with %d\0A\00"
define i32 @run(i8* %0, i8* %1) {
%3 = alloca [2 x i8*]
%4 = alloca i32
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast [2 x i8*]* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%11 = sext i32 %10 to i64
%12 = icmp ult i64 %11, %6
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* %7, i8** %15
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* null, i8** %16
%17 = call i32 (...) @fork()
switch i32 %17, label %25 [
i32 -1, label %18
i32 0, label %21
]
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %2
%22 = call i32 @execvp(i8* %7, i8** %15)
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %2
%26 = call i32 @waitpid(i32 %17, i32* %4, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %25
%32 = load i32, i32* %4
%33 = call i32 @WEXITSTATUS(i32 %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i32, i32* %4
%38 = call i32 @WEXITSTATUS(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %7, i32 %38)
br label %40
40: ; preds = %31, %35
%41 = phi i32 [ -1, %35 ], [ 0, %31 ]
ret i32 %41
}