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

/* Variables and functions */
int /*<<< orphan*/ B38400;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int /*<<< orphan*/ TCSANOW;
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 *);
void set_uart_options(int fd) {
  struct termios options;
  tcgetattr(fd, &options);
  cfsetispeed(&options, B38400);
  cfsetospeed(&options, B38400);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~CRTSCTS;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_oflag &= ~OPOST;
  tcsetattr(fd, TCSANOW, &options);
}


x86 assembly (clang, -O0):
<set_uart_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    0x2e1d(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    0x2da5(%rip),%rcx
or     (%rcx),%eax
mov    0x2d94(%rip),%rcx
or     (%rcx),%eax
mov    0x2d83(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    0x2da0(%rip),%rcx
or     (%rcx),%eax
mov    0x2d37(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_uart_options>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2dfc(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1060 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2de9(%rip),%rax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2e0c(%rip),%rax
mov    0x2e0d(%rip),%rdx
mov    0x2dce(%rip),%rsi
mov    (%rsi),%esi
or     (%rax),%esi
mov    0x2e2b(%rip),%rax
or     (%rax),%esi
not    %esi
and    %ecx,%esi
or     (%rdx),%esi
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %esi,%eax
mov    0x2dbf(%rip),%rcx
mov    0x2df8(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,(%rsp)
mov    0x2de2(%rip),%rax
or     (%rax),%edx
mov    0x2dd1(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2dea(%rip),%rax
mov    0x2df3(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d88(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@B38400 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@TCSANOW = global i32 0
define void @set_uart_options(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 = load i32, i32* @B38400
%7 = call i32 @cfsetispeed(%struct.termios* %3, i32 %6)
%8 = load i32, i32* @B38400
%9 = call i32 @cfsetospeed(%struct.termios* %3, i32 %8)
%10 = load i32, i32* @CLOCAL
%11 = load i32, i32* @CREAD
%12 = or i32 %10, %11
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %14, %12
store i32 %15, i32* %13
%16 = load i32, i32* @CSIZE
%17 = xor i32 %16, -1
%18 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and 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* @PARENB
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @CSTOPB
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @CSIZE
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CS8
%41 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%42 = load i32, i32* %41
%43 = or i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @CRTSCTS
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @ICANON
%50 = load i32, i32* @ECHO
%51 = or i32 %49, %50
%52 = load i32, i32* @ECHOE
%53 = or i32 %51, %52
%54 = load i32, i32* @ISIG
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @IXON
%61 = load i32, i32* @IXOFF
%62 = or i32 %60, %61
%63 = load i32, i32* @IXANY
%64 = or i32 %62, %63
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @OPOST
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* %2
%75 = load i32, i32* @TCSANOW
%76 = call i32 @tcsetattr(i32 %74, i32 %75, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@B38400 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@TCSANOW = global i32 0
define void @set_uart_options(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* @B38400
%6 = call i32 @cfsetispeed(%struct.termios* %2, i32 %5)
%7 = load i32, i32* @B38400
%8 = call i32 @cfsetospeed(%struct.termios* %2, i32 %7)
%9 = load i32, i32* @CLOCAL
%10 = load i32, i32* @CREAD
%11 = or i32 %10, %9
%12 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %11, %13
%15 = load i32, i32* @CSIZE
%16 = load i32, i32* @CS8
%17 = load i32, i32* @PARENB
%18 = load i32, i32* @CSTOPB
%19 = or i32 %18, %15
%20 = or i32 %17, %19
%21 = xor i32 %20, -1
%22 = and i32 %14, %21
%23 = or i32 %16, %22
%24 = load i32, i32* @CRTSCTS
%25 = xor i32 %24, -1
%26 = and i32 %23, %25
store i32 %26, i32* %12
%27 = load i32, i32* @ICANON
%28 = load i32, i32* @ECHO
%29 = or i32 %28, %27
%30 = load i32, i32* @ECHOE
%31 = or i32 %29, %30
%32 = load i32, i32* @ISIG
%33 = or i32 %31, %32
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @IXON
%39 = load i32, i32* @IXOFF
%40 = or i32 %39, %38
%41 = load i32, i32* @IXANY
%42 = or i32 %40, %41
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%45 = load i32, i32* %44
%46 = and i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @OPOST
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @TCSANOW
%53 = call i32 @tcsetattr(i32 %0, i32 %52, %struct.termios* %2)
ret void
}