#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 u_int8_t;
struct termios {
  int /*<<< orphan*/ c_iflag;
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ IXON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
int tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
u_int8_t __chatty_control() {
  struct termios tp;
  if (tcgetattr(STDIN_FILENO, &tp) == -1) {
    return 1;
  }
  tp.c_lflag |= ECHO;
  tp.c_iflag |= IXON;
  if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tp) == -1) {
    return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<__chatty_control>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    114f <__chatty_control+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    11a4 <__chatty_control+0x84>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    119d <__chatty_control+0x7d>
movl   $0x2,-0x4(%rbp)
jmp    11a4 <__chatty_control+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__chatty_control>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     117a <__chatty_control+0x5a>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
or     %eax,0xc(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
or     %eax,0x8(%rsp)
mov    (%rbx),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <tcsetattr@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
add    %eax,%eax
jmp    117f <__chatty_control+0x5f>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@IXON = global i32 0
@TCSAFLUSH = global i32 0
define i32 @__chatty_control() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @tcgetattr(i32 %3, %struct.termios* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 1, i32* %1
br label %22
7: ; preds = %0
%8 = load i32, i32* @ECHO
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
%10 = load i32, i32* %9
%11 = or i32 %10, %8
store i32 %11, i32* %9
%12 = load i32, i32* @IXON
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %14, %12
store i32 %15, i32* %13
%16 = load i32, i32* @STDIN_FILENO
%17 = load i32, i32* @TCSAFLUSH
%18 = call i32 @tcsetattr(i32 %16, i32 %17, %struct.termios* %2)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %7
store i32 2, i32* %1
br label %22
21: ; preds = %7
store i32 0, i32* %1
br label %22
22: ; preds = %21, %20, %6
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@IXON = global i32 0
@TCSAFLUSH = global i32 0
define i32 @__chatty_control() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @tcgetattr(i32 %3, %struct.termios* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %20, label %6
6: ; preds = %0
%7 = load i32, i32* @ECHO
%8 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = or i32 %9, %7
store i32 %10, i32* %8
%11 = load i32, i32* @IXON
%12 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @STDIN_FILENO
%16 = load i32, i32* @TCSAFLUSH
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %1)
%18 = icmp eq i32 %17, -1
%19 = select i1 %18, i32 2, i32 0
br label %20
20: ; preds = %6, %0
%21 = phi i32 [ 1, %0 ], [ %19, %6 ]
ret i32 %21
}