#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;
};
typedef int /*<<< orphan*/ save_sigact;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ getpgid(int /*<<< orphan*/);
int /*<<< orphan*/ getpgrp();
int killpg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(struct sigaction *, struct sigaction *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sigaction(int /*<<< orphan*/, struct sigaction *,
                     struct sigaction *);
void killProcessGroup() {
  pid_t myPgid;
  struct sigaction save_sigact, tmp_sigact;
  int result;
  if ((myPgid = getpgid(0)) < 0)
    perror("getpgid");
  if (sigaction(SIGTERM, NULL, &save_sigact) < 0) {
    ;
  } else {
    memcpy(&tmp_sigact, &save_sigact, sizeof(save_sigact));
    tmp_sigact.sa_handler = SIG_IGN;
    sigaction(SIGTERM, &tmp_sigact, NULL);
  }
  if (killpg(getpgrp(), SIGTERM) == -1)
    perror("killpg");
  sigaction(SIGTERM, &save_sigact, NULL);
}


x86 assembly (clang, -O0):
<killProcessGroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %edi,%edi
call   1080 <getpgid@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1187 <killProcessGroup+0x27>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    11ac <killProcessGroup+0x4c>
jmp    11e0 <killProcessGroup+0x80>
lea    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    $0x0,%al
call   1060 <getpgrp@plt>
mov    %eax,%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1050 <killpg@plt>
cmp    $0xffffffff,%eax
jne    120c <killProcessGroup+0xac>
lea    0xe01(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<killProcessGroup>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1080 <getpgid@plt>
test   %eax,%eax
js     11e7 <killProcessGroup+0x87>
mov    0x2e6f(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1030 <sigaction@plt>
test   %rax,%rax
js     11bc <killProcessGroup+0x5c>
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
xor    %eax,%eax
call   1060 <getpgrp@plt>
mov    (%rbx),%esi
mov    %eax,%edi
call   1050 <killpg@plt>
cmp    $0xffffffff,%eax
je     11f8 <killProcessGroup+0x98>
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe12(%rip),%rdi
call   1070 <perror@plt>
jmp    1172 <killProcessGroup+0x12>
lea    0xe09(%rip),%rdi
call   1070 <perror@plt>
jmp    11d1 <killProcessGroup+0x71>

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@.str = [8 x i8] c"getpgid\00"
@SIGTERM = global i32 0
@SIG_IGN = global i32 0
@.str.1 = [7 x i8] c"killpg\00"
define void @killProcessGroup() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = alloca %struct.sigaction
%4 = alloca i32
%5 = call i32 @getpgid(i32 0)
store i32 %5, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @SIGTERM
%11 = call i64 @sigaction(i32 %10, %struct.sigaction* null, %struct.sigaction* %2)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
br label %20
14: ; preds = %9
%15 = call i32 @memcpy(%struct.sigaction* %3, %struct.sigaction* %2, i32 4)
%16 = load i32, i32* @SIG_IGN
%17 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @SIGTERM
%19 = call i64 @sigaction(i32 %18, %struct.sigaction* %3, %struct.sigaction* null)
br label %20
20: ; preds = %14, %13
%21 = call i32 (...) @getpgrp()
%22 = load i32, i32* @SIGTERM
%23 = call i32 @killpg(i32 %21, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = load i32, i32* @SIGTERM
%29 = call i64 @sigaction(i32 %28, %struct.sigaction* %2, %struct.sigaction* null)
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
@.str = [8 x i8] c"getpgid\00"
@SIGTERM = global i32 0
@SIG_IGN = global i32 0
@.str.1 = [7 x i8] c"killpg\00"
define void @killProcessGroup() {
%1 = alloca %struct.sigaction
%2 = alloca %struct.sigaction
%3 = bitcast %struct.sigaction* %1 to i8*
%4 = bitcast %struct.sigaction* %2 to i8*
%5 = tail call i32 @getpgid(i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @SIGTERM
%11 = call i64 @sigaction(i32 %10, %struct.sigaction* null, %struct.sigaction* %1)
%12 = icmp slt i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = call i32 @memcpy(%struct.sigaction* %2, %struct.sigaction* %1, i32 4)
%15 = load i32, i32* @SIG_IGN
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @SIGTERM
%18 = call i64 @sigaction(i32 %17, %struct.sigaction* %2, %struct.sigaction* null)
br label %19
19: ; preds = %9, %13
%20 = call i32 (...) @getpgrp()
%21 = load i32, i32* @SIGTERM
%22 = call i32 @killpg(i32 %20, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = load i32, i32* @SIGTERM
%28 = call i64 @sigaction(i32 %27, %struct.sigaction* %1, %struct.sigaction* null)
ret void
}