#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_cflag;
  int c_iflag;
  int *c_cc;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
};

/* Variables and functions */
int CLOCAL;
int CREAD;
int HUPCL;
int IGNBRK;
int IGNPAR;
int /*<<< orphan*/ TCSANOW;
size_t VEOL;
size_t VERASE;
size_t VKILL;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void setline(int fd, int speed, int flags) {
  struct termios tio;
  tcgetattr(fd, &tio);
  tio.c_cflag = flags | HUPCL | CLOCAL | CREAD;
  tio.c_iflag = IGNBRK | IGNPAR;
  tio.c_oflag = 0;
  tio.c_lflag = 0;
  tio.c_cc[VMIN] = 1;
  tio.c_cc[VTIME] = 0;
  tio.c_cc[VEOL] = '\r';
  tio.c_cc[VERASE] = 0;
  tio.c_cc[VKILL] = 0;
  cfsetispeed(&tio, speed);
  cfsetospeed(&tio, speed);
  tcsetattr(fd, TCSANOW, &tio);
}


x86 assembly (clang, -O0):
<setline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    -0xc(%rbp),%eax
mov    0x2e41(%rip),%rcx
or     (%rcx),%eax
mov    0x2e18(%rip),%rcx
or     (%rcx),%eax
mov    0x2e57(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    0x2e12(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2ded(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2db8(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xd,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2df3(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2de6(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r15d
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e43(%rip),%rax
or     (%rax),%ebx
mov    0x2e1a(%rip),%rax
or     (%rax),%ebx
mov    0x2e59(%rip),%rax
or     (%rax),%ebx
mov    0x2e38(%rip),%rax
mov    0x2e19(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ebx,0x8(%rsp)
mov    %ecx,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2e21(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2df8(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dc7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xd,(%rax,%rcx,4)
mov    0x2e06(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dfd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i64, i64 }
@HUPCL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@VEOL = global i64 0
@VERASE = global i64 0
@VKILL = global i64 0
@TCSANOW = global i32 0
define void @setline(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %7)
%10 = load i32, i32* %6
%11 = load i32, i32* @HUPCL
%12 = or i32 %10, %11
%13 = load i32, i32* @CLOCAL
%14 = or i32 %12, %13
%15 = load i32, i32* @CREAD
%16 = or i32 %14, %15
%17 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @IGNBRK
%19 = load i32, i32* @IGNPAR
%20 = or i32 %18, %19
%21 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 4
store i64 0, i64* %22
%23 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
store i64 0, i64* %23
%24 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%25 = load i32*, i32** %24
%26 = load i64, i64* @VMIN
%27 = getelementptr inbounds i32, i32* %25, i64 %26
store i32 1, i32* %27
%28 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%29 = load i32*, i32** %28
%30 = load i64, i64* @VTIME
%31 = getelementptr inbounds i32, i32* %29, i64 %30
store i32 0, i32* %31
%32 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%33 = load i32*, i32** %32
%34 = load i64, i64* @VEOL
%35 = getelementptr inbounds i32, i32* %33, i64 %34
store i32 13, i32* %35
%36 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%37 = load i32*, i32** %36
%38 = load i64, i64* @VERASE
%39 = getelementptr inbounds i32, i32* %37, i64 %38
store i32 0, i32* %39
%40 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%41 = load i32*, i32** %40
%42 = load i64, i64* @VKILL
%43 = getelementptr inbounds i32, i32* %41, i64 %42
store i32 0, i32* %43
%44 = load i32, i32* %5
%45 = call i32 @cfsetispeed(%struct.termios* %7, i32 %44)
%46 = load i32, i32* %5
%47 = call i32 @cfsetospeed(%struct.termios* %7, i32 %46)
%48 = load i32, i32* %4
%49 = load i32, i32* @TCSANOW
%50 = call i32 @tcsetattr(i32 %48, i32 %49, %struct.termios* %7)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i64, i64 }
@HUPCL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@VEOL = global i64 0
@VERASE = global i64 0
@VKILL = global i64 0
@TCSANOW = global i32 0
define void @setline(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %4 to i8*
%6 = call i32 @tcgetattr(i32 %0, %struct.termios* %4)
%7 = load i32, i32* @HUPCL
%8 = or i32 %7, %2
%9 = load i32, i32* @CLOCAL
%10 = or i32 %8, %9
%11 = load i32, i32* @CREAD
%12 = or i32 %10, %11
%13 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @IGNBRK
%15 = load i32, i32* @IGNPAR
%16 = or i32 %15, %14
%17 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 3
%19 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%20 = bitcast i64* %18 to i8*
%21 = load i32*, i32** %19
%22 = load i64, i64* @VMIN
%23 = getelementptr inbounds i32, i32* %21, i64 %22
store i32 1, i32* %23
%24 = load i64, i64* @VTIME
%25 = getelementptr inbounds i32, i32* %21, i64 %24
store i32 0, i32* %25
%26 = load i64, i64* @VEOL
%27 = getelementptr inbounds i32, i32* %21, i64 %26
store i32 13, i32* %27
%28 = load i64, i64* @VERASE
%29 = getelementptr inbounds i32, i32* %21, i64 %28
store i32 0, i32* %29
%30 = load i64, i64* @VKILL
%31 = getelementptr inbounds i32, i32* %21, i64 %30
store i32 0, i32* %31
%32 = call i32 @cfsetispeed(%struct.termios* %4, i32 %1)
%33 = call i32 @cfsetospeed(%struct.termios* %4, i32 %1)
%34 = load i32, i32* @TCSANOW
%35 = call i32 @tcsetattr(i32 %0, i32 %34, %struct.termios* %4)
ret void
}