#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*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
struct termios *termios_init(struct termios *);
struct termios *init_keyboard(struct termios *init_term,
                              struct termios *new_term) {
  struct termios *iterm = init_term;
  struct termios *nterm = new_term;
  tcgetattr(STDIN_FILENO, iterm);
  nterm = termios_init(iterm);
  tcsetattr(STDIN_FILENO, TCSANOW, nterm);
  return nterm;
}


x86 assembly (clang, -O0):
<init_keyboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    -0x18(%rbp),%rdi
call   1030 <termios_init@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_keyboard>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9a(%rip),%r14
mov    (%r14),%edi
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
mov    %rbx,%rdi
call   1030 <termios_init@plt>
mov    %rax,%rbx
mov    (%r14),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@TCSANOW = global i32 0
define %struct.termios* @init_keyboard(%struct.termios* %0, %struct.termios* %1) {
%3 = alloca %struct.termios*
%4 = alloca %struct.termios*
%5 = alloca %struct.termios*
%6 = alloca %struct.termios*
store %struct.termios* %0, %struct.termios** %3
store %struct.termios* %1, %struct.termios** %4
%7 = load %struct.termios*, %struct.termios** %3
store %struct.termios* %7, %struct.termios** %5
%8 = load %struct.termios*, %struct.termios** %4
store %struct.termios* %8, %struct.termios** %6
%9 = load i32, i32* @STDIN_FILENO
%10 = load %struct.termios*, %struct.termios** %5
%11 = call i32 @tcgetattr(i32 %9, %struct.termios* %10)
%12 = load %struct.termios*, %struct.termios** %5
%13 = call %struct.termios* @termios_init(%struct.termios* %12)
store %struct.termios* %13, %struct.termios** %6
%14 = load i32, i32* @STDIN_FILENO
%15 = load i32, i32* @TCSANOW
%16 = load %struct.termios*, %struct.termios** %6
%17 = call i32 @tcsetattr(i32 %14, i32 %15, %struct.termios* %16)
%18 = load %struct.termios*, %struct.termios** %6
ret %struct.termios* %18
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@TCSANOW = global i32 0
define %struct.termios* @init_keyboard(%struct.termios* %0, %struct.termios* nocapture readnone %1) {
%3 = load i32, i32* @STDIN_FILENO
%4 = tail call i32 @tcgetattr(i32 %3, %struct.termios* %0)
%5 = tail call %struct.termios* @termios_init(%struct.termios* %0)
%6 = load i32, i32* @STDIN_FILENO
%7 = load i32, i32* @TCSANOW
%8 = tail call i32 @tcsetattr(i32 %6, i32 %7, %struct.termios* %5)
ret %struct.termios* %5
}