#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 */
int /*<<< orphan*/ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int _finished(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ setenv(char *, char const *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int args, char **argv) {
  const char *val = NULL;
  pid_t pid;
  int status;
  int FAILURE = 6;
  if (args < 2) {
    fprintf(stderr, "Need args\n");
    return FAILURE;
  }
  pid = fork();
  if (pid == -1) {
    fprintf(stderr, "Could not fork\n");
    return FAILURE;
  } else if (pid == 0) {
    if (!strcmp(argv[0], "not"))
      val = ">1";
    else if (!strcmp(argv[0], "invalid"))
      val = "3";
    else if (!strcmp(argv[0], "fail"))
      val = "5";
    if (val)
      setenv("LVM_EXPECTED_EXIT_STATUS", val, 1);
    execvp(argv[1], &argv[1]);
    return FAILURE;
  } else {
    waitpid(pid, &status, 0);
    if (!WIFEXITED(status)) {
      if (WIFSIGNALED(status))
        fprintf(stderr, "Process %d died of signal %d.\n", pid,
                WTERMSIG(status));
      return FAILURE;
    }
    return _finished(argv[0], WEXITSTATUS(status), pid);
  }
  return FAILURE;
}


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)
movq   $0x0,-0x18(%rbp)
movl   $0x6,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1201 <main+0x51>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x1ea>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1237 <main+0x87>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x1ea>
cmpl   $0x0,-0x1c(%rbp)
jne    130a <main+0x15a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdcc(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    126d <main+0xbd>
lea    0xdbb(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    12ca <main+0x11a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xda7(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1299 <main+0xe9>
lea    0xd9a(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    12c5 <main+0x115>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd85(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12c0 <main+0x110>
lea    0xd75(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    12c5 <main+0x115>
jmp    12ca <main+0x11a>
cmpq   $0x0,-0x18(%rbp)
je     12ea <main+0x13a>
mov    -0x18(%rbp),%rsi
lea    0xd53(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10a0 <execvp@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x1ea>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x20(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    1376 <main+0x1c6>
mov    -0x20(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     136b <main+0x1bb>
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
lea    0xce8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x1ea>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   10c0 <_finished@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     11cf <main+0x1f>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
jmp    11f4 <main+0x44>
mov    %rsi,%rbx
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     1200 <main+0x50>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1250 <main+0xa0>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12f5 <main+0x145>
mov    (%rbx),%rbp
lea    0xe11(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1287 <main+0xd7>
lea    0xe05(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     12cd <main+0x11d>
lea    0xdf8(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    12e5 <main+0x135>
lea    0xde6(%rip),%rsi
jmp    12d4 <main+0x124>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    0xc(%rsp),%edi
call   10b0 <WIFEXITED@plt>
test   %eax,%eax
je     1290 <main+0xe0>
mov    (%rbx),%rbx
mov    0xc(%rsp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   10c0 <_finished@plt>
mov    %eax,%ebx
jmp    12fa <main+0x14a>
lea    0xd91(%rip),%rsi
jmp    12d4 <main+0x124>
mov    0xc(%rsp),%edi
call   1040 <WIFSIGNALED@plt>
mov    $0x6,%ebx
test   %rax,%rax
je     12fa <main+0x14a>
mov    0x2d36(%rip),%rax
mov    (%rax),%r14d
mov    0xc(%rsp),%edi
call   1070 <WTERMSIG@plt>
lea    0xd8f(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12fa <main+0x14a>
lea    0xd56(%rip),%rsi
lea    0xd58(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   10a0 <execvp@plt>
mov    $0x6,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"Need args\0A\00"
@.str.1 = [16 x i8] c"Could not fork\0A\00"
@.str.2 = [4 x i8] c"not\00"
@.str.3 = [3 x i8] c">1\00"
@.str.4 = [8 x i8] c"invalid\00"
@.str.5 = [2 x i8] c"3\00"
@.str.6 = [5 x i8] c"fail\00"
@.str.7 = [2 x i8] c"5\00"
@.str.8 = [25 x i8] c"LVM_EXPECTED_EXIT_STATUS\00"
@.str.9 = [31 x i8] c"Process %d died of signal %d.\0A\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
store i8* null, i8** %6
store i32 6, i32* %9
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %9
store i32 %15, i32* %3
br label %90
16: ; preds = %2
%17 = call i32 (...) @fork()
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %9
store i32 %23, i32* %3
br label %90
24: ; preds = %16
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %64
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %27
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %6
br label %50
34: ; preds = %27
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %34
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8** %6
br label %49
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %41
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8** %6
br label %48
48: ; preds = %47, %41
br label %49
49: ; preds = %48, %40
br label %50
50: ; preds = %49, %33
%51 = load i8*, i8** %6
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i8*, i8** %6
%55 = call i32 @setenv(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %54, i32 1)
br label %56
56: ; preds = %53, %50
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = call i32 @execvp(i8* %59, i8** %61)
%63 = load i32, i32* %9
store i32 %63, i32* %3
br label %90
64: ; preds = %24
%65 = load i32, i32* %7
%66 = call i32 @waitpid(i32 %65, i32* %8, i32 0)
%67 = load i32, i32* %8
%68 = call i32 @WIFEXITED(i32 %67)
%69 = icmp ne i32 %68, 0
br i1 %69, label %82, label %70
70: ; preds = %64
%71 = load i32, i32* %8
%72 = call i64 @WIFSIGNALED(i32 %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %70
%75 = load i32, i32* @stderr
%76 = load i32, i32* %7
%77 = load i32, i32* %8
%78 = call i32 @WTERMSIG(i32 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %76, i32 %78)
br label %80
80: ; preds = %74, %70
%81 = load i32, i32* %9
store i32 %81, i32* %3
br label %90
82: ; preds = %64
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 0
%85 = load i8*, i8** %84
%86 = load i32, i32* %8
%87 = call i32 @WEXITSTATUS(i32 %86)
%88 = load i32, i32* %7
%89 = call i32 @_finished(i8* %85, i32 %87, i32 %88)
store i32 %89, i32* %3
br label %90
90: ; preds = %82, %80, %56, %20, %12
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"Need args\0A\00"
@.str.1 = [16 x i8] c"Could not fork\0A\00"
@.str.2 = [4 x i8] c"not\00"
@.str.3 = [3 x i8] c">1\00"
@.str.4 = [8 x i8] c"invalid\00"
@.str.5 = [2 x i8] c"3\00"
@.str.6 = [5 x i8] c"fail\00"
@.str.7 = [2 x i8] c"5\00"
@.str.8 = [25 x i8] c"LVM_EXPECTED_EXIT_STATUS\00"
@.str.9 = [31 x i8] c"Process %d died of signal %d.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %50
9: ; preds = %2
%10 = tail call i32 (...) @fork()
switch i32 %10, label %31 [
i32 -1, label %11
i32 0, label %14
]
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %50
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18, %14, %21
%25 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), %21 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), %18 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %14 ]
%26 = tail call i32 @setenv(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %25, i32 1)
br label %27
27: ; preds = %24, %21
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = tail call i32 @execvp(i8* %29, i8** %28)
br label %50
31: ; preds = %9
%32 = call i32 @waitpid(i32 %10, i32* %3, i32 0)
%33 = load i32, i32* %3
%34 = call i32 @WIFEXITED(i32 %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %31
%37 = load i32, i32* %3
%38 = call i64 @WIFSIGNALED(i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i32, i32* %3
%43 = call i32 @WTERMSIG(i32 %42)
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %10, i32 %43)
br label %50
45: ; preds = %31
%46 = load i8*, i8** %1
%47 = load i32, i32* %3
%48 = call i32 @WEXITSTATUS(i32 %47)
%49 = call i32 @_finished(i8* %46, i32 %48, i32 %10)
br label %50
50: ; preds = %36, %40, %45, %27, %11, %6
%51 = phi i32 [ 6, %6 ], [ 6, %11 ], [ 6, %27 ], [ %49, %45 ], [ 6, %40 ], [ 6, %36 ]
ret i32 %51
}