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

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CREAD;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int configure_port(int fd) {
  struct termios port_settings;
  memset(&port_settings, 0, sizeof(struct termios));
  cfsetispeed(&port_settings, B115200);
  cfsetospeed(&port_settings, B115200);
  port_settings.c_cflag |= CREAD;
  port_settings.c_cflag |= CSTOPB;
  port_settings.c_cflag |= CLOCAL;
  port_settings.c_cflag |= CS8;
  return tcsetattr(fd, TCSANOW, &port_settings);
}


x86 assembly (clang, -O0):
<configure_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configure_port>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e62(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1060 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e5d(%rip),%rax
mov    0x8(%rsp),%ecx
or     (%rax),%ecx
mov    0x2e28(%rip),%rax
or     (%rax),%ecx
mov    0x2e17(%rip),%rax
or     (%rax),%ecx
mov    0x2e36(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@B115200 = global i32 0
@CREAD = global i32 0
@CSTOPB = global i32 0
@CLOCAL = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
define i32 @configure_port(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = call i32 @memset(%struct.termios* %3, i32 0, i32 4)
%5 = load i32, i32* @B115200
%6 = call i32 @cfsetispeed(%struct.termios* %3, i32 %5)
%7 = load i32, i32* @B115200
%8 = call i32 @cfsetospeed(%struct.termios* %3, i32 %7)
%9 = load i32, i32* @CREAD
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = or i32 %11, %9
store i32 %12, i32* %10
%13 = load i32, i32* @CSTOPB
%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* @CLOCAL
%18 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%19 = load i32, i32* %18
%20 = or i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* @CS8
%22 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%23 = load i32, i32* %22
%24 = or i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* %2
%26 = load i32, i32* @TCSANOW
%27 = call i32 @tcsetattr(i32 %25, i32 %26, %struct.termios* %3)
ret i32 %27
}

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