#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();
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("Test FAILED: killpg did not return -1 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    11ab <main+0x7b>
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   $0x1,-0x4(%rbp)
jmp    11ab <main+0x7b>
lea    0xedf(%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     1171 <main+0x31>
mov    %eax,%edi
mov    $0xffffffff,%esi
call   1050 <killpg@plt>
cmp    $0xffffffff,%eax
je     1184 <main+0x44>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
pop    %rcx
ret
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Could not get process group number\0A\00"
@.str.1 = [90 x i8] c"Test FAILED: killpg did not return -1 even though it was passed an invalid signal number.\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 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 ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0))
store i32 1, 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.1 = [90 x i8] c"Test FAILED: killpg did not return -1 even though it was passed an invalid signal number.\00"
@str = [12 x i8] c"Test PASSED\00"
@str.3 = [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.3, i64 0, i64 0))
br label %12
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 ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0))
br label %12
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %8, %3
%13 = phi i32 [ 2, %3 ], [ 1, %8 ], [ 0, %10 ]
ret i32 %13
}