#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;
  scalar_t__ c_oflag;
  scalar_t__ c_lflag;
  int /*<<< orphan*/ c_iflag;
};
typedef int /*<<< orphan*/ speed_t;

/* Variables and functions */
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ INPCK;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void init_serial(int fd, speed_t baud_rate) {
  struct termios tty;
  tcgetattr(fd, &tty);
  tty.c_iflag = INPCK;
  tty.c_lflag = 0;
  tty.c_oflag = 0;
  tty.c_cflag = CREAD | CS8 | CLOCAL;
  tty.c_cc[VMIN] = 0;
  tty.c_cc[VTIME] = 0;
  cfsetispeed(&tty, baud_rate);
  cfsetospeed(&tty, baud_rate);
  tcsetattr(fd, TCSANOW, &tty);
}


x86 assembly (clang, -O0):
<init_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    0x2e52(%rip),%rcx
or     (%rcx),%eax
mov    0x2e19(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e31(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2e03(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
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    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_serial>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
xorps  %xmm0,%xmm0
mov    0x2e70(%rip),%rax
mov    0x2e61(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
movups %xmm0,0x18(%rsp)
mov    0x2e21(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2e37(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.termios = type { i32, i64*, i64, i64, i32 }
@INPCK = global i32 0
@CREAD = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define void @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 = load i32, i32* @INPCK
%7 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%9 = bitcast i64* %8 to i8*
%10 = load i32, i32* @CREAD
%11 = load i32, i32* @CS8
%12 = or i32 %11, %10
%13 = load i32, i32* @CLOCAL
%14 = or i32 %12, %13
%15 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%17 = load i64*, i64** %16
%18 = load i64, i64* @VMIN
%19 = getelementptr inbounds i64, i64* %17, i64 %18
store i64 0, i64* %19
%20 = load i64, i64* @VTIME
%21 = getelementptr inbounds i64, i64* %17, i64 %20
store i64 0, i64* %21
%22 = call i32 @cfsetispeed(%struct.termios* %3, i32 %1)
%23 = call i32 @cfsetospeed(%struct.termios* %3, i32 %1)
%24 = load i32, i32* @TCSANOW
%25 = call i32 @tcsetattr(i32 %0, i32 %24, %struct.termios* %3)
ret void
}