#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_iflag;
  int c_lflag;
  int c_cflag;
  scalar_t__ *c_cc;
  int /*<<< orphan*/ c_oflag;
};

/* Variables and functions */
int BRKINT;
int CBAUD;
int CS8;
int ECHO;
int ECHOE;
int ECHOK;
int ECHONL;
int ICANON;
int IGNBRK;
int IGNCR;
int IGNPAR;
int INPCK;
int ISIG;
int IUCLC;
int IXOFF;
int IXON;
int NOFLSH;
int /*<<< orphan*/ ONOCR;
int PARMRK;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VSUSP;
size_t VTIME;
int /*<<< orphan*/ printf(char *, int);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int init_serial_fd(int fd, struct termios *t, int baud_to_use) {
  int i;
  i = tcgetattr(fd, t);
  printf("serial tcgetattr returns %d\n", i);
  t->c_iflag &= ~(BRKINT | PARMRK | INPCK | IUCLC | IXON | IXOFF);
  t->c_iflag |= (IGNBRK | IGNPAR | IGNCR);
  t->c_oflag &= ~(ONOCR);
  t->c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | NOFLSH);
  t->c_lflag |= (ISIG);
  t->c_cc[VMIN] = 0;
  t->c_cc[VTIME] = 0;
  t->c_cc[VSUSP] = 0;
  t->c_cflag &= ~(CBAUD);
  t->c_cflag |= (CS8 | baud_to_use);
  i = tcsetattr(fd, TCSANOW, t);
  printf("result of new serial settings = %d\n", i);
  return (i);
}


x86 assembly (clang, -O0):
<init_serial_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%ecx
mov    0x2e80(%rip),%rax
or     (%rax),%ecx
mov    0x2dff(%rip),%rax
or     (%rax),%ecx
mov    0x2dc6(%rip),%rax
or     (%rax),%ecx
mov    0x2e3d(%rip),%rax
or     (%rax),%ecx
mov    0x2e4c(%rip),%rax
or     (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    0x2db8(%rip),%rax
mov    (%rax),%ecx
mov    0x2d9f(%rip),%rax
or     (%rax),%ecx
mov    0x2e16(%rip),%rax
or     (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    0x2e0d(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    0x18(%rax),%ecx
mov    %ecx,0x18(%rax)
mov    0x2d5f(%rip),%rax
mov    (%rax),%ecx
mov    0x2dce(%rip),%rax
or     (%rax),%ecx
mov    0x2dbd(%rip),%rax
or     (%rax),%ecx
mov    0x2d74(%rip),%rax
or     (%rax),%ecx
mov    0x2d63(%rip),%rax
or     (%rax),%ecx
mov    0x2d7a(%rip),%rax
or     (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    0x2d84(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2d51(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2cff(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2cbd(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2ca3(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    0x2cfd(%rip),%rax
mov    (%rax),%ecx
or     -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0x4(%rbp),%edi
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd51(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_serial_fd>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
call   1040 <tcgetattr@plt>
lea    0xeb8(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    0x2e93(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e10(%rip),%rax
or     (%rax),%ecx
mov    0x2dd7(%rip),%rax
or     (%rax),%ecx
mov    0x2e4e(%rip),%rax
or     (%rax),%ecx
mov    0x2e5d(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    (%rbx),%ecx
mov    %ecx,(%rbx)
mov    0x2dce(%rip),%rax
mov    0x2db7(%rip),%rdx
mov    0x2e30(%rip),%rsi
or     (%rax),%ecx
or     (%rdx),%ecx
or     (%rsi),%ecx
mov    %ecx,(%rbx)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rbx)
mov    0x2d83(%rip),%rax
mov    0x2df4(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2de1(%rip),%rax
or     (%rax),%ecx
mov    0x2d98(%rip),%rax
or     (%rax),%ecx
mov    0x2d87(%rip),%rax
or     (%rax),%ecx
mov    0x2d9e(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x4(%rbx),%ecx
mov    0x2db0(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x4(%rbx)
mov    0x10(%rbx),%rax
mov    0x2d88(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d04(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2cea(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rbx),%eax
mov    0x2d4c(%rip),%rcx
or     %r14d,%eax
or     (%rcx),%eax
mov    %eax,0x8(%rbx)
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
mov    %eax,%ebx
lea    0xdad(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@.str = [29 x i8] c"serial tcgetattr returns %d\0A\00"
@BRKINT = global i32 0
@PARMRK = global i32 0
@INPCK = global i32 0
@IUCLC = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@IGNCR = global i32 0
@ONOCR = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@NOFLSH = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@VSUSP = global i64 0
@CBAUD = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
@.str.1 = [36 x i8] c"result of new serial settings = %d\0A\00"
define i32 @init_serial_fd(i32 %0, %struct.termios* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.termios*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.termios* %1, %struct.termios** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load %struct.termios*, %struct.termios** %5
%10 = call i32 @tcgetattr(i32 %8, %struct.termios* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @BRKINT
%14 = load i32, i32* @PARMRK
%15 = or i32 %13, %14
%16 = load i32, i32* @INPCK
%17 = or i32 %15, %16
%18 = load i32, i32* @IUCLC
%19 = or i32 %17, %18
%20 = load i32, i32* @IXON
%21 = or i32 %19, %20
%22 = load i32, i32* @IXOFF
%23 = or i32 %21, %22
%24 = xor i32 %23, -1
%25 = load %struct.termios*, %struct.termios** %5
%26 = getelementptr inbounds %struct.termios, %struct.termios* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = and i32 %27, %24
store i32 %28, i32* %26
%29 = load i32, i32* @IGNBRK
%30 = load i32, i32* @IGNPAR
%31 = or i32 %29, %30
%32 = load i32, i32* @IGNCR
%33 = or i32 %31, %32
%34 = load %struct.termios*, %struct.termios** %5
%35 = getelementptr inbounds %struct.termios, %struct.termios* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = or i32 %36, %33
store i32 %37, i32* %35
%38 = load i32, i32* @ONOCR
%39 = xor i32 %38, -1
%40 = load %struct.termios*, %struct.termios** %5
%41 = getelementptr inbounds %struct.termios, %struct.termios* %40, i32 0, i32 4
%42 = load i32, i32* %41
%43 = and i32 %42, %39
store i32 %43, i32* %41
%44 = load i32, i32* @ICANON
%45 = load i32, i32* @ECHO
%46 = or i32 %44, %45
%47 = load i32, i32* @ECHOE
%48 = or i32 %46, %47
%49 = load i32, i32* @ECHOK
%50 = or i32 %48, %49
%51 = load i32, i32* @ECHONL
%52 = or i32 %50, %51
%53 = load i32, i32* @NOFLSH
%54 = or i32 %52, %53
%55 = xor i32 %54, -1
%56 = load %struct.termios*, %struct.termios** %5
%57 = getelementptr inbounds %struct.termios, %struct.termios* %56, i32 0, i32 1
%58 = load i32, i32* %57
%59 = and i32 %58, %55
store i32 %59, i32* %57
%60 = load i32, i32* @ISIG
%61 = load %struct.termios*, %struct.termios** %5
%62 = getelementptr inbounds %struct.termios, %struct.termios* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = or i32 %63, %60
store i32 %64, i32* %62
%65 = load %struct.termios*, %struct.termios** %5
%66 = getelementptr inbounds %struct.termios, %struct.termios* %65, i32 0, i32 3
%67 = load i64*, i64** %66
%68 = load i64, i64* @VMIN
%69 = getelementptr inbounds i64, i64* %67, i64 %68
store i64 0, i64* %69
%70 = load %struct.termios*, %struct.termios** %5
%71 = getelementptr inbounds %struct.termios, %struct.termios* %70, i32 0, i32 3
%72 = load i64*, i64** %71
%73 = load i64, i64* @VTIME
%74 = getelementptr inbounds i64, i64* %72, i64 %73
store i64 0, i64* %74
%75 = load %struct.termios*, %struct.termios** %5
%76 = getelementptr inbounds %struct.termios, %struct.termios* %75, i32 0, i32 3
%77 = load i64*, i64** %76
%78 = load i64, i64* @VSUSP
%79 = getelementptr inbounds i64, i64* %77, i64 %78
store i64 0, i64* %79
%80 = load i32, i32* @CBAUD
%81 = xor i32 %80, -1
%82 = load %struct.termios*, %struct.termios** %5
%83 = getelementptr inbounds %struct.termios, %struct.termios* %82, i32 0, i32 2
%84 = load i32, i32* %83
%85 = and i32 %84, %81
store i32 %85, i32* %83
%86 = load i32, i32* @CS8
%87 = load i32, i32* %6
%88 = or i32 %86, %87
%89 = load %struct.termios*, %struct.termios** %5
%90 = getelementptr inbounds %struct.termios, %struct.termios* %89, i32 0, i32 2
%91 = load i32, i32* %90
%92 = or i32 %91, %88
store i32 %92, i32* %90
%93 = load i32, i32* %4
%94 = load i32, i32* @TCSANOW
%95 = load %struct.termios*, %struct.termios** %5
%96 = call i32 @tcsetattr(i32 %93, i32 %94, %struct.termios* %95)
store i32 %96, i32* %7
%97 = load i32, i32* %7
%98 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %97)
%99 = load i32, i32* %7
ret i32 %99
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@.str = [29 x i8] c"serial tcgetattr returns %d\0A\00"
@BRKINT = global i32 0
@PARMRK = global i32 0
@INPCK = global i32 0
@IUCLC = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@IGNCR = global i32 0
@ONOCR = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@NOFLSH = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@VSUSP = global i64 0
@CBAUD = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
@.str.1 = [36 x i8] c"result of new serial settings = %d\0A\00"
define i32 @init_serial_fd(i32 %0, %struct.termios* %1, i32 %2) {
%4 = tail call i32 @tcgetattr(i32 %0, %struct.termios* %1)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @BRKINT
%7 = load i32, i32* @PARMRK
%8 = or i32 %7, %6
%9 = load i32, i32* @INPCK
%10 = or i32 %8, %9
%11 = load i32, i32* @IUCLC
%12 = or i32 %10, %11
%13 = load i32, i32* @IXON
%14 = or i32 %12, %13
%15 = load i32, i32* @IXOFF
%16 = or i32 %14, %15
%17 = xor i32 %16, -1
%18 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* @IGNBRK
%22 = load i32, i32* @IGNPAR
%23 = load i32, i32* @IGNCR
%24 = or i32 %21, %20
%25 = or i32 %24, %22
%26 = or i32 %25, %23
store i32 %26, i32* %18
%27 = load i32, i32* @ONOCR
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 4
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @ICANON
%33 = load i32, i32* @ECHO
%34 = or i32 %33, %32
%35 = load i32, i32* @ECHOE
%36 = or i32 %34, %35
%37 = load i32, i32* @ECHOK
%38 = or i32 %36, %37
%39 = load i32, i32* @ECHONL
%40 = or i32 %38, %39
%41 = load i32, i32* @NOFLSH
%42 = or i32 %40, %41
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%45 = load i32, i32* %44
%46 = and i32 %45, %43
%47 = load i32, i32* @ISIG
%48 = or i32 %47, %46
store i32 %48, i32* %44
%49 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 3
%50 = load i64*, i64** %49
%51 = load i64, i64* @VMIN
%52 = getelementptr inbounds i64, i64* %50, i64 %51
store i64 0, i64* %52
%53 = load i64, i64* @VTIME
%54 = getelementptr inbounds i64, i64* %50, i64 %53
store i64 0, i64* %54
%55 = load i64, i64* @VSUSP
%56 = getelementptr inbounds i64, i64* %50, i64 %55
store i64 0, i64* %56
%57 = load i32, i32* @CBAUD
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%60 = load i32, i32* %59
%61 = and i32 %60, %58
%62 = load i32, i32* @CS8
%63 = or i32 %61, %2
%64 = or i32 %63, %62
store i32 %64, i32* %59
%65 = load i32, i32* @TCSANOW
%66 = tail call i32 @tcsetattr(i32 %0, i32 %65, %struct.termios* %1)
%67 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %66)
ret i32 %66
}