#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_cc;
};
typedef int /*<<< orphan*/ ios;

/* Variables and functions */
int B19200;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
int /*<<< orphan*/ bailout(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned char);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char **argv) {
  int fd, i, n;
  unsigned char vvv[256], *scout;
  int rs232_fd;
  struct termios ios;
  rs232_fd = open("/dev/ttyUSB1", O_RDONLY);
  if (rs232_fd < 0)
    bailout("socket");
  memset(&ios, 0, sizeof(ios));
  ios.c_cflag = B19200 | CLOCAL | CREAD | CS8;
  ios.c_cc[VMIN] = 1;
  tcsetattr(rs232_fd, TCSANOW, &ios);
  i = 0;
  for (;;) {
    if ((n = read(rs232_fd, vvv, 1)) > 0)
      fprintf(stderr, "%c ", *vvv);
  }
  close(rs232_fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe77(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jge    11ad <main+0x4d>
lea    0xe65(%rip),%rdi
call   1030 <bailout@plt>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    0x2dd0(%rip),%rcx
or     (%rcx),%eax
mov    0x2df7(%rip),%rcx
or     (%rcx),%eax
mov    0x2de6(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x140(%rbp)
mov    -0x138(%rbp),%rax
mov    0x2dc8(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x12c(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
lea    -0x140(%rbp),%rdx
call   1070 <tcsetattr@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x12c(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1263 <main+0x103>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
movzbl -0x120(%rbp),%edx
call   1060 <fprintf@plt>
jmp    1224 <main+0xc4>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1195 <main+0x35>
lea    0xe7d(%rip),%rdi
call   1030 <bailout@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e42(%rip),%rax
mov    0x2deb(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e10(%rip),%rax
or     (%rax),%ecx
mov    0x2dff(%rip),%rax
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2de6(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
lea    0x10(%rsp),%r14
mov    0x2dad(%rip),%r12
lea    0xe0a(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1210 <main+0xb0>
mov    (%r12),%edi
movzbl 0x10(%rsp),%edx
mov    %r15,%rsi
call   1060 <fprintf@plt>
jmp    1210 <main+0xb0>

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@.str = [13 x i8] c"/dev/ttyUSB1\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@B19200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CS8 = global i32 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@stderr = global i32 0
@.str.2 = [4 x i8] c"%c \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @bailout(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = call i32 @memset(%struct.termios* %12, i32 0, i32 16)
%21 = load i32, i32* @B19200
%22 = load i32, i32* @CLOCAL
%23 = or i32 %21, %22
%24 = load i32, i32* @CREAD
%25 = or i32 %23, %24
%26 = load i32, i32* @CS8
%27 = or i32 %25, %26
%28 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%30 = load i32*, i32** %29
%31 = load i64, i64* @VMIN
%32 = getelementptr inbounds i32, i32* %30, i64 %31
store i32 1, i32* %32
%33 = load i32, i32* %11
%34 = load i32, i32* @TCSANOW
%35 = call i32 @tcsetattr(i32 %33, i32 %34, %struct.termios* %12)
store i32 0, i32* %7
br label %36
36: ; preds = %46, %19
%37 = load i32, i32* %11
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 1)
store i32 %39, i32* %8
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%44 = load i8, i8* %43
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %44)
br label %46
46: ; preds = %41, %36
br label %36
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@.str = [13 x i8] c"/dev/ttyUSB1\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@B19200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CS8 = global i32 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@stderr = global i32 0
@.str.2 = [4 x i8] c"%c \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.termios
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.termios* %4 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @bailout(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = call i32 @memset(%struct.termios* %4, i32 0, i32 16)
%14 = load i32, i32* @B19200
%15 = load i32, i32* @CLOCAL
%16 = or i32 %15, %14
%17 = load i32, i32* @CREAD
%18 = or i32 %16, %17
%19 = load i32, i32* @CS8
%20 = or i32 %18, %19
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%23 = load i32*, i32** %22
%24 = load i64, i64* @VMIN
%25 = getelementptr inbounds i32, i32* %23, i64 %24
store i32 1, i32* %25
%26 = load i32, i32* @TCSANOW
%27 = call i32 @tcsetattr(i32 %8, i32 %26, %struct.termios* %4)
br label %28
28: ; preds = %35, %12
%29 = call i32 @read(i32 %8, i8* %5, i32 1)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = load i8, i8* %5
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %33)
br label %35
35: ; preds = %31, %28
br label %28
}