#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_cc;
  scalar_t__ c_oflag;
  scalar_t__ c_lflag;
  int /*<<< orphan*/ c_iflag;
  int /*<<< orphan*/ c_cflag;
};
typedef int /*<<< orphan*/ newtio;

/* Variables and functions */
int /*<<< orphan*/ B9600;
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CREAD;
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ IGNPAR;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  int fd;
  struct termios newtio;
  char *device;
  device = "/dev/ttyS1";
  fd = open(device, O_RDWR);
  if (fd < 0) {
    fprintf(stderr, "*** open %s: %s\n", device, strerror(errno));
    exit(-1);
  }
  bzero(&newtio, sizeof(newtio));
  cfsetospeed(&newtio, B9600);
  newtio.c_cflag |= CS8;
  newtio.c_cflag |= CLOCAL;
  newtio.c_cflag |= CREAD;
  newtio.c_cflag &= ~CRTSCTS;
  newtio.c_cflag &= ~PARENB;
  newtio.c_cflag &= ~CSTOPB;
  newtio.c_iflag = IGNPAR;
  newtio.c_lflag = 0;
  newtio.c_oflag = 0;
  newtio.c_cc[VTIME] = 20;
  newtio.c_cc[VMIN] = 0;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &newtio);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11fb <main+0x7b>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xe1f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x38(%rbp),%rdi
mov    $0x20,%esi
call   1080 <bzero@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2ceb(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x14,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
mov    0x2cfe(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2cda(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x14(%rbp),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <tcsetattr@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1274 <main+0xf4>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
call   1080 <bzero@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2df0(%rip),%rax
mov    0x24(%rsp),%ecx
or     (%rax),%ecx
mov    0x2d8b(%rip),%rax
or     (%rax),%ecx
mov    0x2de2(%rip),%rax
or     (%rax),%ecx
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    0x2de8(%rip),%rdx
or     (%rdx),%eax
mov    0x2d6f(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    %eax,0x24(%rsp)
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2d64(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x14,(%rax,%rcx,4)
mov    0x2d7b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d25(%rip),%rax
mov    (%rax),%ebx
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd79(%rip),%rsi
lea    0xd67(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i64, i64, i32, i32 }
@.str = [11 x i8] c"/dev/ttyS1\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"*** open %s: %s\0A\00"
@errno = global i32 0
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CRTSCTS = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %7
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = call i32 @bzero(%struct.termios* %6, i32 32)
%22 = load i32, i32* @B9600
%23 = call i32 @cfsetospeed(%struct.termios* %6, i32 %22)
%24 = load i32, i32* @CS8
%25 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%26 = load i32, i32* %25
%27 = or i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* @CLOCAL
%29 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @CREAD
%33 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%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* %6, i32 0, i32 4
%39 = load i32, i32* %38
%40 = and i32 %39, %37
store i32 %40, i32* %38
%41 = load i32, i32* @PARENB
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* @CSTOPB
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @IGNPAR
%52 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
store i32 %51, i32* %52
%53 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
store i64 0, i64* %53
%54 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
store i64 0, i64* %54
%55 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%56 = load i32*, i32** %55
%57 = load i64, i64* @VTIME
%58 = getelementptr inbounds i32, i32* %56, i64 %57
store i32 20, i32* %58
%59 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%60 = load i32*, i32** %59
%61 = load i64, i64* @VMIN
%62 = getelementptr inbounds i32, i32* %60, i64 %61
store i32 0, i32* %62
%63 = load i32, i32* %5
%64 = load i32, i32* @TCIFLUSH
%65 = call i32 @tcflush(i32 %63, i32 %64)
%66 = load i32, i32* %5
%67 = load i32, i32* @TCSANOW
%68 = call i32 @tcsetattr(i32 %66, i32 %67, %struct.termios* %6)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32*, i64, i64, i32, i32 }
@.str = [11 x i8] c"/dev/ttyS1\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"*** open %s: %s\0A\00"
@errno = global i32 0
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CRTSCTS = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = call i32 @bzero(%struct.termios* %3, i32 32)
%16 = load i32, i32* @B9600
%17 = call i32 @cfsetospeed(%struct.termios* %3, i32 %16)
%18 = load i32, i32* @CS8
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
%20 = load i32, i32* %19
%21 = or i32 %20, %18
%22 = load i32, i32* @CLOCAL
%23 = or i32 %22, %21
%24 = load i32, i32* @CREAD
%25 = or i32 %24, %23
%26 = load i32, i32* @CRTSCTS
%27 = load i32, i32* @PARENB
%28 = or i32 %26, %27
%29 = load i32, i32* @CSTOPB
%30 = or i32 %28, %29
%31 = xor i32 %30, -1
%32 = and i32 %25, %31
store i32 %32, i32* %19
%33 = load i32, i32* @IGNPAR
%34 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%37 = bitcast i64* %35 to i8*
%38 = load i32*, i32** %36
%39 = load i64, i64* @VTIME
%40 = getelementptr inbounds i32, i32* %38, i64 %39
store i32 20, i32* %40
%41 = load i64, i64* @VMIN
%42 = getelementptr inbounds i32, i32* %38, i64 %41
store i32 0, i32* %42
%43 = load i32, i32* @TCIFLUSH
%44 = call i32 @tcflush(i32 %6, i32 %43)
%45 = load i32, i32* @TCSANOW
%46 = call i32 @tcsetattr(i32 %6, i32 %45, %struct.termios* %3)
ret i32 0
}