#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 B0;
int CBAUD;
int CBAUDEX;
int CLOCAL;
int CRTSCTS;
int HUPCL;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void serial_deinit(int fd) {
  tcflush(fd, TCIOFLUSH);
  struct termios tios;
  memset(&tios, 0, sizeof(tios));
  tcgetattr(fd, &tios);
  tios.c_cflag &= ~(CBAUD | CBAUDEX | CRTSCTS);
  tios.c_cflag |= HUPCL | CLOCAL | B0;
  tcsetattr(fd, TCSAFLUSH, &tios);
  close(fd);
}


x86 assembly (clang, -O0):
<serial_deinit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    0x2e38(%rip),%rcx
or     (%rcx),%eax
mov    0x2e07(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    0x2de4(%rip),%rcx
or     (%rcx),%eax
mov    0x2e13(%rip),%rcx
or     (%rcx),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_deinit>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2e29(%rip),%rax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e0f(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    (%rsp),%ecx
mov    0x2e19(%rip),%rax
mov    0x2df2(%rip),%rdx
mov    0x2e23(%rip),%rsi
or     (%rax),%ecx
or     (%rdx),%ecx
or     (%rsi),%ecx
mov    %ecx,(%rsp)
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCIOFLUSH = global i32 0
@CBAUD = global i32 0
@CBAUDEX = global i32 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@B0 = global i32 0
@TCSAFLUSH = global i32 0
define void @serial_deinit(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @TCIOFLUSH
%6 = call i32 @tcflush(i32 %4, i32 %5)
%7 = call i32 @memset(%struct.termios* %3, i32 0, i32 4)
%8 = load i32, i32* %2
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %3)
%10 = load i32, i32* @CBAUD
%11 = load i32, i32* @CBAUDEX
%12 = or i32 %10, %11
%13 = load i32, i32* @CRTSCTS
%14 = or i32 %12, %13
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @HUPCL
%20 = load i32, i32* @CLOCAL
%21 = or i32 %19, %20
%22 = load i32, i32* @B0
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* %2
%28 = load i32, i32* @TCSAFLUSH
%29 = call i32 @tcsetattr(i32 %27, i32 %28, %struct.termios* %3)
%30 = load i32, i32* %2
%31 = call i32 @close(i32 %30)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCIOFLUSH = global i32 0
@CBAUD = global i32 0
@CBAUDEX = global i32 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@B0 = global i32 0
@TCSAFLUSH = global i32 0
define void @serial_deinit(i32 %0) {
%2 = alloca %struct.termios
%3 = load i32, i32* @TCIOFLUSH
%4 = tail call i32 @tcflush(i32 %0, i32 %3)
%5 = bitcast %struct.termios* %2 to i8*
%6 = call i32 @memset(%struct.termios* %2, i32 0, i32 4)
%7 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%8 = load i32, i32* @CBAUD
%9 = load i32, i32* @CBAUDEX
%10 = or i32 %9, %8
%11 = load i32, i32* @CRTSCTS
%12 = or i32 %10, %11
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, %13
%17 = load i32, i32* @HUPCL
%18 = load i32, i32* @CLOCAL
%19 = load i32, i32* @B0
%20 = or i32 %17, %16
%21 = or i32 %20, %18
%22 = or i32 %21, %19
store i32 %22, i32* %14
%23 = load i32, i32* @TCSAFLUSH
%24 = call i32 @tcsetattr(i32 %0, i32 %23, %struct.termios* %2)
%25 = call i32 @close(i32 %0)
ret void
}