#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 */

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int WTERMSIG(int);
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ errx(int, char *, char const *, int);
int /*<<< orphan*/ execl(char *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
char *strrchr(char *, char);
char *strsignal(int);
int vfork();
int wait(int *);
int main(int argc, char **argv) {
  const char *name = strrchr(*++argv, '/');
  if (!name)
    name = *argv;
  else
    name += 1;
  switch (vfork()) {
  case -1:
    err(1, "forking");
  case 0:
    execl(*argv, name, NULL);
    _exit(212);
  }
  int status;
  while (wait(&status) == -1)
    ;
  if (WIFEXITED(status)) {
    int code = WEXITSTATUS(status);
    if (code)
      errx(code, "%s exited with non-zero code %i", name, code);
  } else {
    int sig = WTERMSIG(status);
    fprintf(stderr, "%s killed by signal %s", name, strsignal(sig));
    kill(getpid(), sig);
  }
  name = strrchr(*++argv, '/');
  if (!name)
    name = *argv;
  else
    name += 1;
  execl(*argv, name, NULL);
  err(212, "executing %s", name);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1232 <main+0x52>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    123e <main+0x5e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
call   10d0 <vfork@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
sub    $0xffffffff,%eax
je     1266 <main+0x86>
jmp    1256 <main+0x76>
mov    -0x28(%rbp),%eax
test   %eax,%eax
je     1279 <main+0x99>
jmp    1297 <main+0xb7>
mov    $0x1,%edi
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10f0 <execl@plt>
mov    $0xd4,%edi
call   1030 <_exit@plt>
jmp    129c <main+0xbc>
lea    -0x1c(%rbp),%rdi
call   1100 <wait@plt>
cmp    $0xffffffff,%eax
jne    12b3 <main+0xd3>
jmp    129c <main+0xbc>
mov    -0x1c(%rbp),%edi
call   10e0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12f5 <main+0x115>
mov    -0x1c(%rbp),%edi
call   10c0 <WEXITSTATUS@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12f0 <main+0x110>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
lea    0xd1d(%rip),%rsi
call   1050 <errx@plt>
jmp    1343 <main+0x163>
mov    -0x1c(%rbp),%edi
call   10a0 <WTERMSIG@plt>
mov    %eax,-0x24(%rbp)
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   10b0 <strsignal@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xcfb(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    -0x24(%rbp),%esi
call   1080 <kill@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    137f <main+0x19f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    138b <main+0x1ab>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10f0 <execl@plt>
mov    -0x18(%rbp),%rdx
mov    $0xd4,%edi
lea    0xc90(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    $0x2f,%esi
mov    %rbx,%rdi
call   1060 <strrchr@plt>
lea    0x1(%rax),%r15
test   %rax,%rax
cmove  %rbx,%r15
call   10d0 <vfork@plt>
test   %eax,%eax
je     130d <main+0x12d>
cmp    $0xffffffff,%eax
je     12fa <main+0x11a>
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1100 <wait@plt>
cmp    $0xffffffff,%eax
je     1230 <main+0x50>
mov    0x4(%rsp),%edi
call   10e0 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     126d <main+0x8d>
call   10c0 <WEXITSTATUS@plt>
test   %eax,%eax
je     12a8 <main+0xc8>
mov    %eax,%ecx
lea    0xda7(%rip),%rsi
mov    %eax,%edi
mov    %r15,%rdx
call   1050 <errx@plt>
jmp    12a8 <main+0xc8>
call   10a0 <WTERMSIG@plt>
mov    %eax,%ebx
mov    0x2d65(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   10b0 <strsignal@plt>
lea    0xd9d(%rip),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%edi
mov    %ebx,%esi
call   1080 <kill@plt>
mov    0x10(%r14),%rbx
mov    $0x2f,%esi
mov    %rbx,%rdi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rbp
test   %rax,%rax
cmove  %rbx,%rbp
xor    %r14d,%r14d
mov    %r14d,%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <execl@plt>
lea    0xd63(%rip),%rsi
mov    %r14d,%eax
mov    $0xd4,%edi
mov    %rbp,%rdx
call   1090 <err@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcff(%rip),%rsi
xor    %eax,%eax
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x8(%r14),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %r15,%rsi
call   10f0 <execl@plt>
mov    $0xd4,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"forking\00"
@.str.1 = [32 x i8] c"%s exited with non-zero code %i\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s killed by signal %s\00"
@.str.3 = [13 x i8] c"executing %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i32 1
store i8** %11, i8*** %5
%12 = load i8*, i8** %11
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
store i8* %18, i8** %6
br label %22
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %6
br label %22
22: ; preds = %19, %16
%23 = call i32 @vfork()
switch i32 %23, label %32 [
i32 -1, label %24
i32 0, label %26
]
24: ; preds = %22
%25 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %22, %24
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = load i8*, i8** %6
%30 = call i32 @execl(i8* %28, i8* %29, i32* null)
%31 = call i32 @_exit(i32 212)
unreachable
32: ; preds = %22
br label %33
33: ; preds = %36, %32
%34 = call i32 @wait(i32* %7)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %33
br label %33
37: ; preds = %33
%38 = load i32, i32* %7
%39 = call i64 @WIFEXITED(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %52
41: ; preds = %37
%42 = load i32, i32* %7
%43 = call i32 @WEXITSTATUS(i32 %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = load i32, i32* %8
%48 = load i8*, i8** %6
%49 = load i32, i32* %8
%50 = call i32 @errx(i32 %47, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %48, i32 %49)
br label %51
51: ; preds = %46, %41
br label %63
52: ; preds = %37
%53 = load i32, i32* %7
%54 = call i32 @WTERMSIG(i32 %53)
store i32 %54, i32* %9
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %6
%57 = load i32, i32* %9
%58 = call i8* @strsignal(i32 %57)
%59 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %56, i8* %58)
%60 = call i32 (...) @getpid()
%61 = load i32, i32* %9
%62 = call i32 @kill(i32 %60, i32 %61)
br label %63
63: ; preds = %52, %51
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i32 1
store i8** %65, i8*** %5
%66 = load i8*, i8** %65
%67 = call i8* @strrchr(i8* %66, i8 signext 47)
store i8* %67, i8** %6
%68 = load i8*, i8** %6
%69 = icmp ne i8* %68, null
br i1 %69, label %73, label %70
70: ; preds = %63
%71 = load i8**, i8*** %5
%72 = load i8*, i8** %71
store i8* %72, i8** %6
br label %76
73: ; preds = %63
%74 = load i8*, i8** %6
%75 = getelementptr inbounds i8, i8* %74, i64 1
store i8* %75, i8** %6
br label %76
76: ; preds = %73, %70
%77 = load i8**, i8*** %5
%78 = load i8*, i8** %77
%79 = load i8*, i8** %6
%80 = call i32 @execl(i8* %78, i8* %79, i32* null)
%81 = load i8*, i8** %6
%82 = call i32 (i32, i8*, ...) @err(i32 212, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %81)
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [8 x i8] c"forking\00"
@.str.1 = [32 x i8] c"%s exited with non-zero code %i\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s killed by signal %s\00"
@.str.3 = [13 x i8] c"executing %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 47)
%7 = icmp eq i8* %6, null
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = select i1 %7, i8* %5, i8* %8
%10 = call i32 @vfork()
switch i32 %10, label %17 [
i32 -1, label %11
i32 0, label %13
]
11: ; preds = %2
%12 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %2, %11
%14 = load i8*, i8** %4
%15 = call i32 @execl(i8* %14, i8* %9, i32* null)
%16 = call i32 @_exit(i32 212)
unreachable
17: ; preds = %2
%18 = bitcast i32* %3 to i8*
br label %19
19: ; preds = %19, %17
%20 = call i32 @wait(i32* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %19, label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = call i64 @WIFEXITED(i32 %23)
%25 = icmp eq i64 %24, 0
%26 = load i32, i32* %3
br i1 %25, label %32, label %27
27: ; preds = %22
%28 = call i32 @WEXITSTATUS(i32 %26)
%29 = icmp eq i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %27
%31 = call i32 @errx(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %28)
br label %39
32: ; preds = %22
%33 = call i32 @WTERMSIG(i32 %26)
%34 = load i32, i32* @stderr
%35 = call i8* @strsignal(i32 %33)
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %35)
%37 = call i32 (...) @getpid()
%38 = call i32 @kill(i32 %37, i32 %33)
br label %39
39: ; preds = %27, %30, %32
%40 = getelementptr inbounds i8*, i8** %1, i64 2
%41 = load i8*, i8** %40
%42 = call i8* @strrchr(i8* dereferenceable(1) %41, i8 signext 47)
%43 = icmp eq i8* %42, null
%44 = getelementptr inbounds i8, i8* %42, i64 1
%45 = select i1 %43, i8* %41, i8* %44
%46 = call i32 @execl(i8* %41, i8* %45, i32* null)
%47 = call i32 (i32, i8*, ...) @err(i32 212, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %45)
ret i32 0
}