#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*/ B9600;
int CLOCAL;
int CREAD;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void setup_port(int fd) {
  struct termios options;
  fcntl(fd, F_SETFL, 0);
  tcgetattr(fd, &options);
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);
  options.c_cflag |= (CLOCAL | CREAD);
  tcsetattr(fd, TCSANOW, &options);
}


x86 assembly (clang, -O0):
<setup_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    0x2e2a(%rip),%rcx
or     (%rcx),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1060 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_port>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e5f(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1070 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2e1a(%rip),%rax
mov    0x2e33(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,0x8(%rsp)
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@F_SETFL = global i32 0
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@TCSANOW = global i32 0
define void @setup_port(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @F_SETFL
%6 = call i32 @fcntl(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* %2
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %3)
%9 = load i32, i32* @B9600
%10 = call i32 @cfsetispeed(%struct.termios* %3, i32 %9)
%11 = load i32, i32* @B9600
%12 = call i32 @cfsetospeed(%struct.termios* %3, i32 %11)
%13 = load i32, i32* @CLOCAL
%14 = load i32, i32* @CREAD
%15 = or i32 %13, %14
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = or i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* %2
%20 = load i32, i32* @TCSANOW
%21 = call i32 @tcsetattr(i32 %19, i32 %20, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@F_SETFL = global i32 0
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@TCSANOW = global i32 0
define void @setup_port(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = load i32, i32* @F_SETFL
%5 = tail call i32 @fcntl(i32 %0, i32 %4, i32 0)
%6 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%7 = load i32, i32* @B9600
%8 = call i32 @cfsetispeed(%struct.termios* %2, i32 %7)
%9 = load i32, i32* @B9600
%10 = call i32 @cfsetospeed(%struct.termios* %2, i32 %9)
%11 = load i32, i32* @CLOCAL
%12 = load i32, i32* @CREAD
%13 = or i32 %12, %11
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %13, %15
store i32 %16, i32* %14
%17 = load i32, i32* @TCSANOW
%18 = call i32 @tcsetattr(i32 %0, i32 %17, %struct.termios* %2)
ret void
}