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

/* Variables and functions */
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int posix_input_config(int fd, int buffering) {
  struct termios tio;
  char buf;
  tcgetattr(fd, &tio);
  if (!buffering) {
    tio.c_lflag &= ~ICANON;
    tio.c_cc[VTIME] = 0;
    tio.c_cc[VMIN] = 0;
  } else
    tio.c_lflag |= ICANON;
  tcsetattr(fd, TCSANOW, &tio);
  return 0;
}


x86 assembly (clang, -O0):
<posix_input_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1187 <posix_input_config+0x67>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    1196 <posix_input_config+0x76>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<posix_input_config>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1147 <posix_input_config+0x27>
or     %eax,0x8(%rsp)
jmp    1176 <posix_input_config+0x56>
not    %eax
and    %eax,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2e77(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e75(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i64* }
@ICANON = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define i32 @posix_input_config(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios
%6 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %5)
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %2
%12 = load i32, i32* @ICANON
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, %13
store i32 %16, i32* %14
%17 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%18 = load i64*, i64** %17
%19 = load i64, i64* @VTIME
%20 = getelementptr inbounds i64, i64* %18, i64 %19
store i64 0, i64* %20
%21 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%22 = load i64*, i64** %21
%23 = load i64, i64* @VMIN
%24 = getelementptr inbounds i64, i64* %22, i64 %23
store i64 0, i64* %24
br label %30
25: ; preds = %2
%26 = load i32, i32* @ICANON
%27 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%28 = load i32, i32* %27
%29 = or i32 %28, %26
store i32 %29, i32* %27
br label %30
30: ; preds = %25, %11
%31 = load i32, i32* %3
%32 = load i32, i32* @TCSANOW
%33 = call i32 @tcsetattr(i32 %31, i32 %32, %struct.termios* %5)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32, i64* }
@ICANON = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define i32 @posix_input_config(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = icmp eq i32 %1, 0
%7 = load i32, i32* @ICANON
br i1 %6, label %8, label %19
8: ; preds = %2
%9 = xor i32 %7, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, 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* %3, i64 0, i32 1
%14 = load i64*, i64** %13
%15 = load i64, i64* @VTIME
%16 = getelementptr inbounds i64, i64* %14, i64 %15
store i64 0, i64* %16
%17 = load i64, i64* @VMIN
%18 = getelementptr inbounds i64, i64* %14, i64 %17
store i64 0, i64* %18
br label %23
19: ; preds = %2
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = or i32 %21, %7
store i32 %22, i32* %20
br label %23
23: ; preds = %19, %8
%24 = load i32, i32* @TCSANOW
%25 = call i32 @tcsetattr(i32 %0, i32 %24, %struct.termios* %3)
ret i32 0
}