#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTSTP;
int /*<<< orphan*/ SIGTTIN;
int /*<<< orphan*/ SIGTTOU;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ getpgid(int /*<<< orphan*/);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int tcsetpgrp(int /*<<< orphan*/, int /*<<< orphan*/);
void c_init(int foreground) {
  pid_t c_pid = getpid();
  setpgid(c_pid, c_pid);
  if (foreground) {
    if (tcsetpgrp(STDIN_FILENO, getpgid(c_pid)) == -1)
      perror("tcsetpgrp");
  }
  signal(SIGINT, SIG_DFL);
  signal(SIGQUIT, SIG_DFL);
  signal(SIGTSTP, SIG_DFL);
  signal(SIGTTIN, SIG_DFL);
  signal(SIGTTOU, SIG_DFL);
  signal(SIGCHLD, SIG_DFL);
}


x86 assembly (clang, -O0):
<c_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <setpgid@plt>
cmpl   $0x0,-0x4(%rbp)
je     11c2 <c_init+0x62>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <getpgid@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
call   1050 <tcsetpgrp@plt>
cmp    $0xffffffff,%eax
jne    11bd <c_init+0x5d>
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
jmp    11c2 <c_init+0x62>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_init>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %eax,%esi
call   1080 <setpgid@plt>
test   %ebp,%ebp
je     1199 <c_init+0x39>
mov    0x2e26(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1070 <getpgid@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <tcsetpgrp@plt>
cmp    $0xffffffff,%eax
je     1206 <c_init+0xa6>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e07(%rip),%rbx
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <signal@plt>
lea    0xdf3(%rip),%rdi
call   1060 <perror@plt>
jmp    1199 <c_init+0x39>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [10 x i8] c"tcsetpgrp\00"
@SIGINT = global i32 0
@SIG_DFL = global i32 0
@SIGQUIT = global i32 0
@SIGTSTP = global i32 0
@SIGTTIN = global i32 0
@SIGTTOU = global i32 0
@SIGCHLD = global i32 0
define void @c_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @getpid()
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @setpgid(i32 %5, i32 %6)
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load i32, i32* @STDIN_FILENO
%12 = load i32, i32* %3
%13 = call i32 @getpgid(i32 %12)
%14 = call i32 @tcsetpgrp(i32 %11, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
br label %19
19: ; preds = %18, %1
%20 = load i32, i32* @SIGINT
%21 = load i32, i32* @SIG_DFL
%22 = call i32 @signal(i32 %20, i32 %21)
%23 = load i32, i32* @SIGQUIT
%24 = load i32, i32* @SIG_DFL
%25 = call i32 @signal(i32 %23, i32 %24)
%26 = load i32, i32* @SIGTSTP
%27 = load i32, i32* @SIG_DFL
%28 = call i32 @signal(i32 %26, i32 %27)
%29 = load i32, i32* @SIGTTIN
%30 = load i32, i32* @SIG_DFL
%31 = call i32 @signal(i32 %29, i32 %30)
%32 = load i32, i32* @SIGTTOU
%33 = load i32, i32* @SIG_DFL
%34 = call i32 @signal(i32 %32, i32 %33)
%35 = load i32, i32* @SIGCHLD
%36 = load i32, i32* @SIG_DFL
%37 = call i32 @signal(i32 %35, i32 %36)
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [10 x i8] c"tcsetpgrp\00"
@SIGINT = global i32 0
@SIG_DFL = global i32 0
@SIGQUIT = global i32 0
@SIGTSTP = global i32 0
@SIGTTIN = global i32 0
@SIGTTOU = global i32 0
@SIGCHLD = global i32 0
define void @c_init(i32 %0) {
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 @setpgid(i32 %2, i32 %2)
%4 = icmp eq i32 %0, 0
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = load i32, i32* @STDIN_FILENO
%7 = tail call i32 @getpgid(i32 %2)
%8 = tail call i32 @tcsetpgrp(i32 %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %5, %10, %1
%13 = load i32, i32* @SIGINT
%14 = load i32, i32* @SIG_DFL
%15 = tail call i32 @signal(i32 %13, i32 %14)
%16 = load i32, i32* @SIGQUIT
%17 = load i32, i32* @SIG_DFL
%18 = tail call i32 @signal(i32 %16, i32 %17)
%19 = load i32, i32* @SIGTSTP
%20 = load i32, i32* @SIG_DFL
%21 = tail call i32 @signal(i32 %19, i32 %20)
%22 = load i32, i32* @SIGTTIN
%23 = load i32, i32* @SIG_DFL
%24 = tail call i32 @signal(i32 %22, i32 %23)
%25 = load i32, i32* @SIGTTOU
%26 = load i32, i32* @SIG_DFL
%27 = tail call i32 @signal(i32 %25, i32 %26)
%28 = load i32, i32* @SIGCHLD
%29 = load i32, i32* @SIG_DFL
%30 = tail call i32 @signal(i32 %28, i32 %29)
ret void
}