#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 */
scalar_t__ EINVAL;
scalar_t__ errno;
int getpgrp();
int killpg(int, int);
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, -1) != -1) {
    printf("killpg did not return -1 even though it was passed an invalid "
           "signal number.");
    return 2;
  }
  if (errno != EINVAL) {
    printf("killpg did not set errno to EINVAL even though it was passed an "
           "invalid signal number.");
    return 1;
  }
  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    11dd <main+0xad>
mov    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
call   1040 <killpg@plt>
cmp    $0xffffffff,%eax
je     1198 <main+0x68>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11dd <main+0xad>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    0x2e2f(%rip),%rcx
cmp    (%rcx),%rax
je     11ca <main+0x9a>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dd <main+0xad>
lea    0xef7(%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   %rax
xor    %eax,%eax
call   1060 <getpgrp@plt>
cmp    $0xffffffff,%eax
je     116c <main+0x2c>
mov    %eax,%edi
mov    $0xffffffff,%esi
call   1050 <killpg@plt>
cmp    $0xffffffff,%eax
je     117f <main+0x3f>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
jmp    1178 <main+0x38>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
pop    %rcx
ret
mov    0x2e5a(%rip),%rax
mov    (%rax),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
jne    11a5 <main+0x65>
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Could not get process group number\0A\00"
@.str.1 = [77 x i8] c"killpg did not return -1 even though it was passed an invalid signal number.\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [87 x i8] c"killpg did not set errno to EINVAL even though it was passed an invalid signal number.\00"
@.str.3 = [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 %21
7: ; preds = %0
%8 = load i32, i32* %2
%9 = call i32 @killpg(i32 %8, i32 -1)
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %21
13: ; preds = %7
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINVAL
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %21
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %21
21: ; preds = %19, %17, %11, %5
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str.1 = [77 x i8] c"killpg did not return -1 even though it was passed an invalid signal number.\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [87 x i8] c"killpg did not set errno to EINVAL even though it was passed an invalid signal number.\00"
@str = [12 x i8] c"Test PASSED\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 %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
br label %18
5: ; preds = %0
%6 = tail call i32 @killpg(i32 %1, i32 -1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0))
br label %18
10: ; preds = %5
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINVAL
%13 = icmp eq i64 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %10
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %14, %8, %3
%19 = phi i32 [ 2, %3 ], [ 2, %8 ], [ 1, %14 ], [ 0, %16 ]
ret i32 %19
}