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

/* Variables and functions */
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
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 *);
int init_serial(int fd, int prt) {
  struct termios opt;
  tcgetattr(fd, &opt);
  cfmakeraw(&opt);
  cfsetispeed(&opt, prt);
  cfsetospeed(&opt, prt);
  opt.c_cflag |= (CLOCAL | CREAD);
  opt.c_cflag &= ~CSIZE;
  opt.c_cflag &= ~CRTSCTS;
  opt.c_cflag |= CS8;
  opt.c_cflag &= ~PARENB;
  opt.c_cflag &= ~CSTOPB;
  opt.c_cc[VTIME] = 0;
  opt.c_cc[VMIN] = 0;
  tcsetattr(fd, TCSANOW, &opt);
  return 1;
}


x86 assembly (clang, -O0):
<init_serial>:
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   1050 <tcgetattr@plt>
lea    -0x18(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    0x2e3d(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2dab(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x4(%rbp),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_serial>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    %r14,%rdi
call   1040 <cfmakeraw@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e06(%rip),%rax
mov    0x2e47(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    0x2df8(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2e1b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2dd1(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2dd4(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2dda(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.termios = type { i32, i64* }
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define i32 @init_serial(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 = call i32 @cfmakeraw(%struct.termios* %3)
%7 = call i32 @cfsetispeed(%struct.termios* %3, i32 %1)
%8 = call i32 @cfsetospeed(%struct.termios* %3, i32 %1)
%9 = load i32, i32* @CLOCAL
%10 = load i32, i32* @CREAD
%11 = or i32 %10, %9
%12 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %11, %13
%15 = load i32, i32* @CSIZE
%16 = load i32, i32* @CRTSCTS
%17 = or i32 %15, %16
%18 = xor i32 %17, -1
%19 = and i32 %14, %18
%20 = load i32, i32* @CS8
%21 = or i32 %20, %19
%22 = load i32, i32* @PARENB
%23 = load i32, i32* @CSTOPB
%24 = or i32 %22, %23
%25 = xor i32 %24, -1
%26 = and i32 %21, %25
store i32 %26, i32* %12
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%28 = load i64*, i64** %27
%29 = load i64, i64* @VTIME
%30 = getelementptr inbounds i64, i64* %28, i64 %29
store i64 0, i64* %30
%31 = load i64, i64* @VMIN
%32 = getelementptr inbounds i64, i64* %28, i64 %31
store i64 0, i64* %32
%33 = load i32, i32* @TCSANOW
%34 = call i32 @tcsetattr(i32 %0, i32 %33, %struct.termios* %3)
ret i32 1
}