#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);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *translate_hpc_bash_script(char *);
int waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char *tmp_script_file_name = NULL;
  int child_pid = -1;
  if (argc < 2) {
    fprintf(stderr, "Missing script file\n");
    exit((5));
  }
  if ((tmp_script_file_name = translate_hpc_bash_script(argv[1])) == NULL) {
    exit((5));
  }
  if ((child_pid = fork()) > 0) {
    int status = -1;
    if (waitpid(child_pid, &status, 0) == -1) {
      perror("waitpid() failed");
      exit((5));
    }
    if (WIFEXITED(status)) {
      exit(WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
      exit(128 + WTERMSIG(status));
    } else {
      fprintf(stderr, "Ilegall wait status = %d\n", status);
      exit((5));
    }
  } else if (child_pid == 0) {
    argv++;
    argc--;
    execv(tmp_script_file_name, argv);
    perror("execv() failed");
    exit(127);
  } else {
    perror("fork() failed");
  }
  return 1;
}


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)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1200 <main+0x50>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <translate_hpc_bash_script@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1225 <main+0x75>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12d8 <main+0x128>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0xbc>
lea    0xdb8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     128d <main+0xdd>
mov    -0x20(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12b4 <main+0x104>
mov    -0x20(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%edi
add    $0x80,%edi
call   10b0 <exit@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    131a <main+0x16a>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10c0 <execv@plt>
lea    0xd35(%rip),%rdi
call   1090 <perror@plt>
mov    $0x7f,%edi
call   10b0 <exit@plt>
lea    0xd2e(%rip),%rdi
call   1090 <perror@plt>
jmp    132b <main+0x17b>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    11f7 <main+0x47>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1030 <translate_hpc_bash_script@plt>
test   %rax,%rax
je     120e <main+0x5e>
mov    %rax,%r14
add    $0x8,%rbx
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
jg     1218 <main+0x68>
je     1249 <main+0x99>
lea    0xe6a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
movl   $0xffffffff,0x4(%rsp)
ff
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    126a <main+0xba>
lea    0xddb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <execv@plt>
lea    0xde5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x7f,%edi
call   10b0 <exit@plt>
mov    0x4(%rsp),%edi
call   10a0 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
jne    12ab <main+0xfb>
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
jne    12b7 <main+0x107>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x4(%rsp),%edx
lea    0xd8c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
call   1070 <WEXITSTATUS@plt>
mov    %eax,%edi
call   10b0 <exit@plt>
mov    0x4(%rsp),%edi
call   1060 <WTERMSIG@plt>
lea    0x80(%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Missing script file\0A\00"
@.str.1 = [17 x i8] c"waitpid() failed\00"
@.str.2 = [26 x i8] c"Ilegall wait status = %d\0A\00"
@.str.3 = [15 x i8] c"execv() failed\00"
@.str.4 = [14 x i8] c"fork() failed\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 -1, i32* %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 5)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i8* @translate_hpc_bash_script(i8* %18)
store i8* %19, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @exit(i32 5)
unreachable
23: ; preds = %15
%24 = call i32 (...) @fork()
store i32 %24, i32* %7
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %55
26: ; preds = %23
store i32 -1, i32* %8
%27 = load i32, i32* %7
%28 = call i32 @waitpid(i32 %27, i32* %8, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 5)
unreachable
33: ; preds = %26
%34 = load i32, i32* %8
%35 = call i64 @WIFEXITED(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* %8
%39 = call i32 @WEXITSTATUS(i32 %38)
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %33
%42 = load i32, i32* %8
%43 = call i64 @WIFSIGNALED(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = load i32, i32* %8
%47 = call i32 @WTERMSIG(i32 %46)
%48 = add nsw i32 128, %47
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %41
%51 = load i32, i32* @stderr
%52 = load i32, i32* %8
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = call i32 @exit(i32 5)
unreachable
55: ; preds = %23
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %55
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i32 1
store i8** %60, i8*** %5
%61 = load i32, i32* %4
%62 = add nsw i32 %61, -1
store i32 %62, i32* %4
%63 = load i8*, i8** %6
%64 = load i8**, i8*** %5
%65 = call i32 @execv(i8* %63, i8** %64)
%66 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%67 = call i32 @exit(i32 127)
unreachable
68: ; preds = %55
%69 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %68
br label %71
71: ; preds = %70
ret i32 1
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Missing script file\0A\00"
@.str.1 = [17 x i8] c"waitpid() failed\00"
@.str.2 = [26 x i8] c"Ilegall wait status = %d\0A\00"
@.str.3 = [15 x i8] c"execv() failed\00"
@.str.4 = [14 x i8] c"fork() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 5)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i8* @translate_hpc_bash_script(i8* %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @exit(i32 5)
unreachable
16: ; preds = %9
%17 = tail call i32 (...) @fork()
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %47
19: ; preds = %16
%20 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%21 = call i32 @waitpid(i32 %17, i32* %3, i32 0)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 5)
unreachable
26: ; preds = %19
%27 = load i32, i32* %3
%28 = call i64 @WIFEXITED(i32 %27)
%29 = icmp eq i64 %28, 0
%30 = load i32, i32* %3
br i1 %29, label %34, label %31
31: ; preds = %26
%32 = call i32 @WEXITSTATUS(i32 %30)
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
%35 = call i64 @WIFSIGNALED(i32 %30)
%36 = icmp eq i64 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %34
%38 = load i32, i32* %3
%39 = call i32 @WTERMSIG(i32 %38)
%40 = add nsw i32 %39, 128
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34
%43 = load i32, i32* @stderr
%44 = load i32, i32* %3
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 5)
unreachable
47: ; preds = %16
%48 = icmp eq i32 %17, 0
br i1 %48, label %49, label %53
49: ; preds = %47
%50 = tail call i32 @execv(i8* %12, i8** %10)
%51 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%52 = tail call i32 @exit(i32 127)
unreachable
53: ; preds = %47
%54 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
ret i32 1
}