#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ ESRCH;
int /*<<< orphan*/ LogErrno(char *, int);
scalar_t__ errno;
int kill(scalar_t__, int);
int KillPgrp(pid_t pid, int signo) {
  int ret = kill(-pid, signo);
  if (ret < 0 && errno == ESRCH) {
    LogErrno("Unable to kill process group %d - falling back to leader only",
             (int)pid);
    ret = kill(pid, signo);
  }
  return ret;
}


x86 assembly (clang, -O0):
<KillPgrp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
sub    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <kill@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1187 <KillPgrp+0x67>
mov    0x2e8d(%rip),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    1187 <KillPgrp+0x67>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xe8d(%rip),%rdi
call   1030 <LogErrno@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <kill@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KillPgrp>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
neg    %rdi
call   1040 <kill@plt>
test   %eax,%eax
jns    1168 <KillPgrp+0x48>
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e8b(%rip),%rdx
cmp    (%rdx),%rcx
jne    1168 <KillPgrp+0x48>
lea    0xeaf(%rip),%rdi
mov    %ebx,%esi
call   1030 <LogErrno@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <kill@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ESRCH = global i64 0
@.str = [62 x i8] c"Unable to kill process group %d - falling back to leader only\00"
define i32 @KillPgrp(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
%6 = load i64, i64* %3
%7 = sub nsw i64 0, %6
%8 = load i32, i32* %4
%9 = call i32 @kill(i64 %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i64, i64* @errno
%14 = load i64, i64* @ESRCH
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i64, i64* %3
%18 = trunc i64 %17 to i32
%19 = call i32 @LogErrno(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i64, i64* %3
%21 = load i32, i32* %4
%22 = call i32 @kill(i64 %20, i32 %21)
store i32 %22, i32* %5
br label %23
23: ; preds = %16, %12, %2
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
@errno = global i64 0
@ESRCH = global i64 0
@.str = [62 x i8] c"Unable to kill process group %d - falling back to leader only\00"
define i32 @KillPgrp(i64 %0, i32 %1) {
%3 = sub nsw i64 0, %0
%4 = tail call i32 @kill(i64 %3, i32 %1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @ESRCH
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = trunc i64 %0 to i32
%12 = tail call i32 @LogErrno(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @kill(i64 %0, i32 %1)
br label %14
14: ; preds = %10, %6, %2
%15 = phi i32 [ %13, %10 ], [ %4, %6 ], [ %4, %2 ]
ret i32 %15
}