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

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void termset(struct termios *tio) {
  fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) ^ O_NONBLOCK);
  tcsetattr(STDIN_FILENO, TCSANOW, tio);
}


x86 assembly (clang, -O0):
<termset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    %eax,%edx
mov    0x2e7c(%rip),%rax
xor    (%rax),%edx
call   1030 <fcntl@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<termset>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e8f(%rip),%r15
mov    (%r15),%ebp
mov    0x2e95(%rip),%rax
mov    (%rax),%ebx
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2e92(%rip),%rcx
xor    (%rcx),%eax
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <fcntl@plt>
mov    (%r15),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <tcsetattr@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@TCSANOW = global i32 0
define void @termset(%struct.termios* %0) {
%2 = alloca %struct.termios*
store %struct.termios* %0, %struct.termios** %2
%3 = load i32, i32* @STDIN_FILENO
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @STDIN_FILENO
%6 = load i32, i32* @F_GETFL
%7 = call i32 @fcntl(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @O_NONBLOCK
%9 = xor i32 %7, %8
%10 = call i32 @fcntl(i32 %3, i32 %4, i32 %9)
%11 = load i32, i32* @STDIN_FILENO
%12 = load i32, i32* @TCSANOW
%13 = load %struct.termios*, %struct.termios** %2
%14 = call i32 @tcsetattr(i32 %11, i32 %12, %struct.termios* %13)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@TCSANOW = global i32 0
define void @termset(%struct.termios* %0) {
%2 = load i32, i32* @STDIN_FILENO
%3 = load i32, i32* @F_SETFL
%4 = load i32, i32* @F_GETFL
%5 = tail call i32 @fcntl(i32 %2, i32 %4, i32 0)
%6 = load i32, i32* @O_NONBLOCK
%7 = xor i32 %6, %5
%8 = tail call i32 @fcntl(i32 %2, i32 %3, i32 %7)
%9 = load i32, i32* @STDIN_FILENO
%10 = load i32, i32* @TCSANOW
%11 = tail call i32 @tcsetattr(i32 %9, i32 %10, %struct.termios* %0)
ret void
}