#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 */
typedef int /*<<< orphan*/ tios;
struct termios {
  int c_cflag;
};

/* Variables and functions */
int CBAUD;
int CBAUDEX;
int CLOCAL;
int CRTSCTS;
int HUPCL;
int /*<<< orphan*/ TCSADRAIN;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
void serial_init(int fd, int baudtermio) {
  int res;
  struct termios tios;
  memset(&tios, 0, sizeof(tios));
  res = tcgetattr(fd, &tios);
  assert(res == 0);
  tios.c_cflag &= ~(CRTSCTS | CBAUD | CBAUDEX);
  tios.c_cflag |= HUPCL | CLOCAL | baudtermio;
  res = tcsetattr(fd, TCSADRAIN, &tios);
  assert(res == 0);
}


x86 assembly (clang, -O0):
<serial_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    0x2e32(%rip),%rcx
or     (%rcx),%eax
mov    0x2e41(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    0x2dfe(%rip),%rcx
or     (%rcx),%eax
or     -0x8(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2e3a(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e48(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x8(%rsp),%ecx
mov    0x2e31(%rip),%rax
mov    0x2e0a(%rip),%rdx
or     %ebp,%ecx
or     (%rax),%ecx
or     (%rdx),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CRTSCTS = global i32 0
@CBAUD = global i32 0
@CBAUDEX = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@TCSADRAIN = global i32 0
define void @serial_init(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i32 @memset(%struct.termios* %6, i32 0, i32 4)
%8 = load i32, i32* %3
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %6)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* @CRTSCTS
%15 = load i32, i32* @CBAUD
%16 = or i32 %14, %15
%17 = load i32, i32* @CBAUDEX
%18 = or i32 %16, %17
%19 = xor i32 %18, -1
%20 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @HUPCL
%24 = load i32, i32* @CLOCAL
%25 = or i32 %23, %24
%26 = load i32, i32* %4
%27 = or i32 %25, %26
%28 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%29 = load i32, i32* %28
%30 = or i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* %3
%32 = load i32, i32* @TCSADRAIN
%33 = call i32 @tcsetattr(i32 %31, i32 %32, %struct.termios* %6)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CRTSCTS = global i32 0
@CBAUD = global i32 0
@CBAUDEX = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@TCSADRAIN = global i32 0
define void @serial_init(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @memset(%struct.termios* %3, i32 0, i32 4)
%6 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* @CRTSCTS
%11 = load i32, i32* @CBAUD
%12 = or i32 %11, %10
%13 = load i32, i32* @CBAUDEX
%14 = or i32 %12, %13
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
%19 = load i32, i32* @HUPCL
%20 = load i32, i32* @CLOCAL
%21 = or i32 %18, %1
%22 = or i32 %21, %19
%23 = or i32 %22, %20
store i32 %23, i32* %16
%24 = load i32, i32* @TCSADRAIN
%25 = call i32 @tcsetattr(i32 %0, i32 %24, %struct.termios* %3)
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
ret void
}