#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_lflag;
  scalar_t__ *c_cc;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int ECHO;
int ECHOE;
int ECHONL;
int ICANON;
int /*<<< orphan*/ IGNBRK;
int ISIG;
int /*<<< orphan*/ TCSADRAIN;
int TOSTOP;
size_t VEOL;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void dosetpty() {
  struct termios ti;
  tcgetattr(0, &ti);
  ti.c_iflag |= IGNBRK;
  ti.c_lflag &= ~(ISIG | TOSTOP);
  ti.c_lflag |= ICANON | ECHO | ECHOE | ECHONL;
  ti.c_cc[VEOL] = 0;
  tcsetattr(0, TCSADRAIN, &ti);
}


x86 assembly (clang, -O0):
<dosetpty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1030 <tcgetattr@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    0x2e96(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    0x2e73(%rip),%rcx
or     (%rcx),%eax
mov    0x2e62(%rip),%rcx
or     (%rcx),%eax
mov    0x2e39(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e1c(%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):
<dosetpty>:
push   %rbx
sub    $0x20,%rsp
lea    0x8(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <tcgetattr@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
or     %eax,0x18(%rsp)
mov    0x2e88(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    0x8(%rsp),%ecx
mov    0x2e48(%rip),%rax
mov    0x2e79(%rip),%rdx
mov    0x2e6a(%rip),%rsi
mov    0x2e43(%rip),%rdi
or     (%rax),%ecx
or     (%rdx),%ecx
or     (%rsi),%ecx
or     (%rdi),%ecx
mov    %ecx,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbx,%rdx
call   1040 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i64*, i32 }
@IGNBRK = global i32 0
@ISIG = global i32 0
@TOSTOP = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHONL = global i32 0
@VEOL = global i64 0
@TCSADRAIN = global i32 0
define void @dosetpty() {
%1 = alloca %struct.termios
%2 = call i32 @tcgetattr(i32 0, %struct.termios* %1)
%3 = load i32, i32* @IGNBRK
%4 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 2
%5 = load i32, i32* %4
%6 = or i32 %5, %3
store i32 %6, i32* %4
%7 = load i32, i32* @ISIG
%8 = load i32, i32* @TOSTOP
%9 = or i32 %7, %8
%10 = xor i32 %9, -1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 0
%12 = load i32, i32* %11
%13 = and i32 %12, %10
store i32 %13, i32* %11
%14 = load i32, i32* @ICANON
%15 = load i32, i32* @ECHO
%16 = or i32 %14, %15
%17 = load i32, i32* @ECHOE
%18 = or i32 %16, %17
%19 = load i32, i32* @ECHONL
%20 = or i32 %18, %19
%21 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 0
%22 = load i32, i32* %21
%23 = or i32 %22, %20
store i32 %23, i32* %21
%24 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 1
%25 = load i64*, i64** %24
%26 = load i64, i64* @VEOL
%27 = getelementptr inbounds i64, i64* %25, i64 %26
store i64 0, i64* %27
%28 = load i32, i32* @TCSADRAIN
%29 = call i32 @tcsetattr(i32 0, i32 %28, %struct.termios* %1)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i64*, i32 }
@IGNBRK = global i32 0
@ISIG = global i32 0
@TOSTOP = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHONL = global i32 0
@VEOL = global i64 0
@TCSADRAIN = global i32 0
define void @dosetpty() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = call i32 @tcgetattr(i32 0, %struct.termios* %1)
%4 = load i32, i32* @IGNBRK
%5 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%6 = load i32, i32* %5
%7 = or i32 %6, %4
store i32 %7, i32* %5
%8 = load i32, i32* @ISIG
%9 = load i32, i32* @TOSTOP
%10 = or i32 %9, %8
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
%15 = load i32, i32* @ICANON
%16 = load i32, i32* @ECHO
%17 = load i32, i32* @ECHOE
%18 = load i32, i32* @ECHONL
%19 = or i32 %15, %14
%20 = or i32 %19, %16
%21 = or i32 %20, %17
%22 = or i32 %21, %18
store i32 %22, i32* %12
%23 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%24 = load i64*, i64** %23
%25 = load i64, i64* @VEOL
%26 = getelementptr inbounds i64, i64* %24, i64 %25
store i64 0, i64* %26
%27 = load i32, i32* @TCSADRAIN
%28 = call i32 @tcsetattr(i32 0, i32 %27, %struct.termios* %1)
ret void
}