#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 ECHO;
int ICANON;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ memcpy(struct termios *, struct termios *, int);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void setup_console(int t) {
  struct termios our_termios;
  static struct termios old_termios;
  if (t) {
    tcgetattr(0, &old_termios);
    memcpy(&our_termios, &old_termios, sizeof(struct termios));
    our_termios.c_lflag &= !(ECHO | ICANON);
    tcsetattr(0, TCSANOW, &our_termios);
  } else
    tcsetattr(0, TCSANOW, &old_termios);
}


x86 assembly (clang, -O0):
<setup_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11a6 <setup_console+0x76>
xor    %edi,%edi
lea    0x2eee(%rip),%rsi
call   1040 <tcgetattr@plt>
lea    0x2ee2(%rip),%rsi
lea    -0x8(%rbp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    0x2e58(%rip),%rcx
or     (%rcx),%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1050 <tcsetattr@plt>
jmp    11bd <setup_console+0x8d>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0x2e84(%rip),%rdx
call   1050 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_console>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     1191 <setup_console+0x61>
lea    0x2efd(%rip),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0x2e7d(%rip),%rax
mov    0x2e66(%rip),%rcx
mov    (%rcx),%ecx
xor    %edx,%edx
or     (%rax),%ecx
sete   %dl
and    %edx,(%rsp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0x2e9b(%rip),%rdx
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <tcsetattr@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@setup_console.old_termios = internal global %struct.termios zeroinitializer
@ECHO = global i32 0
@ICANON = global i32 0
@TCSANOW = global i32 0
define void @setup_console(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = call i32 @tcgetattr(i32 0, %struct.termios* @setup_console.old_termios)
%8 = call i32 @memcpy(%struct.termios* %3, %struct.termios* @setup_console.old_termios, i32 4)
%9 = load i32, i32* @ECHO
%10 = load i32, i32* @ICANON
%11 = or i32 %9, %10
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
%15 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = and i32 %16, %14
store i32 %17, i32* %15
%18 = load i32, i32* @TCSANOW
%19 = call i32 @tcsetattr(i32 0, i32 %18, %struct.termios* %3)
br label %23
20: ; preds = %1
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 0, i32 %21, %struct.termios* @setup_console.old_termios)
br label %23
23: ; preds = %20, %6
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@setup_console.old_termios = internal global %struct.termios zeroinitializer
@ECHO = global i32 0
@ICANON = global i32 0
@TCSANOW = global i32 0
define void @setup_console(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %18, label %5
5: ; preds = %1
%6 = tail call i32 @tcgetattr(i32 0, %struct.termios* @setup_console.old_termios)
%7 = call i32 @memcpy(%struct.termios* %2, %struct.termios* @setup_console.old_termios, i32 4)
%8 = load i32, i32* @ECHO
%9 = load i32, i32* @ICANON
%10 = or i32 %9, %8
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, %12
store i32 %15, i32* %13
%16 = load i32, i32* @TCSANOW
%17 = call i32 @tcsetattr(i32 0, i32 %16, %struct.termios* %2)
br label %21
18: ; preds = %1
%19 = load i32, i32* @TCSANOW
%20 = tail call i32 @tcsetattr(i32 0, i32 %19, %struct.termios* @setup_console.old_termios)
br label %21
21: ; preds = %18, %5
ret void
}