#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_cc;
  int /*<<< orphan*/ c_cflag;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ INPCK;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCIOFLUSH;
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*/ perror(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
void init_com(int fd) {
  int status;
  struct termios Opt;
  tcgetattr(fd, &Opt);
  tcflush(fd, TCIOFLUSH);
  cfsetispeed(&Opt, B115200);
  cfsetospeed(&Opt, B115200);
  Opt.c_cflag &= ~CSIZE;
  Opt.c_cflag |= CS8;
  Opt.c_cflag &= ~PARENB;
  Opt.c_iflag &= ~INPCK;
  Opt.c_cflag &= ~CSTOPB;
  Opt.c_cc[VTIME] = 100;
  Opt.c_cc[VMIN] = 0;
  status = tcsetattr(fd, TCSANOW, &Opt);
  if (status != 0) {
    perror("Init Com  Error");
    return;
  }
  tcflush(fd, TCIOFLUSH);
}


x86 assembly (clang, -O0):
<init_com>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x4(%rbp),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d92(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x64,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1260 <init_com+0x100>
lea    0xdaa(%rip),%rdi
call   1080 <perror@plt>
jmp    1271 <init_com+0x111>
mov    -0x4(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_com>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e2f(%rip),%r15
mov    (%r15),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2e16(%rip),%r12
mov    (%r12),%esi
mov    %r14,%rdi
call   1070 <cfsetispeed@plt>
mov    (%r12),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x10(%rsp),%eax
mov    0x2e18(%rip),%rcx
or     (%rcx),%eax
mov    0x2e1f(%rip),%rcx
mov    0x2de8(%rip),%rdx
mov    (%rdx),%edx
not    %edx
and    %edx,0x14(%rsp)
mov    (%rcx),%ecx
mov    0x2daf(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2da9(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x64,(%rax,%rcx,4)
mov    0x2dc8(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %eax,%eax
jne    123f <init_com+0xdf>
mov    (%r15),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdba(%rip),%rdi
call   1080 <perror@plt>
jmp    1233 <init_com+0xd3>

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i32 }
@TCIOFLUSH = global i32 0
@B115200 = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@INPCK = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@.str = [16 x i8] c"Init Com Error\00"
define void @init_com(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = load i32, i32* %2
%8 = load i32, i32* @TCIOFLUSH
%9 = call i32 @tcflush(i32 %7, i32 %8)
%10 = load i32, i32* @B115200
%11 = call i32 @cfsetispeed(%struct.termios* %4, i32 %10)
%12 = load i32, i32* @B115200
%13 = call i32 @cfsetospeed(%struct.termios* %4, i32 %12)
%14 = load i32, i32* @CSIZE
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @CS8
%20 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @PARENB
%24 = xor i32 %23, -1
%25 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%26 = load i32, i32* %25
%27 = and i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* @INPCK
%29 = xor i32 %28, -1
%30 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
%31 = load i32, i32* %30
%32 = and i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* @CSTOPB
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%39 = load i32*, i32** %38
%40 = load i64, i64* @VTIME
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 100, i32* %41
%42 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%43 = load i32*, i32** %42
%44 = load i64, i64* @VMIN
%45 = getelementptr inbounds i32, i32* %43, i64 %44
store i32 0, i32* %45
%46 = load i32, i32* %2
%47 = load i32, i32* @TCSANOW
%48 = call i32 @tcsetattr(i32 %46, i32 %47, %struct.termios* %4)
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %1
%52 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %57
53: ; preds = %1
%54 = load i32, i32* %2
%55 = load i32, i32* @TCIOFLUSH
%56 = call i32 @tcflush(i32 %54, i32 %55)
br label %57
57: ; preds = %53, %51
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i32 }
@TCIOFLUSH = global i32 0
@B115200 = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@INPCK = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@.str = [16 x i8] c"Init Com Error\00"
define void @init_com(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = load i32, i32* @TCIOFLUSH
%6 = call i32 @tcflush(i32 %0, i32 %5)
%7 = load i32, i32* @B115200
%8 = call i32 @cfsetispeed(%struct.termios* %2, i32 %7)
%9 = load i32, i32* @B115200
%10 = call i32 @cfsetospeed(%struct.termios* %2, i32 %9)
%11 = load i32, i32* @CSIZE
%12 = xor i32 %11, -1
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%14 = load i32, i32* %13
%15 = and i32 %14, %12
%16 = load i32, i32* @CS8
%17 = or i32 %16, %15
%18 = load i32, i32* @PARENB
%19 = load i32, i32* @INPCK
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* @CSTOPB
%25 = or i32 %18, %24
%26 = xor i32 %25, -1
%27 = and i32 %17, %26
store i32 %27, i32* %13
%28 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%29 = load i32*, i32** %28
%30 = load i64, i64* @VTIME
%31 = getelementptr inbounds i32, i32* %29, i64 %30
store i32 100, i32* %31
%32 = load i64, i64* @VMIN
%33 = getelementptr inbounds i32, i32* %29, i64 %32
store i32 0, i32* %33
%34 = load i32, i32* @TCSANOW
%35 = call i32 @tcsetattr(i32 %0, i32 %34, %struct.termios* %2)
%36 = icmp eq i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %1
%38 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %42
39: ; preds = %1
%40 = load i32, i32* @TCIOFLUSH
%41 = call i32 @tcflush(i32 %0, i32 %40)
br label %42
42: ; preds = %39, %37
ret void
}