#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*/ err_sys(char *);
int getpgrp();
int getpid();
int /*<<< orphan*/ print();
int /*<<< orphan*/ printf(char *, int, int);
int setpgid(int, int);
int main() {
  int ret = 0;
  pid_t pid = getpid();
  pid_t grp = getpgrp();
  printf("pid = %u, grp = %u\n", pid, grp);
  ret = setpgid(pid, grp);
  if (ret == -1)
    err_sys("setpgid");
  print();
  ret = setpgid(0, grp);
  if (ret == -1)
    err_sys("setpgid");
  print();
  ret = setpgid(pid, 0);
  if (ret == -1)
    err_sys("setpgid");
  print();
  ret = setpgid(pid, grp);
  if (ret == -1)
    err_sys("setpgid");
  print();
  ret = setpgid(0, 0);
  if (ret == -1)
    err_sys("setpgid");
  print();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <getpgrp@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1080 <setpgid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c0 <main+0x60>
lea    0xe59(%rip),%rdi
call   1030 <err_sys@plt>
mov    $0x0,%al
call   1060 <print@plt>
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   1080 <setpgid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11ea <main+0x8a>
lea    0xe2f(%rip),%rdi
call   1030 <err_sys@plt>
mov    $0x0,%al
call   1060 <print@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1080 <setpgid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1214 <main+0xb4>
lea    0xe05(%rip),%rdi
call   1030 <err_sys@plt>
mov    $0x0,%al
call   1060 <print@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1080 <setpgid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    123f <main+0xdf>
lea    0xdda(%rip),%rdi
call   1030 <err_sys@plt>
mov    $0x0,%al
call   1060 <print@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1080 <setpgid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1268 <main+0x108>
lea    0xdb1(%rip),%rdi
call   1030 <err_sys@plt>
mov    $0x0,%al
call   1060 <print@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getpgrp@plt>
mov    %eax,%ebp
lea    0xe84(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1080 <setpgid@plt>
cmp    $0xffffffff,%eax
jne    119f <main+0x3f>
lea    0xe7a(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1060 <print@plt>
xor    %edi,%edi
mov    %ebp,%esi
call   1080 <setpgid@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x60>
lea    0xe59(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1060 <print@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1080 <setpgid@plt>
cmp    $0xffffffff,%eax
jne    11e1 <main+0x81>
lea    0xe38(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1060 <print@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1080 <setpgid@plt>
cmp    $0xffffffff,%eax
jne    1202 <main+0xa2>
lea    0xe17(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1060 <print@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <setpgid@plt>
cmp    $0xffffffff,%eax
jne    1223 <main+0xc3>
lea    0xdf6(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1060 <print@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"pid = %u, grp = %u\0A\00"
@.str.1 = [8 x i8] c"setpgid\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (...) @getpid()
store i32 %5, i32* %3
%6 = call i32 (...) @getpgrp()
store i32 %6, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = call i32 @setpgid(i32 %10, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
%18 = call i32 (...) @print()
%19 = load i32, i32* %4
%20 = call i32 @setpgid(i32 0, i32 %19)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %17
%26 = call i32 (...) @print()
%27 = load i32, i32* %3
%28 = call i32 @setpgid(i32 %27, i32 0)
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
%34 = call i32 (...) @print()
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = call i32 @setpgid(i32 %35, i32 %36)
store i32 %37, i32* %2
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %33
%43 = call i32 (...) @print()
%44 = call i32 @setpgid(i32 0, i32 0)
store i32 %44, i32* %2
%45 = load i32, i32* %2
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
%50 = call i32 (...) @print()
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"pid = %u, grp = %u\0A\00"
@.str.1 = [8 x i8] c"setpgid\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (...) @getpgrp()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%4 = tail call i32 @setpgid(i32 %1, i32 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = tail call i32 (...) @print()
%10 = tail call i32 @setpgid(i32 0, i32 %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = tail call i32 (...) @print()
%16 = tail call i32 @setpgid(i32 %1, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = tail call i32 (...) @print()
%22 = tail call i32 @setpgid(i32 %1, i32 %2)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = tail call i32 (...) @print()
%28 = tail call i32 @setpgid(i32 0, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @err_sys(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = tail call i32 (...) @print()
ret i32 0
}