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

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ execl(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stdout;
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char *tests[] = {"t40a", "t40b", "t40c", "t40d", "t40e", "t40f"};
  int no_tests, i, forkres, status = 0, errorct = 0;
  no_tests = sizeof(tests) / sizeof(char *);
  printf("Test 40 ");
  fflush(stdout);
  for (i = 0; i < no_tests; i++) {
    char subtest[2];
    sprintf(subtest, "%d", i + 1);
    forkres = fork();
    if (forkres == 0) {
      execl(tests[i], tests[i], subtest, (char *)0);
      printf("Failed to execute subtest %s\n", tests[i]);
      exit(-2);
    } else if (forkres > 0) {
      if (waitpid(forkres, &status, 0) > 0 && WEXITSTATUS(status) < 20) {
        errorct += WEXITSTATUS(status);
      }
      status = 0;
    } else {
      printf("Failed to fork\n");
      exit(-2);
    }
  }
  if (errorct == 0) {
    printf("ok\n");
    exit(0);
  } else {
    printf("%d error(s)\n", errorct);
    exit(1);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    0xe43(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe37(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe31(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe2b(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe25(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x6,-0x44(%rbp)
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1323 <main+0x193>
lea    -0x56(%rbp),%rdi
mov    -0x48(%rbp),%edx
add    $0x1,%edx
lea    0xdda(%rip),%rsi
call   1080 <sprintf@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    12a6 <main+0x116>
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
lea    -0x56(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   10a0 <execl@plt>
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xfffffffe,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x4c(%rbp)
jle    12f3 <main+0x163>
mov    -0x4c(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
cmp    $0x0,%rax
jle    12e7 <main+0x157>
mov    -0x50(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x14,%eax
jge    12e7 <main+0x157>
mov    -0x50(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x50(%rbp)
jmp    130b <main+0x17b>
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xfffffffe,%edi
call   1090 <exit@plt>
jmp    1310 <main+0x180>
jmp    1315 <main+0x185>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1230 <main+0xa0>
cmpl   $0x0,-0x54(%rbp)
jne    1342 <main+0x1b2>
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x54(%rbp),%esi
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
lea    0xe5d(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe56(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe4f(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe48(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe41(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe3a(%rip),%rax
mov    %rax,0x38(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xe18(%rip),%r14
lea    0xe(%rsp),%r15
lea    0x8(%rsp),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1235 <main+0xa5>
nop
movl   $0x0,0x8(%rsp)
add    $0x1,%rbx
cmp    $0x6,%ebx
je     12c4 <main+0x134>
lea    0x1(%rbx),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <sprintf@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     127c <main+0xec>
jle    12ae <main+0x11e>
mov    %eax,%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
test   %rax,%rax
jle    1220 <main+0x90>
mov    0x8(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x13,%eax
jg     1220 <main+0x90>
mov    0x8(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
add    %eax,%ebp
jmp    1220 <main+0x90>
mov    0x10(%rsp,%rbx,8),%rbx
lea    0xe(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   10a0 <execl@plt>
lea    0xd90(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   1090 <exit@plt>
lea    0xda3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%edi
call   1090 <exit@plt>
test   %ebp,%ebp
jne    12db <main+0x14b>
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xd66(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"t40a\00"
@.str.1 = [5 x i8] c"t40b\00"
@.str.2 = [5 x i8] c"t40c\00"
@.str.3 = [5 x i8] c"t40d\00"
@.str.4 = [5 x i8] c"t40e\00"
@.str.5 = [5 x i8] c"t40f\00"
@.str.6 = [9 x i8] c"Test 40 \00"
@stdout = global i32 0
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [30 x i8] c"Failed to execute subtest %s\0A\00"
@.str.9 = [16 x i8] c"Failed to fork\0A\00"
@.str.10 = [4 x i8] c"ok\0A\00"
@.str.11 = [13 x i8] c"%d error(s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [6 x i8*]* %6 to i8*
%14 = bitcast i8* %13 to [6 x i8*]*
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i32 0, i32 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i32 0, i32 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i32 0, i32 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i32 0, i32 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i32 0, i32 5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8** %20
store i32 0, i32* %10
store i32 0, i32* %11
store i32 6, i32* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
store i32 0, i32* %8
br label %24
24: ; preds = %75, %2
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %78
28: ; preds = %24
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %31)
%33 = call i32 (...) @fork()
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %53
36: ; preds = %28
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 %42
%44 = load i8*, i8** %43
%45 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%46 = call i32 @execl(i8* %40, i8* %44, i8* %45, i8* null)
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 -2)
unreachable
53: ; preds = %28
%54 = load i32, i32* %9
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %70
56: ; preds = %53
%57 = load i32, i32* %9
%58 = call i64 @waitpid(i32 %57, i32* %10, i32 0)
%59 = icmp sgt i64 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load i32, i32* %10
%62 = call i32 @WEXITSTATUS(i32 %61)
%63 = icmp slt i32 %62, 20
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = load i32, i32* %10
%66 = call i32 @WEXITSTATUS(i32 %65)
%67 = load i32, i32* %11
%68 = add nsw i32 %67, %66
store i32 %68, i32* %11
br label %69
69: ; preds = %64, %60, %56
store i32 0, i32* %10
br label %73
70: ; preds = %53
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%72 = call i32 @exit(i32 -2)
unreachable
73: ; preds = %69
br label %74
74: ; preds = %73
br label %75
75: ; preds = %74
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %24
78: ; preds = %24
%79 = load i32, i32* %11
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%83 = call i32 @exit(i32 0)
unreachable
84: ; preds = %78
%85 = load i32, i32* %11
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %85)
%87 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"t40a\00"
@.str.1 = [5 x i8] c"t40b\00"
@.str.2 = [5 x i8] c"t40c\00"
@.str.3 = [5 x i8] c"t40d\00"
@.str.4 = [5 x i8] c"t40e\00"
@.str.5 = [5 x i8] c"t40f\00"
@.str.6 = [9 x i8] c"Test 40 \00"
@stdout = global i32 0
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [30 x i8] c"Failed to execute subtest %s\0A\00"
@.str.11 = [13 x i8] c"%d error(s)\0A\00"
@str = [3 x i8] c"ok\00"
@str.12 = [15 x i8] c"Failed to fork\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [6 x i8*]
%4 = alloca i32
%5 = alloca [2 x i8]
%6 = bitcast [6 x i8*]* %3 to i8*
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %12
%13 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = tail call i32 @fflush(i32 %15)
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
br label %18
18: ; preds = %2, %45
%19 = phi i32 [ 0, %2 ], [ %46, %45 ]
%20 = phi i32 [ 0, %2 ], [ %21, %45 ]
%21 = add nuw nsw i32 %20, 1
%22 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %21)
%23 = call i32 (...) @fork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = zext i32 %20 to i64
%27 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @execl(i8* %28, i8* %28, i8* %17, i8* null)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %28)
%31 = call i32 @exit(i32 -2)
unreachable
32: ; preds = %18
%33 = icmp sgt i32 %23, 0
br i1 %33, label %34, label %48
34: ; preds = %32
%35 = call i64 @waitpid(i32 %23, i32* %4, i32 0)
%36 = icmp sgt i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i32, i32* %4
%39 = call i32 @WEXITSTATUS(i32 %38)
%40 = icmp slt i32 %39, 20
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %4
%43 = call i32 @WEXITSTATUS(i32 %42)
%44 = add nsw i32 %43, %19
br label %45
45: ; preds = %41, %37, %34
%46 = phi i32 [ %44, %41 ], [ %19, %37 ], [ %19, %34 ]
store i32 0, i32* %4
%47 = icmp eq i32 %21, 6
br i1 %47, label %51, label %18
48: ; preds = %32
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%50 = call i32 @exit(i32 -2)
unreachable
51: ; preds = %45
%52 = icmp eq i32 %46, 0
br i1 %52, label %53, label %56
53: ; preds = %51
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %51
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %46)
%58 = call i32 @exit(i32 1)
unreachable
}