#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;
};

/* Variables and functions */
int /*<<< orphan*/ B38400;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
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 *);
long int initport(int fd) {
  struct termios options;
  tcgetattr(fd, &options);
  cfmakeraw(&options);
  cfsetispeed(&options, B38400);
  cfsetospeed(&options, B38400);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~CRTSCTS;
  tcsetattr(fd, TCSANOW, &options);
  tcgetattr(fd, &options);
  return 1;
}


x86 assembly (clang, -O0):
<initport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <tcgetattr@plt>
lea    -0x8(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    0x2e34(%rip),%rcx
or     (%rcx),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initport>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    %r14,%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e22(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1070 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e0f(%rip),%rax
mov    0x2e40(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    0x2df8(%rip),%rdx
or     (%rdx),%eax
mov    0x2e0f(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2e0a(%rip),%rcx
or     (%rcx),%eax
mov    0x2de1(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0x8(%rsp)
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.termios = type { i32 }
@B38400 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
define i64 @initport(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = call i32 @cfmakeraw(%struct.termios* %2)
%6 = load i32, i32* @B38400
%7 = call i32 @cfsetispeed(%struct.termios* %2, i32 %6)
%8 = load i32, i32* @B38400
%9 = call i32 @cfsetospeed(%struct.termios* %2, i32 %8)
%10 = load i32, i32* @CLOCAL
%11 = load i32, i32* @CREAD
%12 = or i32 %11, %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %12, %14
%16 = load i32, i32* @PARENB
%17 = load i32, i32* @CSTOPB
%18 = or i32 %16, %17
%19 = load i32, i32* @CSIZE
%20 = or i32 %18, %19
%21 = xor i32 %20, -1
%22 = and i32 %15, %21
%23 = load i32, i32* @CS8
%24 = or i32 %23, %22
%25 = load i32, i32* @CRTSCTS
%26 = xor i32 %25, -1
%27 = and i32 %24, %26
store i32 %27, i32* %13
%28 = load i32, i32* @TCSANOW
%29 = call i32 @tcsetattr(i32 %0, i32 %28, %struct.termios* %2)
%30 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
ret i64 1
}