#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ getpgid(int /*<<< orphan*/);
int killpg(int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: killpg <pid>\n");
    return 1;
  }
  pid_t pid = atoi(argv[1]);
  pid_t pgrp = getpgid(pid);
  int ret = killpg(pgrp, 9);
  if (ret != 0) {
    perror("Cannot kill process group");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dc <main+0x8c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <getpgid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x9,%esi
call   1040 <killpg@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d5 <main+0x85>
lea    0xe51(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dc <main+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x1,%edi
jg     1169 <main+0x19>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    118d <main+0x3d>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1070 <getpgid@plt>
mov    %eax,%edi
mov    $0x9,%esi
call   1040 <killpg@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    118f <main+0x3f>
pop    %rcx
ret
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
jmp    1162 <main+0x12>

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: killpg <pid>\0A\00"
@.str.1 = [26 x i8] c"Cannot kill process group\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %27
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i32 @getpgid(i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = call i32 @killpg(i32 %20, i32 9)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %27
26: ; preds = %13
store i32 0, i32* %3
br label %27
27: ; preds = %26, %24, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"Cannot kill process group\00"
@str = [20 x i8] c"Usage: killpg <pid>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %15
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 @getpgid(i32 %9)
%11 = tail call i32 @killpg(i32 %10, i32 9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %6
%14 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %6, %4
%16 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 0, %6 ]
ret i32 %16
}