#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;
  int *c_cc;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
struct termios set_non_canonical() {
  struct termios old_info;
  tcgetattr(0, &old_info);
  struct termios info = old_info;
  info.c_lflag &= ~(ICANON | ECHO);
  info.c_cc[VMIN] = 1;
  info.c_cc[VTIME] = 0;
  tcsetattr(0, TCSANOW, &info);
  return old_info;
}


x86 assembly (clang, -O0):
<set_non_canonical>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %edi,%edi
mov    %edi,-0x24(%rbp)
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
mov    -0x24(%rbp),%edi
movups -0x10(%rbp),%xmm0
movaps %xmm0,-0x20(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
not    %ecx
mov    -0x20(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <tcsetattr@plt>
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rdx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_non_canonical>:
sub    $0x28,%rsp
lea    0x18(%rsp),%rsi
xor    %edi,%edi
call   1030 <tcgetattr@plt>
movups 0x18(%rsp),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e80(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1040 <tcsetattr@plt>
mov    0x18(%rsp),%eax
mov    0x20(%rsp),%rdx
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@ICANON = global i32 0
@ECHO = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define { i32, i32* } @set_non_canonical() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = call i32 @tcgetattr(i32 0, %struct.termios* %1)
%4 = bitcast %struct.termios* %2 to i8*
%5 = bitcast %struct.termios* %1 to i8*
%6 = load i32, i32* @ICANON
%7 = load i32, i32* @ECHO
%8 = or i32 %6, %7
%9 = xor i32 %8, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
%14 = load i32*, i32** %13
%15 = load i64, i64* @VMIN
%16 = getelementptr inbounds i32, i32* %14, i64 %15
store i32 1, i32* %16
%17 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
%18 = load i32*, i32** %17
%19 = load i64, i64* @VTIME
%20 = getelementptr inbounds i32, i32* %18, i64 %19
store i32 0, i32* %20
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 0, i32 %21, %struct.termios* %2)
%23 = bitcast %struct.termios* %1 to { i32, i32* }*
%24 = load { i32, i32* }, { i32, i32* }* %23
ret { i32, i32* } %24
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@ICANON = global i32 0
@ECHO = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define { i32, i32* } @set_non_canonical() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = call i32 @tcgetattr(i32 0, %struct.termios* %1)
%4 = bitcast %struct.termios* %2 to i8*
%5 = bitcast %struct.termios* %1 to i8*
%6 = load i32, i32* @ICANON
%7 = load i32, i32* @ECHO
%8 = or i32 %7, %6
%9 = xor i32 %8, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%14 = load i32*, i32** %13
%15 = load i64, i64* @VMIN
%16 = getelementptr inbounds i32, i32* %14, i64 %15
store i32 1, i32* %16
%17 = load i64, i64* @VTIME
%18 = getelementptr inbounds i32, i32* %14, i64 %17
store i32 0, i32* %18
%19 = load i32, i32* @TCSANOW
%20 = call i32 @tcsetattr(i32 0, i32 %19, %struct.termios* %2)
%21 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%22 = load i32, i32* %21
%23 = insertvalue { i32, i32* } poison, i32 %22, 0
%24 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%25 = load i32*, i32** %24
%26 = insertvalue { i32, i32* } %23, i32* %25, 1
ret { i32, i32* } %26
}