#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 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 flags, int speed) {
  struct termios t;
  tcgetattr(fd, &t);
  t.c_cflag = flags | CREAD | HUPCL | CLOCAL;
  t.c_iflag = IGNBRK | IGNPAR;
  t.c_oflag = 0;
  t.c_lflag = 0;
  t.c_cc[VMIN] = 1;
  t.c_cc[VTIME] = 0;
  cfsetispeed(&t, speed);
  cfsetospeed(&t, speed);
  tcsetattr(fd, TCSANOW, &t);
}


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    -0x8(%rbp),%eax
mov    0x2e79(%rip),%rcx
or     (%rcx),%eax
mov    0x2e48(%rip),%rcx
or     (%rcx),%eax
mov    0x2e27(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    0x2e22(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2dfd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2df9(%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,%ebp
mov    %esi,%ebx
mov    %edi,%r15d
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e7b(%rip),%rax
or     (%rax),%ebx
mov    0x2e4a(%rip),%rax
or     (%rax),%ebx
mov    0x2e29(%rip),%rax
or     (%rax),%ebx
mov    %ebx,0x8(%rsp)
mov    0x2e44(%rip),%rax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2e31(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e08(%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    0x2e0b(%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 }
@CREAD = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@VMIN = global i64 0
@VTIME = 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* %5
%11 = load i32, i32* @CREAD
%12 = or i32 %10, %11
%13 = load i32, i32* @HUPCL
%14 = or i32 %12, %13
%15 = load i32, i32* @CLOCAL
%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 = load i32, i32* %6
%33 = call i32 @cfsetispeed(%struct.termios* %7, i32 %32)
%34 = load i32, i32* %6
%35 = call i32 @cfsetospeed(%struct.termios* %7, i32 %34)
%36 = load i32, i32* %4
%37 = load i32, i32* @TCSANOW
%38 = call i32 @tcsetattr(i32 %36, i32 %37, %struct.termios* %7)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i64, i64 }
@CREAD = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@VMIN = global i64 0
@VTIME = 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* @CREAD
%8 = or i32 %7, %1
%9 = load i32, i32* @HUPCL
%10 = or i32 %8, %9
%11 = load i32, i32* @CLOCAL
%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 = call i32 @cfsetispeed(%struct.termios* %4, i32 %2)
%27 = call i32 @cfsetospeed(%struct.termios* %4, i32 %2)
%28 = load i32, i32* @TCSANOW
%29 = call i32 @tcsetattr(i32 %0, i32 %28, %struct.termios* %4)
ret void
}