#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 /*<<< orphan*/ c_cflag;
};

/* Variables and functions */
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ CBAUD;
scalar_t__ O_NONBLOCK;
scalar_t__ O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCMBIC;
int /*<<< orphan*/ TIOCMBIS;
int TIOCM_DTR;
int TIOCM_RTS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void main(int argc, char **argv) {
  unsigned long i = 0;
  int fd;
  if (argv[1] != 0) {
    fd = open(argv[1], O_RDWR || O_NONBLOCK);
  } else {
    fd = open("/dev/ttyUSB0", O_RDWR || O_NONBLOCK);
  }
  printf("opened: %d\n", fd);
  struct termios ComParams;
  tcgetattr(fd, &ComParams);
  ComParams.c_cflag &= ~CBAUD;
  ComParams.c_cflag |= B57600;
  tcsetattr(fd, TCSANOW, &ComParams);
  int iFlags;
  iFlags = TIOCM_RTS;
  ioctl(fd, TIOCMBIS, &iFlags);
  iFlags = TIOCM_RTS;
  ioctl(fd, TIOCMBIC, &iFlags);
  iFlags = TIOCM_DTR;
  ioctl(fd, TIOCMBIS, &iFlags);
  sleep(1);
  iFlags = TIOCM_DTR;
  ioctl(fd, TIOCMBIC, &iFlags);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11e2 <main+0x72>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    $0x1,%al
mov    0x2e3d(%rip),%rcx
cmpq   $0x0,(%rcx)
mov    %al,-0x25(%rbp)
jne    11c9 <main+0x59>
mov    0x2e21(%rip),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
jmp    1220 <main+0xb0>
mov    $0x1,%al
mov    0x2dfd(%rip),%rcx
cmpq   $0x0,(%rcx)
mov    %al,-0x31(%rbp)
jne    1209 <main+0x99>
mov    0x2de1(%rip),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%esi
lea    0xde8(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1040 <ioctl@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1040 <ioctl@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2ce7(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1040 <ioctl@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2cb4(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
xor    %esi,%esi
or     (%rcx),%rax
setne  %sil
test   %rdi,%rdi
jne    11a7 <main+0x37>
lea    0xe59(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0xe58(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2ddf(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
mov    0x2dcf(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    0x2da1(%rip),%r12
mov    (%r12),%esi
lea    0x4(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    0x2d78(%rip),%r15
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
mov    0x2d84(%rip),%r13
mov    0x0(%r13),%eax
mov    %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    0x0(%r13),%eax
mov    %eax,0x4(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@O_RDWR = global i64 0
@O_NONBLOCK = global i64 0
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@.str.1 = [12 x i8] c"opened: %d\0A\00"
@CBAUD = global i32 0
@B57600 = global i32 0
@TCSANOW = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMBIS = global i32 0
@TIOCMBIC = global i32 0
@TIOCM_DTR = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.termios
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i64 0, i64* %5
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %26
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i64, i64* @O_RDWR
%18 = icmp ne i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = load i64, i64* @O_NONBLOCK
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %19, %13
%23 = phi i1 [ true, %13 ], [ %21, %19 ]
%24 = zext i1 %23 to i32
%25 = call i32 @open(i8* %16, i32 %24)
store i32 %25, i32* %6
br label %36
26: ; preds = %2
%27 = load i64, i64* @O_RDWR
%28 = icmp ne i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i64, i64* @O_NONBLOCK
%31 = icmp ne i64 %30, 0
br label %32
32: ; preds = %29, %26
%33 = phi i1 [ true, %26 ], [ %31, %29 ]
%34 = zext i1 %33 to i32
%35 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %34)
store i32 %35, i32* %6
br label %36
36: ; preds = %32, %22
%37 = load i32, i32* %6
%38 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %6
%40 = call i32 @tcgetattr(i32 %39, %struct.termios* %7)
%41 = load i32, i32* @CBAUD
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* @B57600
%47 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%48 = load i32, i32* %47
%49 = or i32 %48, %46
store i32 %49, i32* %47
%50 = load i32, i32* %6
%51 = load i32, i32* @TCSANOW
%52 = call i32 @tcsetattr(i32 %50, i32 %51, %struct.termios* %7)
%53 = load i32, i32* @TIOCM_RTS
store i32 %53, i32* %8
%54 = load i32, i32* %6
%55 = load i32, i32* @TIOCMBIS
%56 = call i32 @ioctl(i32 %54, i32 %55, i32* %8)
%57 = load i32, i32* @TIOCM_RTS
store i32 %57, i32* %8
%58 = load i32, i32* %6
%59 = load i32, i32* @TIOCMBIC
%60 = call i32 @ioctl(i32 %58, i32 %59, i32* %8)
%61 = load i32, i32* @TIOCM_DTR
store i32 %61, i32* %8
%62 = load i32, i32* %6
%63 = load i32, i32* @TIOCMBIS
%64 = call i32 @ioctl(i32 %62, i32 %63, i32* %8)
%65 = call i32 @sleep(i32 1)
%66 = load i32, i32* @TIOCM_DTR
store i32 %66, i32* %8
%67 = load i32, i32* %6
%68 = load i32, i32* @TIOCMBIC
%69 = call i32 @ioctl(i32 %67, i32 %68, i32* %8)
%70 = load i32, i32* %6
%71 = call i32 @close(i32 %70)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@O_RDWR = global i64 0
@O_NONBLOCK = global i64 0
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@.str.1 = [12 x i8] c"opened: %d\0A\00"
@CBAUD = global i32 0
@B57600 = global i32 0
@TCSANOW = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMBIS = global i32 0
@TIOCMBIC = global i32 0
@TIOCM_DTR = global i32 0
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca i32
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
%8 = load i64, i64* @O_RDWR
%9 = icmp ne i64 %8, 0
%10 = load i64, i64* @O_NONBLOCK
%11 = icmp ne i64 %10, 0
%12 = select i1 %9, i1 true, i1 %11
%13 = zext i1 %12 to i32
br i1 %7, label %16, label %14
14: ; preds = %2
%15 = tail call i32 @open(i8* %6, i32 %13)
br label %18
16: ; preds = %2
%17 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ %15, %14 ], [ %17, %16 ]
%20 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = bitcast %struct.termios* %3 to i8*
%22 = call i32 @tcgetattr(i32 %19, %struct.termios* %3)
%23 = load i32, i32* @CBAUD
%24 = xor i32 %23, -1
%25 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%26 = load i32, i32* %25
%27 = and i32 %26, %24
%28 = load i32, i32* @B57600
%29 = or i32 %28, %27
store i32 %29, i32* %25
%30 = load i32, i32* @TCSANOW
%31 = call i32 @tcsetattr(i32 %19, i32 %30, %struct.termios* %3)
%32 = bitcast i32* %4 to i8*
%33 = load i32, i32* @TIOCM_RTS
store i32 %33, i32* %4
%34 = load i32, i32* @TIOCMBIS
%35 = call i32 @ioctl(i32 %19, i32 %34, i32* %4)
%36 = load i32, i32* @TIOCM_RTS
store i32 %36, i32* %4
%37 = load i32, i32* @TIOCMBIC
%38 = call i32 @ioctl(i32 %19, i32 %37, i32* %4)
%39 = load i32, i32* @TIOCM_DTR
store i32 %39, i32* %4
%40 = load i32, i32* @TIOCMBIS
%41 = call i32 @ioctl(i32 %19, i32 %40, i32* %4)
%42 = call i32 @sleep(i32 1)
%43 = load i32, i32* @TIOCM_DTR
store i32 %43, i32* %4
%44 = load i32, i32* @TIOCMBIC
%45 = call i32 @ioctl(i32 %19, i32 %44, i32* %4)
%46 = call i32 @close(i32 %19)
ret void
}