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

/* Variables and functions */
int /*<<< orphan*/ SIGTSTP;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ TCSANOW;
size_t VDISCARD;
size_t VEOF;
size_t VERASE;
size_t VINTR;
size_t VKILL;
size_t VLNEXT;
size_t VQUIT;
size_t VREPRINT;
size_t VSTART;
size_t VSTOP;
size_t VSUSP;
size_t VWERASE;
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void md_control_keyboard(int mode) {
  static char called_before = 0;
  static struct termios tc_orig;
  static struct termios tc_temp;
  signal(SIGTSTP, SIG_IGN);
  if (!called_before) {
    called_before = 1;
    tcgetattr(0, &tc_orig);
  }
  tc_temp = tc_orig;
  if (!mode) {
    tc_temp.c_cc[VINTR] = -1;
    tc_temp.c_cc[VQUIT] = -1;
    tc_temp.c_cc[VERASE] = -1;
    tc_temp.c_cc[VKILL] = -1;
    tc_temp.c_cc[VEOF] = -1;
    tc_temp.c_cc[VSTART] = -1;
    tc_temp.c_cc[VSTOP] = -1;
    tc_temp.c_cc[VSUSP] = -1;
    tc_temp.c_cc[VLNEXT] = -1;
    tc_temp.c_cc[VWERASE] = -1;
    tc_temp.c_cc[VREPRINT] = -1;
    tc_temp.c_cc[VDISCARD] = -1;
  }
  tcsetattr(0, TCSANOW, &tc_temp);
}


x86 assembly (clang, -O0):
<md_control_keyboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
cmpb   $0x0,0x2ee7(%rip)
jne    1174 <md_control_keyboard+0x44>
movb   $0x1,0x2eda(%rip)
xor    %edi,%edi
lea    0x2ed9(%rip),%rsi
call   1040 <tcgetattr@plt>
mov    0x2ecd(%rip),%rax
mov    %rax,0x2ece(%rip)
cmpl   $0x0,-0x4(%rbp)
jne    12ac <md_control_keyboard+0x17c>
mov    0x2ebd(%rip),%rax
mov    0x2dde(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2ea5(%rip),%rax
mov    0x2dde(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e8d(%rip),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e75(%rip),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e5d(%rip),%rax
mov    0x2d6e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e45(%rip),%rax
mov    0x2d5e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e2d(%rip),%rax
mov    0x2dae(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e15(%rip),%rax
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2dfd(%rip),%rax
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2de5(%rip),%rax
mov    0x2d76(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2dcd(%rip),%rax
mov    0x2d26(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2db5(%rip),%rax
mov    0x2d2e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0x2d92(%rip),%rdx
call   1050 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md_control_keyboard>:
push   %rbx
mov    %edi,%ebx
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
cmpb   $0x0,0x2eef(%rip)
jne    1168 <md_control_keyboard+0x38>
movb   $0x1,0x2ee6(%rip)
lea    0x2ee7(%rip),%rsi
xor    %edi,%edi
call   1040 <tcgetattr@plt>
mov    0x2ed9(%rip),%rax
mov    %rax,0x2eda(%rip)
test   %ebx,%ebx
jne    124a <md_control_keyboard+0x11a>
mov    0x2df3(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2dfa(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e21(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2e28(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d9f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d96(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2ded(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d84(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d8b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2dca(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d81(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d90(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
lea    0x2df6(%rip),%rdx
xor    %edi,%edi
pop    %rbx
jmp    1050 <tcsetattr@plt>

LLVM IR (-O0):
%struct.termios = type { i32* }
@md_control_keyboard.called_before = internal global i8 0
@md_control_keyboard.tc_orig = internal global %struct.termios zeroinitializer
@md_control_keyboard.tc_temp = internal global %struct.termios zeroinitializer
@SIGTSTP = global i32 0
@SIG_IGN = global i32 0
@VINTR = global i64 0
@VQUIT = global i64 0
@VERASE = global i64 0
@VKILL = global i64 0
@VEOF = global i64 0
@VSTART = global i64 0
@VSTOP = global i64 0
@VSUSP = global i64 0
@VLNEXT = global i64 0
@VWERASE = global i64 0
@VREPRINT = global i64 0
@VDISCARD = global i64 0
@TCSANOW = global i32 0
define void @md_control_keyboard(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @SIGTSTP
%4 = load i32, i32* @SIG_IGN
%5 = call i32 @signal(i32 %3, i32 %4)
%6 = load i8, i8* @md_control_keyboard.called_before
%7 = icmp ne i8 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
store i8 1, i8* @md_control_keyboard.called_before
%9 = call i32 @tcgetattr(i32 0, %struct.termios* @md_control_keyboard.tc_orig)
br label %10
10: ; preds = %8, %1
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %50, label %13
13: ; preds = %10
%14 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%15 = load i64, i64* @VINTR
%16 = getelementptr inbounds i32, i32* %14, i64 %15
store i32 -1, i32* %16
%17 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%18 = load i64, i64* @VQUIT
%19 = getelementptr inbounds i32, i32* %17, i64 %18
store i32 -1, i32* %19
%20 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%21 = load i64, i64* @VERASE
%22 = getelementptr inbounds i32, i32* %20, i64 %21
store i32 -1, i32* %22
%23 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%24 = load i64, i64* @VKILL
%25 = getelementptr inbounds i32, i32* %23, i64 %24
store i32 -1, i32* %25
%26 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%27 = load i64, i64* @VEOF
%28 = getelementptr inbounds i32, i32* %26, i64 %27
store i32 -1, i32* %28
%29 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%30 = load i64, i64* @VSTART
%31 = getelementptr inbounds i32, i32* %29, i64 %30
store i32 -1, i32* %31
%32 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%33 = load i64, i64* @VSTOP
%34 = getelementptr inbounds i32, i32* %32, i64 %33
store i32 -1, i32* %34
%35 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%36 = load i64, i64* @VSUSP
%37 = getelementptr inbounds i32, i32* %35, i64 %36
store i32 -1, i32* %37
%38 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%39 = load i64, i64* @VLNEXT
%40 = getelementptr inbounds i32, i32* %38, i64 %39
store i32 -1, i32* %40
%41 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%42 = load i64, i64* @VWERASE
%43 = getelementptr inbounds i32, i32* %41, i64 %42
store i32 -1, i32* %43
%44 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%45 = load i64, i64* @VREPRINT
%46 = getelementptr inbounds i32, i32* %44, i64 %45
store i32 -1, i32* %46
%47 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* @md_control_keyboard.tc_temp, i32 0, i32 0)
%48 = load i64, i64* @VDISCARD
%49 = getelementptr inbounds i32, i32* %47, i64 %48
store i32 -1, i32* %49
br label %50
50: ; preds = %13, %10
%51 = load i32, i32* @TCSANOW
%52 = call i32 @tcsetattr(i32 0, i32 %51, %struct.termios* @md_control_keyboard.tc_temp)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32* }
@md_control_keyboard.called_before = internal unnamed_addr global i1 false
@md_control_keyboard.tc_orig = internal global %struct.termios zeroinitializer
@md_control_keyboard.tc_temp = internal global %struct.termios zeroinitializer
@SIGTSTP = global i32 0
@SIG_IGN = global i32 0
@VINTR = global i64 0
@VQUIT = global i64 0
@VERASE = global i64 0
@VKILL = global i64 0
@VEOF = global i64 0
@VSTART = global i64 0
@VSTOP = global i64 0
@VSUSP = global i64 0
@VLNEXT = global i64 0
@VWERASE = global i64 0
@VREPRINT = global i64 0
@VDISCARD = global i64 0
@TCSANOW = global i32 0
define void @md_control_keyboard(i32 %0) {
%2 = load i32, i32* @SIGTSTP
%3 = load i32, i32* @SIG_IGN
%4 = tail call i32 @signal(i32 %2, i32 %3)
%5 = load i1, i1* @md_control_keyboard.called_before
br i1 %5, label %8, label %6
6: ; preds = %1
store i1 true, i1* @md_control_keyboard.called_before
%7 = tail call i32 @tcgetattr(i32 0, %struct.termios* @md_control_keyboard.tc_orig)
br label %8
8: ; preds = %6, %1
%9 = load i64, i64* bitcast (%struct.termios* @md_control_keyboard.tc_orig to i64*)
store i64 %9, i64* bitcast (%struct.termios* @md_control_keyboard.tc_temp to i64*)
%10 = icmp eq i32 %0, 0
%11 = inttoptr i64 %9 to i32*
br i1 %10, label %12, label %37
12: ; preds = %8
%13 = load i64, i64* @VINTR
%14 = getelementptr inbounds i32, i32* %11, i64 %13
store i32 -1, i32* %14
%15 = load i64, i64* @VQUIT
%16 = getelementptr inbounds i32, i32* %11, i64 %15
store i32 -1, i32* %16
%17 = load i64, i64* @VERASE
%18 = getelementptr inbounds i32, i32* %11, i64 %17
store i32 -1, i32* %18
%19 = load i64, i64* @VKILL
%20 = getelementptr inbounds i32, i32* %11, i64 %19
store i32 -1, i32* %20
%21 = load i64, i64* @VEOF
%22 = getelementptr inbounds i32, i32* %11, i64 %21
store i32 -1, i32* %22
%23 = load i64, i64* @VSTART
%24 = getelementptr inbounds i32, i32* %11, i64 %23
store i32 -1, i32* %24
%25 = load i64, i64* @VSTOP
%26 = getelementptr inbounds i32, i32* %11, i64 %25
store i32 -1, i32* %26
%27 = load i64, i64* @VSUSP
%28 = getelementptr inbounds i32, i32* %11, i64 %27
store i32 -1, i32* %28
%29 = load i64, i64* @VLNEXT
%30 = getelementptr inbounds i32, i32* %11, i64 %29
store i32 -1, i32* %30
%31 = load i64, i64* @VWERASE
%32 = getelementptr inbounds i32, i32* %11, i64 %31
store i32 -1, i32* %32
%33 = load i64, i64* @VREPRINT
%34 = getelementptr inbounds i32, i32* %11, i64 %33
store i32 -1, i32* %34
%35 = load i64, i64* @VDISCARD
%36 = getelementptr inbounds i32, i32* %11, i64 %35
store i32 -1, i32* %36
br label %37
37: ; preds = %12, %8
%38 = load i32, i32* @TCSANOW
%39 = tail call i32 @tcsetattr(i32 0, i32 %38, %struct.termios* @md_control_keyboard.tc_temp)
ret void
}