#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*/ O_RDONLY;
int /*<<< orphan*/ SIGTTIN;
int /*<<< orphan*/ SIGTTOU;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ TIOCSPGRP;
int /*<<< orphan*/ close(int);
int getpid();
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
void sub_sigchld(void) {
  int fd;
  int pid;
  pid = getpid();
  signal(SIGTTOU, SIG_IGN);
  signal(SIGTTIN, SIG_IGN);
  fd = open("/dev/tty", O_RDONLY);
  ioctl(fd, TIOCSPGRP, &pid);
  close(fd);
}


x86 assembly (clang, -O0):
<sub_sigchld>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sub_sigchld>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0xc(%rsp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rbx
mov    (%rbx),%esi
call   1060 <signal@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1060 <signal@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SIGTTOU = global i32 0
@SIG_IGN = global i32 0
@SIGTTIN = global i32 0
@.str = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@TIOCSPGRP = global i32 0
define void @sub_sigchld() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @getpid()
store i32 %3, i32* %2
%4 = load i32, i32* @SIGTTOU
%5 = load i32, i32* @SIG_IGN
%6 = call i32 @signal(i32 %4, i32 %5)
%7 = load i32, i32* @SIGTTIN
%8 = load i32, i32* @SIG_IGN
%9 = call i32 @signal(i32 %7, i32 %8)
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = load i32, i32* @TIOCSPGRP
%14 = call i32 @ioctl(i32 %12, i32 %13, i32* %2)
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
ret void
}

LLVM IR (-O2):
@SIGTTOU = global i32 0
@SIG_IGN = global i32 0
@SIGTTIN = global i32 0
@.str = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@TIOCSPGRP = global i32 0
define void @sub_sigchld() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @getpid()
store i32 %3, i32* %1
%4 = load i32, i32* @SIGTTOU
%5 = load i32, i32* @SIG_IGN
%6 = tail call i32 @signal(i32 %4, i32 %5)
%7 = load i32, i32* @SIGTTIN
%8 = load i32, i32* @SIG_IGN
%9 = tail call i32 @signal(i32 %7, i32 %8)
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @TIOCSPGRP
%13 = call i32 @ioctl(i32 %11, i32 %12, i32* %1)
%14 = call i32 @close(i32 %11)
ret void
}