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

/* Variables and functions */
int ECHO;
int ECHONL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int ICANON;
int IEXTEN;
int ISIG;
int OCRNL;
int ONLCR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int maestroGetPosition(int, int /*<<< orphan*/);
int /*<<< orphan*/ maestroSetTarget(int, int /*<<< orphan*/, int);
int open(char const *, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  int target = 0;
  int opt;
  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_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  options.c_oflag &= ~(ONLCR | OCRNL);
  tcsetattr(fd, TCSANOW, &options);
  while ((opt = getopt(argc, argv, "t:")) != -1) {
    switch (opt) {
    case 't':
      target = atoi(optarg);
      break;
    default:
      fprintf(stderr, "Usage: [-t target]\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  if (target < 3968 || target > 8000) {
    fprintf(stderr, "maestro_set: out of range (3969..8000),  target: %i\n",
            target);
    fprintf(stderr, "             did you use the -t <n> option\n");
  } else {
    int position = maestroGetPosition(fd, 0);
    maestroSetTarget(fd, 0, target);
  }
  close(fd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe2c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    0x2dbc(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1214 <main+0x64>
mov    -0x20(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret
mov    -0x24(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    0x2d68(%rip),%rcx
or     (%rcx),%eax
mov    0x2d3f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d7e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6d(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    0x2d82(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd79(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     12fd <main+0x14d>
mov    -0x18(%rbp),%eax
sub    $0x74,%eax
jne    12cc <main+0x11c>
jmp    12b6 <main+0x106>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    12f8 <main+0x148>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    1286 <main+0xd6>
cmpl   $0xf80,-0x14(%rbp)
jl     1317 <main+0x167>
cmpl   $0x1f40,-0x14(%rbp)
jle    134d <main+0x19d>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xcfa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
lea    0xd18(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1367 <main+0x1b7>
mov    -0x24(%rbp),%edi
xor    %esi,%esi
call   10d0 <maestroGetPosition@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1050 <maestroSetTarget@plt>
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e11(%rip),%rax
mov    0x2dda(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe27(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    1203 <main+0x53>
lea    0xe16(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r14d
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <tcgetattr@plt>
mov    0x2dae(%rip),%rax
mov    0x2d77(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d4c(%rip),%rax
or     (%rax),%ecx
mov    0x2d8b(%rip),%rax
or     (%rax),%ecx
mov    0x2d7a(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2d34(%rip),%rax
mov    0x2d95(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1070 <tcsetattr@plt>
xor    %ebx,%ebx
lea    0xd93(%rip),%r12
mov    0x2d77(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10a0 <getopt@plt>
cmp    $0x74,%eax
jne    12af <main+0xff>
mov    0x0(%r13),%edi
call   10b0 <atoi@plt>
mov    %eax,%ebx
jmp    1290 <main+0xe0>
cmp    $0xffffffff,%eax
jne    12ee <main+0x13e>
lea    -0x1f41(%rbx),%eax
cmp    $0xfffff03e,%eax
ja     1316 <main+0x166>
mov    0x2cd8(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd52(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd74(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    132c <main+0x17c>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd0f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    %r14d,%edi
xor    %esi,%esi
call   10d0 <maestroGetPosition@plt>
mov    %r14d,%edi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <maestroSetTarget@plt>
mov    %r14d,%edi
call   1030 <close@plt>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@ONLCR = global i32 0
@OCRNL = global i32 0
@TCSANOW = global i32 0
@.str.1 = [3 x i8] c"t:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.2 = [20 x i8] c"Usage: [-t target]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [53 x i8] c"maestro_set: out of range (3969..8000), target: %i\0A\00"
@.str.4 = [44 x i8] c" did you use the -t <n> option\0A\00"
@EXIT_SUCCESS = 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 i8*
%9 = alloca i32
%10 = alloca %struct.termios
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %8
%12 = load i8*, i8** %8
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_NOCTTY
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %12, i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i8*, i8** %8
%21 = call i32 @perror(i8* %20)
ret i32 1
22: ; preds = %2
%23 = load i32, i32* %9
%24 = call i32 @tcgetattr(i32 %23, %struct.termios* %10)
%25 = load i32, i32* @ECHO
%26 = load i32, i32* @ECHONL
%27 = or i32 %25, %26
%28 = load i32, i32* @ICANON
%29 = or i32 %27, %28
%30 = load i32, i32* @ISIG
%31 = or i32 %29, %30
%32 = load i32, i32* @IEXTEN
%33 = or i32 %31, %32
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @ONLCR
%39 = load i32, i32* @OCRNL
%40 = or i32 %38, %39
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* %9
%46 = load i32, i32* @TCSANOW
%47 = call i32 @tcsetattr(i32 %45, i32 %46, %struct.termios* %10)
br label %48
48: ; preds = %66, %22
%49 = load i32, i32* %4
%50 = load i8**, i8*** %5
%51 = call i32 @getopt(i32 %49, i8** %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %51, i32* %7
%52 = icmp ne i32 %51, -1
br i1 %52, label %53, label %67
53: ; preds = %48
%54 = load i32, i32* %7
switch i32 %54, label %58 [
i32 116, label %55
]
55: ; preds = %53
%56 = load i32, i32* @optarg
%57 = call i32 @atoi(i32 %56)
store i32 %57, i32* %6
br label %66
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %62)
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %55
br label %48
67: ; preds = %48
%68 = load i32, i32* %6
%69 = icmp slt i32 %68, 3968
br i1 %69, label %73, label %70
70: ; preds = %67
%71 = load i32, i32* %6
%72 = icmp sgt i32 %71, 8000
br i1 %72, label %73, label %79
73: ; preds = %70, %67
%74 = load i32, i32* @stderr
%75 = load i32, i32* %6
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %75)
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %85
79: ; preds = %70
%80 = load i32, i32* %9
%81 = call i32 @maestroGetPosition(i32 %80, i32 0)
store i32 %81, i32* %11
%82 = load i32, i32* %9
%83 = load i32, i32* %6
%84 = call i32 @maestroSetTarget(i32 %82, i32 0, i32 %83)
br label %85
85: ; preds = %79, %73
%86 = load i32, i32* %9
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* @EXIT_SUCCESS
%89 = call i32 @exit(i32 %88)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@ONLCR = global i32 0
@OCRNL = global i32 0
@TCSANOW = global i32 0
@.str.1 = [3 x i8] c"t:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.2 = [20 x i8] c"Usage: [-t target]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [53 x i8] c"maestro_set: out of range (3969..8000), target: %i\0A\00"
@.str.4 = [44 x i8] c" did you use the -t <n> option\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.termios
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NOCTTY
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
ret i32 1
11: ; preds = %2
%12 = bitcast %struct.termios* %3 to i8*
%13 = call i32 @tcgetattr(i32 %7, %struct.termios* %3)
%14 = load i32, i32* @ECHO
%15 = load i32, i32* @ECHONL
%16 = or i32 %15, %14
%17 = load i32, i32* @ICANON
%18 = or i32 %16, %17
%19 = load i32, i32* @ISIG
%20 = or i32 %18, %19
%21 = load i32, i32* @IEXTEN
%22 = or i32 %20, %21
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @ONLCR
%28 = load i32, i32* @OCRNL
%29 = or i32 %28, %27
%30 = xor i32 %29, -1
%31 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%32 = load i32, i32* %31
%33 = and i32 %32, %30
store i32 %33, i32* %31
%34 = load i32, i32* @TCSANOW
%35 = call i32 @tcsetattr(i32 %7, i32 %34, %struct.termios* %3)
br label %36
36: ; preds = %39, %11
%37 = phi i32 [ 0, %11 ], [ %41, %39 ]
%38 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %38, label %42 [
i32 -1, label %48
i32 116, label %39
]
39: ; preds = %36
%40 = load i32, i32* @optarg
%41 = call i32 @atoi(i32 %40)
br label %36
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %1
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %36
%49 = add i32 %37, -8001
%50 = icmp ult i32 %49, -4033
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %59
56: ; preds = %48
%57 = call i32 @maestroGetPosition(i32 %7, i32 0)
%58 = call i32 @maestroSetTarget(i32 %7, i32 0, i32 %37)
br label %59
59: ; preds = %56, %51
%60 = call i32 @close(i32 %7)
%61 = load i32, i32* @EXIT_SUCCESS
%62 = call i32 @exit(i32 %61)
unreachable
}