#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getpgid(int /*<<< orphan*/);
scalar_t__ getpid();
scalar_t__ getppid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ tcgetpgrp(int);
scalar_t__ tcgetsid(int);
int main(int argc, char *argv[]) {
  int fd;
  printf("process ID = %ld; parent = %ld\n", (long)getpid(), (long)getppid());
  printf("session ID = %ld; process-group ID = %ld\n", (long)tcgetsid(0),
         (long)getpgid(0));
  if ((fd = open("/dev/tty", O_RDWR)) < 0) {
    fprintf(stderr, "Err.(%s) open() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("foreground Process-Group ID del terminale di controllo = %ld\n",
         (long)tcgetpgrp(fd));
  printf("Session-ID del terminale di controllo = %ld\n", (long)tcgetsid(fd));
  close(fd);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10b0 <getppid@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1030 <tcgetsid@plt>
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   10a0 <getpgid@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    126f <main+0xbf>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf7(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1080 <tcgetpgrp@plt>
mov    %rax,%rsi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1030 <tcgetsid@plt>
mov    %rax,%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <getppid@plt>
lea    0xe37(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1030 <tcgetsid@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   10a0 <getpgid@plt>
lea    0xe32(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1258 <main+0xa8>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <tcgetpgrp@plt>
lea    0xe47(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1030 <tcgetsid@plt>
lea    0xe6d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2d79(%rip),%rax
mov    (%rax),%ebx
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xddd(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"process ID = %ld; parent = %ld\0A\00"
@.str.1 = [42 x i8] c"session ID = %ld; process-group ID = %ld\0A\00"
@.str.2 = [9 x i8] c"/dev/tty\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.3 = [24 x i8] c"Err.(%s) open() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [62 x i8] c"foreground Process-Group ID del terminale di controllo = %ld\0A\00"
@.str.5 = [45 x i8] c"Session-ID del terminale di controllo = %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @getpid()
%8 = call i64 (...) @getppid()
%9 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %7, i64 %8)
%10 = call i64 @tcgetsid(i32 0)
%11 = call i64 @getpgid(i32 0)
%12 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %10, i64 %11)
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i32, i32* %6
%25 = call i64 @tcgetpgrp(i32 %24)
%26 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0), i64 %25)
%27 = load i32, i32* %6
%28 = call i64 @tcgetsid(i32 %27)
%29 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i64 %28)
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}

LLVM IR (-O2):
@.str = [32 x i8] c"process ID = %ld; parent = %ld\0A\00"
@.str.1 = [42 x i8] c"session ID = %ld; process-group ID = %ld\0A\00"
@.str.2 = [9 x i8] c"/dev/tty\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.3 = [24 x i8] c"Err.(%s) open() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [62 x i8] c"foreground Process-Group ID del terminale di controllo = %ld\0A\00"
@.str.5 = [45 x i8] c"Session-ID del terminale di controllo = %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @getpid()
%4 = tail call i64 (...) @getppid()
%5 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %3, i64 %4)
%6 = tail call i64 @tcgetsid(i32 0)
%7 = tail call i64 @getpgid(i32 0)
%8 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %6, i64 %7)
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = tail call i64 @tcgetpgrp(i32 %10)
%21 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0), i64 %20)
%22 = tail call i64 @tcgetsid(i32 %10)
%23 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i64 %22)
%24 = tail call i32 @close(i32 %10)
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}