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

/* Variables and functions */
int B2400;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCMGET;
int /*<<< orphan*/ TIOCMSET;
int TIOCM_DTR;
int TIOCM_RTS;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char **argv) {
  int fd, c, res;
  struct termios oldtio, newtio;
  char buf[255];
  if (argc < 2) {
    printf(
        "Program that reads data form UT70B over RS232\nUsage: %s [device]\n",
        argv[0]);
    return 1;
  }
  fd = open(argv[1], O_RDWR | O_NOCTTY);
  if (fd < 0) {
    perror(argv[1]);
    return 1;
  }
  tcgetattr(fd, &oldtio);
  memset(&newtio, 0, sizeof(newtio));
  newtio.c_cflag = B2400 | CRTSCTS | CS8 | CLOCAL | CREAD;
  newtio.c_iflag = IGNPAR;
  newtio.c_oflag = 0;
  newtio.c_lflag = 0;
  newtio.c_cc[VTIME] = 0;
  newtio.c_cc[VMIN] = 5;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &newtio);
  int status;
  ioctl(fd, TIOCMGET, &status);
  status |= TIOCM_DTR;
  status &= ~TIOCM_RTS;
  ioctl(fd, TIOCMSET, &status);
  for (;;) {
    res = read(fd, buf, 100);
    int i = 0;
    for (; i < res; i++)
      putc(buf[i] & 0b01111111, stdout);
    fflush(stdout);
  }
  tcsetattr(fd, TCSANOW, &oldtio);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c6 <main+0x216>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2d86(%rip),%rax
or     (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1237 <main+0x87>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c6 <main+0x216>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   10a0 <tcgetattr@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
mov    0x2cfd(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4c(%rip),%rcx
or     (%rcx),%eax
mov    0x2ce3(%rip),%rcx
or     (%rcx),%eax
mov    0x2d42(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x70(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x68(%rbp),%rax
mov    0x2cce(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x68(%rbp),%rax
mov    0x2cf1(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2cc5(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x14(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
lea    -0x70(%rbp),%rdx
call   10b0 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
lea    -0x174(%rbp),%rdx
call   1060 <ioctl@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%eax
or     -0x174(%rbp),%eax
mov    %eax,-0x174(%rbp)
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x174(%rbp),%eax
mov    %eax,-0x174(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ca2(%rip),%rax
mov    (%rax),%esi
lea    -0x174(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
lea    -0x170(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x178(%rbp)
mov    -0x178(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13b3 <main+0x203>
movslq -0x178(%rbp),%rax
movsbl -0x170(%rbp,%rax,1),%eax
ff
and    $0x7f,%eax
mov    0x2beb(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1080 <putc@plt>
mov    -0x178(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x178(%rbp)
jmp    136d <main+0x1bd>
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
jmp    134c <main+0x19c>
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x160,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11eb <main+0x3b>
mov    (%rbx),%rsi
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x160,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
mov    0x2df2(%rip),%rax
mov    0x2d93(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10c0 <open@plt>
test   %eax,%eax
js     136c <main+0x1bc>
mov    %eax,%r15d
lea    0x38(%rsp),%rsi
mov    %eax,%edi
call   10a0 <tcgetattr@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2d50(%rip),%rax
mov    0x2d21(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d6e(%rip),%rax
or     (%rax),%ecx
mov    0x2d05(%rip),%rax
or     (%rax),%ecx
mov    0x2d64(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x10(%rsp)
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
mov    0x18(%rsp),%rax
mov    0x2cf5(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d1c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1030 <tcflush@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   10b0 <tcsetattr@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    0x2ce5(%rip),%rax
mov    0xc(%rsp),%ecx
or     (%rax),%ecx
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    %eax,0xc(%rsp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
lea    0x60(%rsp),%r14
mov    0x2c66(%rip),%r12
jmp    1329 <main+0x179>
nopl   0x0(%rax)
mov    (%r12),%edi
call   1090 <fflush@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1320 <main+0x170>
mov    %eax,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x60(%rsp,%rbp,1),%edi
mov    (%r12),%esi
and    $0x7f,%edi
call   1080 <putc@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1350 <main+0x1a0>
jmp    1320 <main+0x170>
mov    0x8(%rbx),%rdi
call   10d0 <perror@plt>
jmp    11d6 <main+0x26>

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [66 x i8] c"Program that reads data form UT70B over RS232\0AUsage: %s [device]\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B2400 = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
@stdout = global i32 0
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 %struct.termios
%10 = alloca %struct.termios
%11 = alloca [255 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %105
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_NOCTTY
%27 = or i32 %25, %26
%28 = call i32 @open(i8* %24, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %21
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @perror(i8* %34)
store i32 1, i32* %3
br label %105
36: ; preds = %21
%37 = load i32, i32* %6
%38 = call i32 @tcgetattr(i32 %37, %struct.termios* %9)
%39 = call i32 @memset(%struct.termios* %10, i32 0, i32 40)
%40 = load i32, i32* @B2400
%41 = load i32, i32* @CRTSCTS
%42 = or i32 %40, %41
%43 = load i32, i32* @CS8
%44 = or i32 %42, %43
%45 = load i32, i32* @CLOCAL
%46 = or i32 %44, %45
%47 = load i32, i32* @CREAD
%48 = or i32 %46, %47
%49 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
store i32 %48, i32* %49
%50 = load i32, i32* @IGNPAR
%51 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 4
store i32 %50, i32* %51
%52 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 3
store i64 0, i64* %52
%53 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 2
store i64 0, i64* %53
%54 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%55 = load i32*, i32** %54
%56 = load i64, i64* @VTIME
%57 = getelementptr inbounds i32, i32* %55, i64 %56
store i32 0, i32* %57
%58 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%59 = load i32*, i32** %58
%60 = load i64, i64* @VMIN
%61 = getelementptr inbounds i32, i32* %59, i64 %60
store i32 5, i32* %61
%62 = load i32, i32* %6
%63 = load i32, i32* @TCIFLUSH
%64 = call i32 @tcflush(i32 %62, i32 %63)
%65 = load i32, i32* %6
%66 = load i32, i32* @TCSANOW
%67 = call i32 @tcsetattr(i32 %65, i32 %66, %struct.termios* %10)
%68 = load i32, i32* %6
%69 = load i32, i32* @TIOCMGET
%70 = call i32 @ioctl(i32 %68, i32 %69, i32* %12)
%71 = load i32, i32* @TIOCM_DTR
%72 = load i32, i32* %12
%73 = or i32 %72, %71
store i32 %73, i32* %12
%74 = load i32, i32* @TIOCM_RTS
%75 = xor i32 %74, -1
%76 = load i32, i32* %12
%77 = and i32 %76, %75
store i32 %77, i32* %12
%78 = load i32, i32* %6
%79 = load i32, i32* @TIOCMSET
%80 = call i32 @ioctl(i32 %78, i32 %79, i32* %12)
br label %81
81: ; preds = %102, %36
%82 = load i32, i32* %6
%83 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%84 = call i32 @read(i32 %82, i8* %83, i32 100)
store i32 %84, i32* %8
store i32 0, i32* %13
br label %85
85: ; preds = %99, %81
%86 = load i32, i32* %13
%87 = load i32, i32* %8
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %102
89: ; preds = %85
%90 = load i32, i32* %13
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %91
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = and i32 %94, 127
%96 = trunc i32 %95 to i8
%97 = load i32, i32* @stdout
%98 = call i32 @putc(i8 signext %96, i32 %97)
br label %99
99: ; preds = %89
%100 = load i32, i32* %13
%101 = add nsw i32 %100, 1
store i32 %101, i32* %13
br label %85
102: ; preds = %85
%103 = load i32, i32* @stdout
%104 = call i32 @fflush(i32 %103)
br label %81
105: ; preds = %31, %16
%106 = load i32, i32* %3
ret i32 %106
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [66 x i8] c"Program that reads data form UT70B over RS232\0AUsage: %s [device]\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B2400 = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = alloca [255 x i8]
%6 = alloca i32
%7 = bitcast %struct.termios* %3 to i8*
%8 = bitcast %struct.termios* %4 to i8*
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%10 = icmp slt i32 %0, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %80
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_NOCTTY
%19 = or i32 %18, %17
%20 = tail call i32 @open(i8* %16, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i8*, i8** %15
%24 = tail call i32 @perror(i8* %23)
br label %80
25: ; preds = %14
%26 = call i32 @tcgetattr(i32 %20, %struct.termios* %3)
%27 = call i32 @memset(%struct.termios* %4, i32 0, i32 40)
%28 = load i32, i32* @B2400
%29 = load i32, i32* @CRTSCTS
%30 = or i32 %29, %28
%31 = load i32, i32* @CS8
%32 = or i32 %30, %31
%33 = load i32, i32* @CLOCAL
%34 = or i32 %32, %33
%35 = load i32, i32* @CREAD
%36 = or i32 %34, %35
%37 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* @IGNPAR
%39 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 4
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%41 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%42 = bitcast i64* %40 to i8*
%43 = load i32*, i32** %41
%44 = load i64, i64* @VTIME
%45 = getelementptr inbounds i32, i32* %43, i64 %44
store i32 0, i32* %45
%46 = load i64, i64* @VMIN
%47 = getelementptr inbounds i32, i32* %43, i64 %46
store i32 5, i32* %47
%48 = load i32, i32* @TCIFLUSH
%49 = call i32 @tcflush(i32 %20, i32 %48)
%50 = load i32, i32* @TCSANOW
%51 = call i32 @tcsetattr(i32 %20, i32 %50, %struct.termios* %4)
%52 = bitcast i32* %6 to i8*
%53 = load i32, i32* @TIOCMGET
%54 = call i32 @ioctl(i32 %20, i32 %53, i32* %6)
%55 = load i32, i32* @TIOCM_DTR
%56 = load i32, i32* %6
%57 = or i32 %56, %55
%58 = load i32, i32* @TIOCM_RTS
%59 = xor i32 %58, -1
%60 = and i32 %57, %59
store i32 %60, i32* %6
%61 = load i32, i32* @TIOCMSET
%62 = call i32 @ioctl(i32 %20, i32 %61, i32* %6)
br label %63
63: ; preds = %77, %25
%64 = call i32 @read(i32 %20, i8* %9, i32 100)
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %77
66: ; preds = %63
%67 = zext i32 %64 to i64
br label %68
68: ; preds = %66, %68
%69 = phi i64 [ 0, %66 ], [ %75, %68 ]
%70 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = and i8 %71, 127
%73 = load i32, i32* @stdout
%74 = call i32 @putc(i8 signext %72, i32 %73)
%75 = add nuw nsw i64 %69, 1
%76 = icmp eq i64 %75, %67
br i1 %76, label %77, label %68
77: ; preds = %68, %63
%78 = load i32, i32* @stdout
%79 = call i32 @fflush(i32 %78)
br label %63
80: ; preds = %22, %11
ret i32 1
}