#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ B115200;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCMBIC;
int TIOCM_DTR;
int TIOCM_RTS;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void main() {
  int fd;
  fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
  struct termios options;
  tcgetattr(fd, &options);
  cfsetispeed(&options, B115200);
  cfsetospeed(&options, B115200);
  tcsetattr(fd, TCSANOW, &options);
  int RTS_flag;
  int DTR_flag;
  RTS_flag = TIOCM_RTS;
  DTR_flag = TIOCM_DTR;
  ioctl(fd, TIOCMBIC, &DTR_flag);
  usleep(1000);
  ioctl(fd, TIOCMBIC, &RTS_flag);
  while (1) {
    char buf[256];
    int len;
    len = read(fd, buf, 256);
    if (len != -1) {
      write(STDOUT_FILENO, buf, len);
    }
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
or     (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10a0 <cfsetispeed@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    -0x4(%rbp),%edi
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
je     128f <main+0xff>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1030 <write@plt>
jmp    124d <main+0xbd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    0x2e3e(%rip),%rax
mov    0x2e0f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <tcgetattr@plt>
mov    0x2dd7(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10a0 <cfsetispeed@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1080 <tcsetattr@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2d96(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    (%rbx),%esi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
lea    0x10(%rsp),%rbx
mov    0x2da6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     1250 <main+0xc0>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1250 <main+0xc0>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B115200 = global i32 0
@TCSANOW = global i32 0
@TIOCM_RTS = global i32 0
@TIOCM_DTR = global i32 0
@TIOCMBIC = global i32 0
@STDOUT_FILENO = global i32 0
define void @main() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = call i32 @tcgetattr(i32 %11, %struct.termios* %2)
%13 = load i32, i32* @B115200
%14 = call i32 @cfsetispeed(%struct.termios* %2, i32 %13)
%15 = load i32, i32* @B115200
%16 = call i32 @cfsetospeed(%struct.termios* %2, i32 %15)
%17 = load i32, i32* %1
%18 = load i32, i32* @TCSANOW
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %2)
%20 = load i32, i32* @TIOCM_RTS
store i32 %20, i32* %3
%21 = load i32, i32* @TIOCM_DTR
store i32 %21, i32* %4
%22 = load i32, i32* %1
%23 = load i32, i32* @TIOCMBIC
%24 = call i32 @ioctl(i32 %22, i32 %23, i32* %4)
%25 = call i32 @usleep(i32 1000)
%26 = load i32, i32* %1
%27 = load i32, i32* @TIOCMBIC
%28 = call i32 @ioctl(i32 %26, i32 %27, i32* %3)
br label %29
29: ; preds = %0, %40
%30 = load i32, i32* %1
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 256)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* @STDOUT_FILENO
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* %6
%39 = call i32 @write(i32 %36, i8* %37, i32 %38)
br label %40
40: ; preds = %35, %29
br label %29
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B115200 = global i32 0
@TCSANOW = global i32 0
@TIOCM_RTS = global i32 0
@TIOCM_DTR = global i32 0
@TIOCMBIC = global i32 0
@STDOUT_FILENO = global i32 0
define void @main() {
%1 = alloca %struct.termios
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NOCTTY
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = bitcast %struct.termios* %1 to i8*
%10 = call i32 @tcgetattr(i32 %8, %struct.termios* %1)
%11 = load i32, i32* @B115200
%12 = call i32 @cfsetispeed(%struct.termios* %1, i32 %11)
%13 = load i32, i32* @B115200
%14 = call i32 @cfsetospeed(%struct.termios* %1, i32 %13)
%15 = load i32, i32* @TCSANOW
%16 = call i32 @tcsetattr(i32 %8, i32 %15, %struct.termios* %1)
%17 = bitcast i32* %2 to i8*
%18 = bitcast i32* %3 to i8*
%19 = load i32, i32* @TIOCM_RTS
store i32 %19, i32* %2
%20 = load i32, i32* @TIOCM_DTR
store i32 %20, i32* %3
%21 = load i32, i32* @TIOCMBIC
%22 = call i32 @ioctl(i32 %8, i32 %21, i32* %3)
%23 = call i32 @usleep(i32 1000)
%24 = load i32, i32* @TIOCMBIC
%25 = call i32 @ioctl(i32 %8, i32 %24, i32* %2)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
br label %27
27: ; preds = %33, %0
%28 = call i32 @read(i32 %8, i8* %26, i32 256)
%29 = icmp eq i32 %28, -1
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* @STDOUT_FILENO
%32 = call i32 @write(i32 %31, i8* %26, i32 %28)
br label %33
33: ; preds = %30, %27
br label %27
}