#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*/ SIGINT;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int wait(int *);
void fork12() {
  pid_t pid[5];
  int i;
  int child_status;
  for (i = 0; i < 5; i++) {
    if ((pid[i] = fork()) == 0) {
      while (1)
        ;
    }
  }
  for (i = 0; i < 5; i++) {
    printf("Killing process %d\n", pid[i]);
    kill(pid[i], SIGINT);
  }
  for (i = 0; i < 5; i++) {
    pid_t wpid = wait(&child_status);
    if (WIFEXITED(child_status))
      printf("Child %d terminated with exit status %d\n", wpid,
             WEXITSTATUS(child_status));
    else
      printf("Child %d terminated abnormally\n", wpid);
  }
}


x86 assembly (clang, -O0):
<fork12>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    11ae <fork12+0x4e>
mov    $0x0,%al
call   1080 <fork@plt>
movslq -0x24(%rbp),%rcx
mov    %eax,-0x20(%rbp,%rcx,4)
cmp    $0x0,%eax
jne    119b <fork12+0x3b>
jmp    1196 <fork12+0x36>
jmp    1196 <fork12+0x36>
jmp    11a0 <fork12+0x40>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116f <fork12+0xf>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    11f9 <fork12+0x99>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b5 <fork12+0x55>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    1272 <fork12+0x112>
lea    -0x28(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     124e <fork12+0xee>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125f <fork12+0xff>
mov    -0x2c(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1264 <fork12+0x104>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1200 <fork12+0xa0>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork12>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1290 <fork12+0x130>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1290 <fork12+0x130>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1290 <fork12+0x130>
mov    %eax,%r12d
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1290 <fork12+0x130>
mov    %eax,%r15d
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1290 <fork12+0x130>
mov    %eax,%r14d
lea    0xe36(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e0e(%rip),%r13
mov    0x0(%r13),%esi
mov    %ebx,%edi
call   1040 <kill@plt>
lea    0xe14(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1040 <kill@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%r13),%esi
mov    %r12d,%edi
call   1040 <kill@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%r13),%esi
mov    %r15d,%edi
call   1040 <kill@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%r13),%esi
mov    %r14d,%edi
call   1040 <kill@plt>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     1292 <fork12+0x132>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xd9c(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12a2 <fork12+0x142>
cs nopw 0x0(%rax,%rax,1)
nop
jmp    1290 <fork12+0x130>
lea    0xda4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     12d9 <fork12+0x179>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xd48(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12e9 <fork12+0x189>
lea    0xd5d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     1320 <fork12+0x1c0>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xd01(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1330 <fork12+0x1d0>
lea    0xd16(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     1367 <fork12+0x207>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xcba(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1377 <fork12+0x217>
lea    0xccf(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     13ae <fork12+0x24e>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xc73(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    13be <fork12+0x25e>
lea    0xc88(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Killing process %d\0A\00"
@SIGINT = global i32 0
@.str.1 = [41 x i8] c"Child %d terminated with exit status %d\0A\00"
@.str.2 = [32 x i8] c"Child %d terminated abnormally\0A\00"
define void @fork12() {
%1 = alloca [5 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = call i32 (...) @fork()
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %11
store i32 %9, i32* %12
%13 = icmp eq i32 %9, 0
br i1 %13, label %14, label %16
14: ; preds = %8
br label %15
15: ; preds = %14, %15
br label %15
16: ; preds = %8
br label %17
17: ; preds = %16
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %5
20: ; preds = %5
store i32 0, i32* %2
br label %21
21: ; preds = %36, %20
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 5
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* @SIGINT
%35 = call i32 @kill(i32 %33, i32 %34)
br label %36
36: ; preds = %24
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %21
39: ; preds = %21
store i32 0, i32* %2
br label %40
40: ; preds = %57, %39
%41 = load i32, i32* %2
%42 = icmp slt i32 %41, 5
br i1 %42, label %43, label %60
43: ; preds = %40
%44 = call i32 @wait(i32* %3)
store i32 %44, i32* %4
%45 = load i32, i32* %3
%46 = call i64 @WIFEXITED(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %43
%49 = load i32, i32* %4
%50 = load i32, i32* %3
%51 = call i32 @WEXITSTATUS(i32 %50)
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %49, i32 %51)
br label %56
53: ; preds = %43
%54 = load i32, i32* %4
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %48
br label %57
57: ; preds = %56
%58 = load i32, i32* %2
%59 = add nsw i32 %58, 1
store i32 %59, i32* %2
br label %40
60: ; preds = %40
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Killing process %d\0A\00"
@SIGINT = global i32 0
@.str.1 = [41 x i8] c"Child %d terminated with exit status %d\0A\00"
@.str.2 = [32 x i8] c"Child %d terminated abnormally\0A\00"
define void @fork12() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %15, %12, %9, %6, %0
br label %38
6: ; preds = %0
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %5, label %9
9: ; preds = %6
%10 = tail call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %5, label %12
12: ; preds = %9
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %5, label %15
15: ; preds = %12
%16 = tail call i32 (...) @fork()
%17 = icmp eq i32 %16, 0
br i1 %17, label %5, label %18
18: ; preds = %15
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3)
%20 = load i32, i32* @SIGINT
%21 = tail call i32 @kill(i32 %3, i32 %20)
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %7)
%23 = load i32, i32* @SIGINT
%24 = tail call i32 @kill(i32 %7, i32 %23)
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %10)
%26 = load i32, i32* @SIGINT
%27 = tail call i32 @kill(i32 %10, i32 %26)
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13)
%29 = load i32, i32* @SIGINT
%30 = tail call i32 @kill(i32 %13, i32 %29)
%31 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %16)
%32 = load i32, i32* @SIGINT
%33 = tail call i32 @kill(i32 %16, i32 %32)
%34 = call i32 @wait(i32* %1)
%35 = load i32, i32* %1
%36 = call i64 @WIFEXITED(i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %43, label %39
38: ; preds = %5, %38
br label %38
39: ; preds = %18
%40 = load i32, i32* %1
%41 = call i32 @WEXITSTATUS(i32 %40)
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %41)
br label %45
43: ; preds = %18
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %45
45: ; preds = %43, %39
%46 = call i32 @wait(i32* %1)
%47 = load i32, i32* %1
%48 = call i64 @WIFEXITED(i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %45
%51 = load i32, i32* %1
%52 = call i32 @WEXITSTATUS(i32 %51)
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %52)
br label %56
54: ; preds = %45
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %56
56: ; preds = %54, %50
%57 = call i32 @wait(i32* %1)
%58 = load i32, i32* %1
%59 = call i64 @WIFEXITED(i32 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %56
%62 = load i32, i32* %1
%63 = call i32 @WEXITSTATUS(i32 %62)
%64 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %57, i32 %63)
br label %67
65: ; preds = %56
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %57)
br label %67
67: ; preds = %65, %61
%68 = call i32 @wait(i32* %1)
%69 = load i32, i32* %1
%70 = call i64 @WIFEXITED(i32 %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %76, label %72
72: ; preds = %67
%73 = load i32, i32* %1
%74 = call i32 @WEXITSTATUS(i32 %73)
%75 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %68, i32 %74)
br label %78
76: ; preds = %67
%77 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %68)
br label %78
78: ; preds = %76, %72
%79 = call i32 @wait(i32* %1)
%80 = load i32, i32* %1
%81 = call i64 @WIFEXITED(i32 %80)
%82 = icmp eq i64 %81, 0
br i1 %82, label %87, label %83
83: ; preds = %78
%84 = load i32, i32* %1
%85 = call i32 @WEXITSTATUS(i32 %84)
%86 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %79, i32 %85)
br label %89
87: ; preds = %78
%88 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %79)
br label %89
89: ; preds = %87, %83
ret void
}