#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 */

/* Variables and functions */
int getpgrp();
scalar_t__ killpg(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int pgrp;
  if ((pgrp = getpgrp()) == -1) {
    printf("Could not get process group number\n");
    return 2;
  }
  if (killpg(pgrp, 0) != 0) {
    printf("killpg did not return success.\n");
    return 2;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getpgrp@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    116a <main+0x3a>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11a9 <main+0x79>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <killpg@plt>
cmp    $0x0,%rax
je     1196 <main+0x66>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11a9 <main+0x79>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <getpgrp@plt>
cmp    $0xffffffff,%eax
je     1164 <main+0x34>
mov    %eax,%edi
xor    %esi,%esi
call   1040 <killpg@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
lea    0xeab(%rip),%rax
lea    0xeb0(%rip),%rdi
cmove  %rax,%rdi
add    %ebx,%ebx
jmp    1170 <main+0x40>
mov    $0x2,%ebx
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Could not get process group number\0A\00"
@.str.1 = [32 x i8] c"killpg did not return success.\0A\00"
@.str.2 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @getpgrp()
store i32 %3, i32* %2
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %15
7: ; preds = %0
%8 = load i32, i32* %2
%9 = call i64 @killpg(i32 %8, i32 0)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %15
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %15
15: ; preds = %13, %11, %5
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@str = [12 x i8] c"Test PASSED\00"
@str.3 = [31 x i8] c"killpg did not return success.\00"
@str.4 = [35 x i8] c"Could not get process group number\00"
define i32 @main() {
%1 = tail call i32 (...) @getpgrp()
%2 = icmp eq i32 %1, -1
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = tail call i64 @killpg(i32 %1, i32 0)
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str.3, i64 0, i64 0)
%7 = select i1 %5, i32 0, i32 2
br label %8
8: ; preds = %3, %0
%9 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0), %0 ], [ %6, %3 ]
%10 = phi i32 [ 2, %0 ], [ %7, %3 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %9)
ret i32 %10
}