#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;
};
typedef int /*<<< orphan*/ speed_t;

/* Variables and functions */
scalar_t__ B115200;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char const *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int write(int, int const *, int);
void serialTelescope(const char *port, const int axis) {
  int usb = open(port, O_RDWR | O_NOCTTY);
  struct termios tty;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(usb, &tty) != 0) {
    printf("Error %d from tcgetattr: %s\n", errno, strerror(errno));
  }
  cfsetospeed(&tty, (speed_t)B115200);
  cfsetispeed(&tty, (speed_t)B115200);
  tty.c_cflag &= ~PARENB;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= CS8;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_cc[VMIN] = 1;
  tty.c_cc[VTIME] = 5;
  tty.c_cflag |= CREAD | CLOCAL;
  cfmakeraw(&tty);
  tcflush(usb, TCIFLUSH);
  if (tcsetattr(usb, TCSANOW, &tty) != 0) {
    printf("Error %d from tcsetattr\n", errno);
  }
  int written = write(usb, &axis, 1);
  if (written != 1) {
    printf("Error not writen correct side");
  }
}


x86 assembly (clang, -O0):
<serialTelescope>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    0x2dcd(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1090 <tcgetattr@plt>
cmp    $0x0,%rax
je     1231 <serialTelescope+0x81>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x28(%rbp),%esi
mov    %rax,%rdx
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
call   10c0 <cfsetispeed@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d03(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2cb6(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    0x2c7c(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <cfmakeraw@plt>
mov    -0x10(%rbp),%edi
mov    0x2ca1(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
mov    -0x10(%rbp),%edi
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
je     1344 <serialTelescope+0x194>
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1370 <serialTelescope+0x1c0>
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialTelescope>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,0xc(%rsp)
mov    0x2e25(%rip),%rax
mov    0x2dd6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <tcgetattr@plt>
test   %rax,%rax
je     121b <serialTelescope+0x6b>
mov    0x2d99(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xdf1(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d6e(%rip),%rbx
mov    (%rbx),%esi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   10c0 <cfsetispeed@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    0x2d25(%rip),%rcx
or     (%rcx),%eax
mov    0x2d64(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x10(%rsp),%eax
mov    0x2d65(%rip),%rcx
or     (%rcx),%eax
mov    0x2d0c(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2cf5(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d2c(%rip),%rax
mov    0x2cbd(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,0x10(%rsp)
mov    %r14,%rdi
call   1080 <cfmakeraw@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <tcflush@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   10a0 <tcsetattr@plt>
test   %rax,%rax
je     12fa <serialTelescope+0x14a>
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
lea    0xd2a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     131e <serialTelescope+0x16e>
lea    0xd1f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [29 x i8] c"Error %d from tcgetattr: %s\0A\00"
@errno = global i32 0
@B115200 = global i64 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [25 x i8] c"Error %d from tcsetattr\0A\00"
@.str.2 = [30 x i8] c"Error not writen correct side\00"
define void @serialTelescope(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_NOCTTY
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %8, i32 %11)
store i32 %12, i32* %5
%13 = call i32 @memset(%struct.termios* %6, i32 0, i32 16)
%14 = load i32, i32* %5
%15 = call i64 @tcgetattr(i32 %14, %struct.termios* %6)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %18, i8* %20)
br label %22
22: ; preds = %17, %2
%23 = load i64, i64* @B115200
%24 = trunc i64 %23 to i32
%25 = call i32 @cfsetospeed(%struct.termios* %6, i32 %24)
%26 = load i64, i64* @B115200
%27 = trunc i64 %26 to i32
%28 = call i32 @cfsetispeed(%struct.termios* %6, i32 %27)
%29 = load i32, i32* @PARENB
%30 = xor i32 %29, -1
%31 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%32 = load i32, i32* %31
%33 = and i32 %32, %30
store i32 %33, i32* %31
%34 = load i32, i32* @CSTOPB
%35 = xor i32 %34, -1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%37 = load i32, i32* %36
%38 = and i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @CSIZE
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @CS8
%45 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%46 = load i32, i32* %45
%47 = or i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @CRTSCTS
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%54 = load i32*, i32** %53
%55 = load i64, i64* @VMIN
%56 = getelementptr inbounds i32, i32* %54, i64 %55
store i32 1, i32* %56
%57 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%58 = load i32*, i32** %57
%59 = load i64, i64* @VTIME
%60 = getelementptr inbounds i32, i32* %58, i64 %59
store i32 5, i32* %60
%61 = load i32, i32* @CREAD
%62 = load i32, i32* @CLOCAL
%63 = or i32 %61, %62
%64 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%65 = load i32, i32* %64
%66 = or i32 %65, %63
store i32 %66, i32* %64
%67 = call i32 @cfmakeraw(%struct.termios* %6)
%68 = load i32, i32* %5
%69 = load i32, i32* @TCIFLUSH
%70 = call i32 @tcflush(i32 %68, i32 %69)
%71 = load i32, i32* %5
%72 = load i32, i32* @TCSANOW
%73 = call i64 @tcsetattr(i32 %71, i32 %72, %struct.termios* %6)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %22
%76 = load i32, i32* @errno
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %75, %22
%79 = load i32, i32* %5
%80 = call i32 @write(i32 %79, i32* %4, i32 1)
store i32 %80, i32* %7
%81 = load i32, i32* %7
%82 = icmp ne i32 %81, 1
br i1 %82, label %83, label %85
83: ; preds = %78
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %85
85: ; preds = %83, %78
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [29 x i8] c"Error %d from tcgetattr: %s\0A\00"
@errno = global i32 0
@B115200 = global i64 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [25 x i8] c"Error %d from tcsetattr\0A\00"
@.str.2 = [30 x i8] c"Error not writen correct side\00"
define void @serialTelescope(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %1, i32* %3
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NOCTTY
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = bitcast %struct.termios* %4 to i8*
%10 = call i32 @memset(%struct.termios* %4, i32 0, i32 16)
%11 = call i64 @tcgetattr(i32 %8, %struct.termios* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %15)
br label %17
17: ; preds = %13, %2
%18 = load i64, i64* @B115200
%19 = trunc i64 %18 to i32
%20 = call i32 @cfsetospeed(%struct.termios* %4, i32 %19)
%21 = load i64, i64* @B115200
%22 = trunc i64 %21 to i32
%23 = call i32 @cfsetispeed(%struct.termios* %4, i32 %22)
%24 = load i32, i32* @PARENB
%25 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @CSTOPB
%28 = or i32 %24, %27
%29 = load i32, i32* @CSIZE
%30 = or i32 %28, %29
%31 = xor i32 %30, -1
%32 = and i32 %26, %31
%33 = load i32, i32* @CS8
%34 = or i32 %33, %32
%35 = load i32, i32* @CRTSCTS
%36 = xor i32 %35, -1
%37 = and i32 %34, %36
store i32 %37, i32* %25
%38 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%39 = load i32*, i32** %38
%40 = load i64, i64* @VMIN
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 1, i32* %41
%42 = load i64, i64* @VTIME
%43 = getelementptr inbounds i32, i32* %39, i64 %42
store i32 5, i32* %43
%44 = load i32, i32* @CREAD
%45 = load i32, i32* @CLOCAL
%46 = or i32 %45, %44
%47 = load i32, i32* %25
%48 = or i32 %46, %47
store i32 %48, i32* %25
%49 = call i32 @cfmakeraw(%struct.termios* %4)
%50 = load i32, i32* @TCIFLUSH
%51 = call i32 @tcflush(i32 %8, i32 %50)
%52 = load i32, i32* @TCSANOW
%53 = call i64 @tcsetattr(i32 %8, i32 %52, %struct.termios* %4)
%54 = icmp eq i64 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %17
%56 = load i32, i32* @errno
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %17
%59 = call i32 @write(i32 %8, i32* %3, i32 1)
%60 = icmp eq i32 %59, 1
br i1 %60, label %63, label %61
61: ; preds = %58
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %61, %58
ret void
}