#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 */
struct sigaction {
  int /*<<< orphan*/ sa_handler;
  int /*<<< orphan*/ sa_flags;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SA_NOCLDWAIT;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sigaction(int /*<<< orphan*/, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t cpid;
  struct sigaction act;
  cpid = fork();
  if (cpid == 0) {
    printf("CHILD:  I am in child task %d \n", getpid());
    sleep(10);
    exit(100);
  } else {
    printf("PARENT\n");
    act.sa_flags = SA_NOCLDWAIT;
    act.sa_handler = SIG_DFL;
    if (sigaction(SIGCHLD, &act, NULL) == -1)
      ;
    perror("sigaction: ");
    while (1)
      ;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c0 <main+0x50>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1080 <sleep@plt>
mov    $0x64,%edi
call   1070 <exit@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    120a <main+0x9a>
jmp    120a <main+0x9a>
lea    0xe17(%rip),%rdi
call   1060 <perror@plt>
jmp    1216 <main+0xa6>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11e2 <main+0x62>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jmp    11e0 <main+0x60>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1090 <sleep@plt>
mov    $0x64,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@.str = [32 x i8] c"CHILD: I am in child task %d \0A\00"
@.str.1 = [8 x i8] c"PARENT\0A\00"
@SA_NOCLDWAIT = global i32 0
@SIG_DFL = global i32 0
@SIGCHLD = global i32 0
@.str.2 = [12 x i8] c"sigaction: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.sigaction
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @sleep(i32 10)
%11 = call i32 @exit(i32 100)
unreachable
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @SA_NOCLDWAIT
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @SIG_DFL
%17 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @SIGCHLD
%19 = call i32 @sigaction(i32 %18, %struct.sigaction* %3, i32* null)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %12
br label %22
22: ; preds = %21, %12
%23 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %24
br label %24
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@.str = [32 x i8] c"CHILD: I am in child task %d \0A\00"
@SA_NOCLDWAIT = global i32 0
@SIG_DFL = global i32 0
@SIGCHLD = global i32 0
@.str.2 = [12 x i8] c"sigaction: \00"
@str = [7 x i8] c"PARENT\00"
define i32 @main() {
%1 = alloca %struct.sigaction
%2 = bitcast %struct.sigaction* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @sleep(i32 10)
%9 = tail call i32 @exit(i32 100)
unreachable
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @SA_NOCLDWAIT
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @SIG_DFL
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @SIGCHLD
%17 = call i32 @sigaction(i32 %16, %struct.sigaction* %1, i32* null)
%18 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %19, %10
br label %19
}