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

/* Variables and functions */
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int setterminal(int fd) {
  struct termios newfd;
  tcgetattr(fd, &newfd);
  cfmakeraw(&newfd);
  newfd.c_cc[VMIN] = 1;
  newfd.c_cc[VTIME] = 1;
  newfd.c_cflag |= CSTOPB;
  tcsetattr(fd, TCSANOW, &newfd);
  return 0;
}


x86 assembly (clang, -O0):
<setterminal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
lea    -0x18(%rbp),%rdi
call   1030 <cfmakeraw@plt>
mov    -0x18(%rbp),%rax
mov    0x2e85(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2e60(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <tcsetattr@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setterminal>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    %r14,%rdi
call   1030 <cfmakeraw@plt>
mov    0x8(%rsp),%rax
mov    0x2e86(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e65(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
or     %eax,0x10(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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