#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*/ SIGINT;
int /*<<< orphan*/ execlp(char *, char *, char *);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
main(int argc, char *argv[]) {
  int pid, chpid[3];
  int i, status;
  for (i = 0; i < 3; i++) {
    if ((pid = fork()) == 0)
      execlp("./sig_child", "./sig_child", (char *)0);
    chpid[i] = pid;
  }
  printf("sig_parent: %d child process run\n", 3);
  sleep(10);
  for (i = 0; i < 3; i++)
    kill(chpid[i], SIGINT);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11b6 <main+0x66>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    119d <main+0x4d>
lea    0xe6f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1050 <execlp@plt>
mov    -0x14(%rbp),%ecx
movslq -0x24(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116d <main+0x1d>
lea    0xe4f(%rip),%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1206 <main+0xb6>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d8 <main+0x88>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    1176 <main+0x26>
lea    0xe94(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1050 <execlp@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    1195 <main+0x45>
lea    0xe75(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1050 <execlp@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11b3 <main+0x63>
lea    0xe57(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1050 <execlp@plt>
lea    0xe52(%rip),%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
mov    0x2e13(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r14d,%edi
call   1040 <kill@plt>
mov    0x0(%rbp),%esi
mov    %r15d,%edi
call   1040 <kill@plt>
mov    0x0(%rbp),%esi
mov    %ebx,%edi
call   1040 <kill@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"./sig_child\00"
@.str.1 = [34 x i8] c"sig_parent: %d child process run\0A\00"
@SIGINT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [3 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = call i32 (...) @fork()
store i32 %14, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* null)
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %6
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %21
store i32 %19, i32* %22
br label %23
23: ; preds = %18
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %10
26: ; preds = %10
%27 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 3)
%28 = call i32 @sleep(i32 10)
store i32 0, i32* %8
br label %29
29: ; preds = %39, %26
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 3
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* @SIGINT
%38 = call i32 @kill(i32 %36, i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %29
42: ; preds = %29
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [12 x i8] c"./sig_child\00"
@.str.1 = [34 x i8] c"sig_parent: %d child process run\0A\00"
@SIGINT = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* null)
br label %7
7: ; preds = %5, %2
%8 = tail call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* null)
br label %12
12: ; preds = %10, %7
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* null)
br label %17
17: ; preds = %15, %12
%18 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 3)
%19 = tail call i32 @sleep(i32 10)
%20 = load i32, i32* @SIGINT
%21 = tail call i32 @kill(i32 %3, i32 %20)
%22 = load i32, i32* @SIGINT
%23 = tail call i32 @kill(i32 %8, i32 %22)
%24 = load i32, i32* @SIGINT
%25 = tail call i32 @kill(i32 %13, i32 %24)
ret i32 0
}