#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 */
struct termios {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SIGTTOU;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ alarm(int);
scalar_t__ getpid();
int /*<<< orphan*/ printf(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int /*<<< orphan*/ usleep(int);
int main() {
  signal(SIGTTOU, SIG_DFL);
  alarm(240);
  int count = 0;
  while (1) {
    struct termios termios;
    printf("pid=%ld, count=%d\n", (long)getpid(), count++);
    tcgetattr(0, &termios);
    tcsetattr(0, TCSANOW, &termios);
    usleep(100000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    $0xf0,%edi
call   1050 <alarm@plt>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
mov    -0x8(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x8(%rbp)
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
jmp    11a7 <main+0x37>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    $0xf0,%edi
call   1050 <alarm@plt>
lea    0xe5c(%rip),%r14
lea    0x8(%rsp),%r15
mov    0x2e30(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0x1(%rbx),%ebp
mov    %r14,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <tcgetattr@plt>
mov    (%r12),%esi
xor    %edi,%edi
mov    %r15,%rdx
call   1080 <tcsetattr@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    %ebp,%ebx
jmp    11c0 <main+0x50>

LLVM IR (-O0):
%struct.termios = type { i32 }
@SIGTTOU = global i32 0
@SIG_DFL = global i32 0
@.str = [19 x i8] c"pid=%ld, count=%d\0A\00"
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.termios
store i32 0, i32* %1
%4 = load i32, i32* @SIGTTOU
%5 = load i32, i32* @SIG_DFL
%6 = call i32 @signal(i32 %4, i32 %5)
%7 = call i32 @alarm(i32 240)
store i32 0, i32* %2
br label %8
8: ; preds = %0, %8
%9 = call i64 (...) @getpid()
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
store i32 %11, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %9, i32 %10)
%13 = call i32 @tcgetattr(i32 0, %struct.termios* %3)
%14 = load i32, i32* @TCSANOW
%15 = call i32 @tcsetattr(i32 0, i32 %14, %struct.termios* %3)
%16 = call i32 @usleep(i32 100000)
br label %8
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@SIGTTOU = global i32 0
@SIG_DFL = global i32 0
@.str = [19 x i8] c"pid=%ld, count=%d\0A\00"
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca %struct.termios
%2 = load i32, i32* @SIGTTOU
%3 = load i32, i32* @SIG_DFL
%4 = tail call i32 @signal(i32 %2, i32 %3)
%5 = tail call i32 @alarm(i32 240)
%6 = bitcast %struct.termios* %1 to i8*
br label %7
7: ; preds = %7, %0
%8 = phi i32 [ 0, %0 ], [ %10, %7 ]
%9 = call i64 (...) @getpid()
%10 = add nuw nsw i32 %8, 1
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %9, i32 %8)
%12 = call i32 @tcgetattr(i32 0, %struct.termios* %1)
%13 = load i32, i32* @TCSANOW
%14 = call i32 @tcsetattr(i32 0, i32 %13, %struct.termios* %1)
%15 = call i32 @usleep(i32 100000)
br label %7
}