#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_flags;
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_handler;
};

/* Variables and functions */
int /*<<< orphan*/ SA_NOCLDWAIT;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int sigaction(int /*<<< orphan*/, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void nozombies() {
  struct sigaction sa;
  sa.sa_handler = SIG_IGN;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = SA_NOCLDWAIT;
  if (sigaction(SIGCHLD, &sa, NULL) == -1) {
    perror("sigaction() failed");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<nozombies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    11a2 <nozombies+0x62>
lea    0xe6d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nozombies>:
sub    $0x18,%rsp
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
je     1187 <nozombies+0x47>
add    $0x18,%rsp
ret
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i32, i32, i32 }
@SIG_IGN = global i32 0
@SA_NOCLDWAIT = global i32 0
@SIGCHLD = global i32 0
@.str = [19 x i8] c"sigaction() failed\00"
define void @nozombies() {
%1 = alloca %struct.sigaction
%2 = load i32, i32* @SIG_IGN
%3 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 2
store i32 %2, i32* %3
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 1
%5 = call i32 @sigemptyset(i32* %4)
%6 = load i32, i32* @SA_NOCLDWAIT
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @SIGCHLD
%9 = call i32 @sigaction(i32 %8, %struct.sigaction* %1, i32* null)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32, i32 }
@SIG_IGN = global i32 0
@SA_NOCLDWAIT = global i32 0
@SIGCHLD = global i32 0
@.str = [19 x i8] c"sigaction() failed\00"
define void @nozombies() {
%1 = alloca %struct.sigaction
%2 = bitcast %struct.sigaction* %1 to i8*
%3 = load i32, i32* @SIG_IGN
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 2
store i32 %3, i32* %4
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
%6 = call i32 @sigemptyset(i32* %5)
%7 = load i32, i32* @SA_NOCLDWAIT
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @SIGCHLD
%10 = call i32 @sigaction(i32 %9, %struct.sigaction* %1, i32* null)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
ret void
}