#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_iflag;
  int c_oflag;
  int c_lflag;
};

/* Variables and functions */
int ECHO;
int ECHONL;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNCR;
int INLCR;
int ISIG;
int IXOFF;
int IXON;
int OCRNL;
int ONLCR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ maestroSetTarget(int, int, int);
int open(char const *, int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main() {
  const char *device = "/dev/ttyACM0";
  int fd = open(device, O_RDWR | O_NOCTTY);
  if (fd == -1) {
    perror(device);
    return 1;
  }
  struct termios options;
  tcgetattr(fd, &options);
  options.c_iflag &= ~(INLCR | IGNCR | ICRNL | IXON | IXOFF);
  options.c_oflag &= ~(ONLCR | OCRNL);
  options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  tcsetattr(fd, TCSANOW, &options);
  maestroSetTarget(fd, 5, 10000);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    0x2dfa(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b7 <main+0x57>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1280 <main+0x120>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    0x2ded(%rip),%rcx
or     (%rcx),%eax
mov    0x2dfc(%rip),%rcx
or     (%rcx),%eax
mov    0x2dd3(%rip),%rcx
or     (%rcx),%eax
mov    0x2dda(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    0x2de7(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    0x2d5c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d43(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d59(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
mov    $0x2710,%edx
call   1040 <maestroSetTarget@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e72(%rip),%rax
mov    0x2e13(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe80(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1252 <main+0xf2>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e2a(%rip),%rax
mov    0x2e13(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e20(%rip),%rax
or     (%rax),%ecx
mov    0x2df7(%rip),%rax
or     (%rax),%ecx
mov    0x2dfe(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d9f(%rip),%rax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    %ecx,0xc(%rsp)
mov    0x2db7(%rip),%rax
mov    0x2d88(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d6d(%rip),%rax
or     (%rax),%ecx
mov    0x2d94(%rip),%rax
or     (%rax),%ecx
mov    0x2d83(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x10(%rsp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %ebx,%edi
mov    $0x5,%esi
mov    $0x2710,%edx
call   1040 <maestroSetTarget@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xda7(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    124a <main+0xea>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32 }
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@ONLCR = global i32 0
@OCRNL = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.termios
store i32 0, i32* %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %6, %7
%9 = call i32 @open(i8* %5, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i8*, i8** %2
%14 = call i32 @perror(i8* %13)
store i32 1, i32* %1
br label %58
15: ; preds = %0
%16 = load i32, i32* %3
%17 = call i32 @tcgetattr(i32 %16, %struct.termios* %4)
%18 = load i32, i32* @INLCR
%19 = load i32, i32* @IGNCR
%20 = or i32 %18, %19
%21 = load i32, i32* @ICRNL
%22 = or i32 %20, %21
%23 = load i32, i32* @IXON
%24 = or i32 %22, %23
%25 = load i32, i32* @IXOFF
%26 = or i32 %24, %25
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @ONLCR
%32 = load i32, i32* @OCRNL
%33 = or i32 %31, %32
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @ECHO
%39 = load i32, i32* @ECHONL
%40 = or i32 %38, %39
%41 = load i32, i32* @ICANON
%42 = or i32 %40, %41
%43 = load i32, i32* @ISIG
%44 = or i32 %42, %43
%45 = load i32, i32* @IEXTEN
%46 = or i32 %44, %45
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* %3
%52 = load i32, i32* @TCSANOW
%53 = call i32 @tcsetattr(i32 %51, i32 %52, %struct.termios* %4)
%54 = load i32, i32* %3
%55 = call i32 @maestroSetTarget(i32 %54, i32 5, i32 10000)
%56 = load i32, i32* %3
%57 = call i32 @close(i32 %56)
store i32 0, i32* %1
br label %58
58: ; preds = %15, %12
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32 }
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@ONLCR = global i32 0
@OCRNL = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca %struct.termios
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %49
9: ; preds = %0
%10 = bitcast %struct.termios* %1 to i8*
%11 = call i32 @tcgetattr(i32 %5, %struct.termios* %1)
%12 = load i32, i32* @INLCR
%13 = load i32, i32* @IGNCR
%14 = or i32 %13, %12
%15 = load i32, i32* @ICRNL
%16 = or i32 %14, %15
%17 = load i32, i32* @IXON
%18 = or i32 %16, %17
%19 = load i32, i32* @IXOFF
%20 = or i32 %18, %19
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @ONLCR
%26 = load i32, i32* @OCRNL
%27 = or i32 %26, %25
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @ECHO
%33 = load i32, i32* @ECHONL
%34 = or i32 %33, %32
%35 = load i32, i32* @ICANON
%36 = or i32 %34, %35
%37 = load i32, i32* @ISIG
%38 = or i32 %36, %37
%39 = load i32, i32* @IEXTEN
%40 = or i32 %38, %39
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* @TCSANOW
%46 = call i32 @tcsetattr(i32 %5, i32 %45, %struct.termios* %1)
%47 = call i32 @maestroSetTarget(i32 %5, i32 5, i32 10000)
%48 = call i32 @close(i32 %5)
br label %49
49: ; preds = %9, %7
%50 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %50
}