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

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
struct termios setup_console() {
  struct termios new, old;
  printf("\e[?25l");
  system("clear");
  tcgetattr(STDIN_FILENO, &old);
  new = old;
  new.c_lflag &= ~ICANON;
  new.c_lflag &= ~ECHO;
  tcsetattr(STDIN_FILENO, TCSANOW, &new);
  return old;
}


x86 assembly (clang, -O0):
<setup_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
call   1030 <system@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_console>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
call   1030 <system@plt>
mov    0x2e6c(%rip),%rbx
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    0x2e62(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    (%rbx),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1060 <tcsetattr@plt>
mov    (%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [7 x i8] c"\1B[?25l\00"
@.str.1 = [6 x i8] c"clear\00"
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @setup_console() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %1)
%7 = bitcast %struct.termios* %2 to i8*
%8 = bitcast %struct.termios* %1 to i8*
%9 = load i32, i32* @ICANON
%10 = xor i32 %9, -1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%12 = load i32, i32* %11
%13 = and i32 %12, %10
store i32 %13, i32* %11
%14 = load i32, i32* @ECHO
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @STDIN_FILENO
%20 = load i32, i32* @TCSANOW
%21 = call i32 @tcsetattr(i32 %19, i32 %20, %struct.termios* %2)
%22 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 0
%23 = load i32, i32* %22
ret i32 %23
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [7 x i8] c"\1B[?25l\00"
@.str.1 = [6 x i8] c"clear\00"
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @setup_console() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %1)
%8 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%10 = load i32, i32* %8
%11 = load i32, i32* @ICANON
%12 = load i32, i32* @ECHO
%13 = or i32 %11, %12
%14 = xor i32 %13, -1
%15 = and i32 %10, %14
store i32 %15, i32* %9
%16 = load i32, i32* @STDIN_FILENO
%17 = load i32, i32* @TCSANOW
%18 = call i32 @tcsetattr(i32 %16, i32 %17, %struct.termios* %2)
%19 = load i32, i32* %8
ret i32 %19
}