#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 c_lflag;
};

/* Variables and functions */
int ISIG;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
main() {
  struct termios attrs;
  tcgetattr(0, &attrs);
  attrs.c_lflag = attrs.c_lflag & ~ISIG;
  tcsetattr(0, TCSANOW, &attrs);
  printf("you can't stop me!\n");
  while (1) {
    sleep(1);
    printf("haha\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1050 <tcsetattr@plt>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
jmp    118e <main+0x4e>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8a(%rip),%rbx
nopl   0x0(%rax)
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x50>

LLVM IR (-O0):
%struct.termios = type { i32 }
@ISIG = global i32 0
@TCSANOW = global i32 0
@.str = [20 x i8] c"you can't stop me!\0A\00"
@.str.1 = [6 x i8] c"haha\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.termios
store i32 0, i32* %1
%3 = call i32 @tcgetattr(i32 0, %struct.termios* %2)
%4 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%5 = load i32, i32* %4
%6 = load i32, i32* @ISIG
%7 = xor i32 %6, -1
%8 = and i32 %5, %7
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* @TCSANOW
%11 = call i32 @tcsetattr(i32 0, i32 %10, %struct.termios* %2)
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %0, %13
%14 = call i32 @sleep(i32 1)
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %13
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@ISIG = global i32 0
@TCSANOW = global i32 0
@str = [19 x i8] c"you can't stop me!\00"
@str.2 = [5 x i8] c"haha\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = call i32 @tcgetattr(i32 0, %struct.termios* %1)
%4 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = load i32, i32* @ISIG
%7 = xor i32 %6, -1
%8 = and i32 %5, %7
store i32 %8, i32* %4
%9 = load i32, i32* @TCSANOW
%10 = call i32 @tcsetattr(i32 0, i32 %9, %struct.termios* %1)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %12, %0
%13 = call i32 @sleep(i32 1)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.2, i64 0, i64 0))
br label %12
}