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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int getpgid(int);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ setpgid(int, int);
int main(void) {
  pid_t pid, group_id;
  pid = getpid();
  if ((group_id = getpgid(pid)) < 0) {
    perror("getpgid");
    exit(-1);
  }
  printf("Group ID = %d\n", group_id);
  if (setpgid(pid, pid) < 0) {
    perror("setpgid");
    exit(1);
  }
  if ((group_id = getpgid(pid)) < 0) {
    perror("getpgid");
    exit(-1);
  }
  printf("Group ID = %d\n", group_id);
  printf("pid = %d\n", pid);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <getpgid@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11a3 <main+0x43>
lea    0xe6c(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <setpgid@plt>
cmp    $0x0,%rax
jge    11dd <main+0x7d>
lea    0xe49(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <getpgid@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1207 <main+0xa7>
lea    0xe08(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <getpgid@plt>
test   %eax,%eax
js     11b2 <main+0x52>
lea    0xe8c(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %ebx,%esi
call   1070 <setpgid@plt>
test   %rax,%rax
jns    11a7 <main+0x47>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %ebx,%edi
call   1060 <getpgid@plt>
test   %eax,%eax
jns    11c8 <main+0x68>
lea    0xe47(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe39(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe42(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"getpgid\00"
@.str.1 = [15 x i8] c"Group ID = %d\0A\00"
@.str.2 = [8 x i8] c"setpgid\00"
@.str.3 = [10 x i8] c"pid = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @getpid()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @getpgid(i32 %5)
store i32 %6, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = load i32, i32* %2
%16 = call i64 @setpgid(i32 %14, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i32, i32* %2
%23 = call i32 @getpgid(i32 %22)
store i32 %23, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %21
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %2
%32 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"getpgid\00"
@.str.1 = [15 x i8] c"Group ID = %d\0A\00"
@.str.2 = [8 x i8] c"setpgid\00"
@.str.3 = [10 x i8] c"pid = %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 @getpgid(i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%9 = tail call i64 @setpgid(i32 %1, i32 %1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = tail call i32 @getpgid(i32 %1)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %14
%21 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%23 = tail call i32 @exit(i32 0)
unreachable
}