#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 /*<<< orphan*/ barf(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fdpair(int *);
int fork();
int /*<<< orphan*/ receiver(int, int, int, int);
int /*<<< orphan*/ sender(int *, int, int);
unsigned int group(int ready_out, int wakefd) {
  unsigned int i;
  int out_fds[20];
  for (i = 0; i < 20; i++) {
    int fds[2];
    fdpair(fds);
    switch (fork()) {
    case -1:
      barf("fork()");
    case 0:
      close(fds[1]);
      receiver(20 * 100, fds[0], ready_out, wakefd);
      exit(0);
    }
    out_fds[i] = fds[1];
    close(fds[0]);
  }
  for (i = 0; i < 20; i++) {
    switch (fork()) {
    case -1:
      barf("fork()");
    case 0:
      sender(out_fds, ready_out, wakefd);
      exit(0);
    }
  }
  for (i = 0; i < 20; i++)
    close(out_fds[i]);
  return 20 * 2;
}


x86 assembly (clang, -O0):
<group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jae    1210 <group+0xa0>
lea    -0x68(%rbp),%rdi
call   1060 <fdpair@plt>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x6c(%rbp)
sub    $0xffffffff,%eax
je     11c2 <group+0x52>
jmp    11b2 <group+0x42>
mov    -0x6c(%rbp),%eax
test   %eax,%eax
je     11ce <group+0x5e>
jmp    11f0 <group+0x80>
lea    0xe37(%rip),%rdi
call   1030 <barf@plt>
mov    -0x64(%rbp),%edi
call   1040 <close@plt>
mov    -0x68(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    $0x7d0,%edi
call   1050 <receiver@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x64(%rbp),%ecx
mov    -0xc(%rbp),%eax
mov    %ecx,-0x60(%rbp,%rax,4)
mov    -0x68(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1185 <group+0x15>
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jae    1280 <group+0x110>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x70(%rbp)
sub    $0xffffffff,%eax
je     124b <group+0xdb>
jmp    123b <group+0xcb>
mov    -0x70(%rbp),%eax
test   %eax,%eax
je     1257 <group+0xe7>
jmp    126d <group+0xfd>
lea    0xdae(%rip),%rdi
call   1030 <barf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <sender@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1272 <group+0x102>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1217 <group+0xa7>
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jae    12ab <group+0x13b>
mov    -0xc(%rbp),%eax
mov    -0x60(%rbp,%rax,4),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1287 <group+0x117>
mov    $0x28,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<group>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x8(%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <fdpair@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     147b <group+0x30b>
cmp    $0xffffffff,%eax
je     146f <group+0x2ff>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%eax
mov    %eax,0x10(%rsp,%rbp,4)
call   1040 <close@plt>
add    $0x1,%rbp
cmp    $0x14,%rbp
jne    1190 <group+0x20>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     14ab <group+0x33b>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     149f <group+0x32f>
test   %eax,%eax
je     14ab <group+0x33b>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
mov    0x18(%rsp),%edi
call   1040 <close@plt>
mov    0x1c(%rsp),%edi
call   1040 <close@plt>
mov    0x20(%rsp),%edi
call   1040 <close@plt>
mov    0x24(%rsp),%edi
call   1040 <close@plt>
mov    0x28(%rsp),%edi
call   1040 <close@plt>
mov    0x2c(%rsp),%edi
call   1040 <close@plt>
mov    0x30(%rsp),%edi
call   1040 <close@plt>
mov    0x34(%rsp),%edi
call   1040 <close@plt>
mov    0x38(%rsp),%edi
call   1040 <close@plt>
mov    0x3c(%rsp),%edi
call   1040 <close@plt>
mov    0x40(%rsp),%edi
call   1040 <close@plt>
mov    0x44(%rsp),%edi
call   1040 <close@plt>
mov    0x48(%rsp),%edi
call   1040 <close@plt>
mov    0x4c(%rsp),%edi
call   1040 <close@plt>
mov    0x50(%rsp),%edi
call   1040 <close@plt>
mov    0x54(%rsp),%edi
call   1040 <close@plt>
mov    0x58(%rsp),%edi
call   1040 <close@plt>
mov    0x5c(%rsp),%edi
call   1040 <close@plt>
mov    $0x28,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb8a(%rip),%rdi
call   1030 <barf@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%esi
mov    $0x7d0,%edi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1050 <receiver@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xb5a(%rip),%rdi
call   1030 <barf@plt>
lea    0x10(%rsp),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1070 <sender@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"fork()\00"
define i32 @group(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [20 x i32]
%7 = alloca [2 x i32]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %36, %2
%9 = load i32, i32* %5
%10 = icmp ult i32 %9, 20
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%13 = call i32 @fdpair(i32* %12)
%14 = call i32 (...) @fork()
switch i32 %14, label %27 [
i32 -1, label %15
i32 0, label %17
]
15: ; preds = %11
%16 = call i32 @barf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %11, %15
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%22 = load i32, i32* %21
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 @receiver(i32 2000, i32 %22, i32 %23, i32 %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %11
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%29 = load i32, i32* %28
%30 = load i32, i32* %5
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %31
store i32 %29, i32* %32
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
br label %36
36: ; preds = %27
%37 = load i32, i32* %5
%38 = add i32 %37, 1
store i32 %38, i32* %5
br label %8
39: ; preds = %8
store i32 0, i32* %5
br label %40
40: ; preds = %54, %39
%41 = load i32, i32* %5
%42 = icmp ult i32 %41, 20
br i1 %42, label %43, label %57
43: ; preds = %40
%44 = call i32 (...) @fork()
switch i32 %44, label %53 [
i32 -1, label %45
i32 0, label %47
]
45: ; preds = %43
%46 = call i32 @barf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %43, %45
%48 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%49 = load i32, i32* %3
%50 = load i32, i32* %4
%51 = call i32 @sender(i32* %48, i32 %49, i32 %50)
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %43
br label %54
54: ; preds = %53
%55 = load i32, i32* %5
%56 = add i32 %55, 1
store i32 %56, i32* %5
br label %40
57: ; preds = %40
store i32 0, i32* %5
br label %58
58: ; preds = %67, %57
%59 = load i32, i32* %5
%60 = icmp ult i32 %59, 20
br i1 %60, label %61, label %70
61: ; preds = %58
%62 = load i32, i32* %5
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 @close(i32 %65)
br label %67
67: ; preds = %61
%68 = load i32, i32* %5
%69 = add i32 %68, 1
store i32 %69, i32* %5
br label %58
70: ; preds = %58
ret i32 40
}

LLVM IR (-O2):
@.str = [7 x i8] c"fork()\00"
define i32 @group(i32 %0, i32 %1) {
%3 = alloca [20 x i32]
%4 = alloca [2 x i32]
%5 = bitcast [20 x i32]* %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
br label %9
9: ; preds = %2, %21
%10 = phi i64 [ 0, %2 ], [ %26, %21 ]
%11 = call i32 @fdpair(i32* %7)
%12 = call i32 (...) @fork()
switch i32 %12, label %21 [
i32 -1, label %13
i32 0, label %15
]
13: ; preds = %9
%14 = call i32 @barf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %9, %13
%16 = load i32, i32* %8
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %7
%19 = call i32 @receiver(i32 2000, i32 %18, i32 %0, i32 %1)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %9
%22 = load i32, i32* %8
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %10
store i32 %22, i32* %23
%24 = load i32, i32* %7
%25 = call i32 @close(i32 %24)
%26 = add nuw nsw i64 %10, 1
%27 = icmp eq i64 %26, 20
br i1 %27, label %28, label %9
28: ; preds = %21
%29 = call i32 (...) @fork()
switch i32 %29, label %36 [
i32 -1, label %30
i32 0, label %32
]
30: ; preds = %72, %70, %68, %66, %64, %62, %60, %58, %56, %54, %52, %50, %48, %46, %44, %42, %40, %38, %36, %28
%31 = call i32 @barf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %28, %36, %38, %40, %42, %44, %46, %48, %50, %52, %54, %56, %58, %60, %62, %64, %66, %68, %70, %72, %30
%33 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%34 = call i32 @sender(i32* %33, i32 %0, i32 %1)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %28
%37 = call i32 (...) @fork()
switch i32 %37, label %38 [
i32 -1, label %30
i32 0, label %32
]
38: ; preds = %36
%39 = call i32 (...) @fork()
switch i32 %39, label %40 [
i32 -1, label %30
i32 0, label %32
]
40: ; preds = %38
%41 = call i32 (...) @fork()
switch i32 %41, label %42 [
i32 -1, label %30
i32 0, label %32
]
42: ; preds = %40
%43 = call i32 (...) @fork()
switch i32 %43, label %44 [
i32 -1, label %30
i32 0, label %32
]
44: ; preds = %42
%45 = call i32 (...) @fork()
switch i32 %45, label %46 [
i32 -1, label %30
i32 0, label %32
]
46: ; preds = %44
%47 = call i32 (...) @fork()
switch i32 %47, label %48 [
i32 -1, label %30
i32 0, label %32
]
48: ; preds = %46
%49 = call i32 (...) @fork()
switch i32 %49, label %50 [
i32 -1, label %30
i32 0, label %32
]
50: ; preds = %48
%51 = call i32 (...) @fork()
switch i32 %51, label %52 [
i32 -1, label %30
i32 0, label %32
]
52: ; preds = %50
%53 = call i32 (...) @fork()
switch i32 %53, label %54 [
i32 -1, label %30
i32 0, label %32
]
54: ; preds = %52
%55 = call i32 (...) @fork()
switch i32 %55, label %56 [
i32 -1, label %30
i32 0, label %32
]
56: ; preds = %54
%57 = call i32 (...) @fork()
switch i32 %57, label %58 [
i32 -1, label %30
i32 0, label %32
]
58: ; preds = %56
%59 = call i32 (...) @fork()
switch i32 %59, label %60 [
i32 -1, label %30
i32 0, label %32
]
60: ; preds = %58
%61 = call i32 (...) @fork()
switch i32 %61, label %62 [
i32 -1, label %30
i32 0, label %32
]
62: ; preds = %60
%63 = call i32 (...) @fork()
switch i32 %63, label %64 [
i32 -1, label %30
i32 0, label %32
]
64: ; preds = %62
%65 = call i32 (...) @fork()
switch i32 %65, label %66 [
i32 -1, label %30
i32 0, label %32
]
66: ; preds = %64
%67 = call i32 (...) @fork()
switch i32 %67, label %68 [
i32 -1, label %30
i32 0, label %32
]
68: ; preds = %66
%69 = call i32 (...) @fork()
switch i32 %69, label %70 [
i32 -1, label %30
i32 0, label %32
]
70: ; preds = %68
%71 = call i32 (...) @fork()
switch i32 %71, label %72 [
i32 -1, label %30
i32 0, label %32
]
72: ; preds = %70
%73 = call i32 (...) @fork()
switch i32 %73, label %74 [
i32 -1, label %30
i32 0, label %32
]
74: ; preds = %72
%75 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%76 = load i32, i32* %75
%77 = call i32 @close(i32 %76)
%78 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 1
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 2
%82 = load i32, i32* %81
%83 = call i32 @close(i32 %82)
%84 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 3
%85 = load i32, i32* %84
%86 = call i32 @close(i32 %85)
%87 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 4
%88 = load i32, i32* %87
%89 = call i32 @close(i32 %88)
%90 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 5
%91 = load i32, i32* %90
%92 = call i32 @close(i32 %91)
%93 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 6
%94 = load i32, i32* %93
%95 = call i32 @close(i32 %94)
%96 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 7
%97 = load i32, i32* %96
%98 = call i32 @close(i32 %97)
%99 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 8
%100 = load i32, i32* %99
%101 = call i32 @close(i32 %100)
%102 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 9
%103 = load i32, i32* %102
%104 = call i32 @close(i32 %103)
%105 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 10
%106 = load i32, i32* %105
%107 = call i32 @close(i32 %106)
%108 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 11
%109 = load i32, i32* %108
%110 = call i32 @close(i32 %109)
%111 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 12
%112 = load i32, i32* %111
%113 = call i32 @close(i32 %112)
%114 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 13
%115 = load i32, i32* %114
%116 = call i32 @close(i32 %115)
%117 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 14
%118 = load i32, i32* %117
%119 = call i32 @close(i32 %118)
%120 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 15
%121 = load i32, i32* %120
%122 = call i32 @close(i32 %121)
%123 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 16
%124 = load i32, i32* %123
%125 = call i32 @close(i32 %124)
%126 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 17
%127 = load i32, i32* %126
%128 = call i32 @close(i32 %127)
%129 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 18
%130 = load i32, i32* %129
%131 = call i32 @close(i32 %130)
%132 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 19
%133 = load i32, i32* %132
%134 = call i32 @close(i32 %133)
ret i32 40
}