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

/* Variables and functions */
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void setup_terminal(struct termios *old_args) {
  tcgetattr(0, old_args);
  struct termios new_args = *old_args;
  new_args.c_lflag &= ~ICANON;
  new_args.c_cc[VMIN] = 1;
  tcsetattr(0, TCSANOW, &new_args);
}


x86 assembly (clang, -O0):
<setup_terminal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1030 <tcgetattr@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x18(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_terminal>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <tcgetattr@plt>
movups (%rbx),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    (%rsp),%rax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.termios = type { i32*, i32 }
@ICANON = global i32 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define void @setup_terminal(%struct.termios* %0) {
%2 = alloca %struct.termios
%3 = tail call i32 @tcgetattr(i32 0, %struct.termios* %0)
%4 = bitcast %struct.termios* %2 to i8*
%5 = bitcast %struct.termios* %0 to i8*
%6 = load i32, i32* @ICANON
%7 = xor i32 %6, -1
%8 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%9 = load i32, i32* %8
%10 = and i32 %9, %7
store i32 %10, i32* %8
%11 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%12 = load i32*, i32** %11
%13 = load i64, i64* @VMIN
%14 = getelementptr inbounds i32, i32* %12, i64 %13
store i32 1, i32* %14
%15 = load i32, i32* @TCSANOW
%16 = call i32 @tcsetattr(i32 0, i32 %15, %struct.termios* %2)
ret void
}