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

/* Variables and functions */
int /*<<< orphan*/ B500000;
int BRKINT;
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ CS8;
int ECHO;
int ECHOCTL;
int ECHOE;
int ECHOK;
int ECHOKE;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IMAXBEL;
int ISIG;
int IXON;
int NOFLSH;
int ONLCR;
int OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Serial port wasn't provided!\n");
    return 1;
  }
  int usbdev;
  struct termios options;
  usbdev = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY);
  if (usbdev == -1)
    perror("open_port : Unable to open:");
  tcgetattr(usbdev, &options);
  cfsetispeed(&options, B500000);
  cfsetospeed(&options, B500000);
  options.c_cflag |= CS8;
  options.c_iflag |= IGNBRK;
  options.c_iflag &= ~(BRKINT | ICRNL | IMAXBEL | IXON);
  options.c_oflag &= ~(OPOST | ONLCR);
  options.c_lflag &=
      ~(ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE);
  options.c_lflag |= NOFLSH;
  options.c_cflag &= ~CRTSCTS;
  tcsetattr(usbdev, TCSANOW, &options);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    0x2db0(%rip),%rax
or     (%rax),%esi
mov    0x2d97(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e9 <main+0x79>
lea    0xe3a(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    0x2d99(%rip),%rcx
or     (%rcx),%eax
mov    0x2ce8(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6f(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    0x2cdc(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    0x2cb1(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf0(%rip),%rcx
or     (%rcx),%eax
mov    0x2d17(%rip),%rcx
or     (%rcx),%eax
mov    0x2d06(%rip),%rcx
or     (%rcx),%eax
mov    0x2cb5(%rip),%rcx
or     (%rcx),%eax
mov    0x2d1c(%rip),%rcx
or     (%rcx),%eax
mov    0x2cb3(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c42(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cc5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    12b9 <main+0x149>
mov    0x2e60(%rip),%rcx
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x8(%rsi),%rdi
mov    0x2dc2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     12d3 <main+0x163>
mov    %rsp,%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2d82(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1080 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2db7(%rip),%rcx
mov    (%rsp),%edx
mov    0xc(%rsp),%eax
or     (%rcx),%eax
mov    0x2d67(%rip),%rcx
or     (%rcx),%edx
mov    0x2da6(%rip),%rcx
mov    0x2ddf(%rip),%rsi
mov    (%rsi),%esi
or     (%rcx),%esi
mov    0x2d2c(%rip),%rcx
or     (%rcx),%esi
mov    0x2db3(%rip),%rcx
or     (%rcx),%esi
not    %esi
and    %edx,%esi
mov    %esi,(%rsp)
mov    0x2dab(%rip),%rcx
mov    0x2d24(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2d6b(%rip),%rcx
mov    0x2cfc(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2d39(%rip),%rcx
or     (%rcx),%edx
mov    0x2d60(%rip),%rcx
or     (%rcx),%edx
mov    0x2d4f(%rip),%rcx
or     (%rcx),%edx
mov    0x2cfe(%rip),%rcx
or     (%rcx),%edx
mov    0x2d65(%rip),%rcx
or     (%rcx),%edx
mov    0x2cfc(%rip),%rcx
or     (%rcx),%edx
not    %edx
and    0x8(%rsp),%edx
mov    0x2d05(%rip),%rcx
or     (%rcx),%edx
mov    %edx,0x8(%rsp)
mov    0x2c90(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0xc(%rsp)
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
xor    %eax,%eax
jmp    12ca <main+0x15a>
lea    0xd5c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd26(%rip),%rdi
call   1090 <perror@plt>
jmp    11b2 <main+0x42>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@.str = [30 x i8] c"Serial port wasn't provided!\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [28 x i8] c"open_port : Unable to open:\00"
@B500000 = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@IMAXBEL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ONLCR = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHOCTL = global i32 0
@ECHOKE = global i32 0
@NOFLSH = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %90
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_NOCTTY
%18 = or i32 %16, %17
%19 = load i32, i32* @O_NDELAY
%20 = or i32 %18, %19
%21 = call i32 @open(i8* %15, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %12
%25 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %12
%27 = load i32, i32* %6
%28 = call i32 @tcgetattr(i32 %27, %struct.termios* %7)
%29 = load i32, i32* @B500000
%30 = call i32 @cfsetispeed(%struct.termios* %7, i32 %29)
%31 = load i32, i32* @B500000
%32 = call i32 @cfsetospeed(%struct.termios* %7, i32 %31)
%33 = load i32, i32* @CS8
%34 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%35 = load i32, i32* %34
%36 = or i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* @IGNBRK
%38 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%39 = load i32, i32* %38
%40 = or i32 %39, %37
store i32 %40, i32* %38
%41 = load i32, i32* @BRKINT
%42 = load i32, i32* @ICRNL
%43 = or i32 %41, %42
%44 = load i32, i32* @IMAXBEL
%45 = or i32 %43, %44
%46 = load i32, i32* @IXON
%47 = or i32 %45, %46
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @OPOST
%53 = load i32, i32* @ONLCR
%54 = or i32 %52, %53
%55 = xor i32 %54, -1
%56 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%57 = load i32, i32* %56
%58 = and i32 %57, %55
store i32 %58, i32* %56
%59 = load i32, i32* @ISIG
%60 = load i32, i32* @ICANON
%61 = or i32 %59, %60
%62 = load i32, i32* @IEXTEN
%63 = or i32 %61, %62
%64 = load i32, i32* @ECHO
%65 = or i32 %63, %64
%66 = load i32, i32* @ECHOE
%67 = or i32 %65, %66
%68 = load i32, i32* @ECHOK
%69 = or i32 %67, %68
%70 = load i32, i32* @ECHOCTL
%71 = or i32 %69, %70
%72 = load i32, i32* @ECHOKE
%73 = or i32 %71, %72
%74 = xor i32 %73, -1
%75 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%76 = load i32, i32* %75
%77 = and i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* @NOFLSH
%79 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%80 = load i32, i32* %79
%81 = or i32 %80, %78
store i32 %81, i32* %79
%82 = load i32, i32* @CRTSCTS
%83 = xor i32 %82, -1
%84 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%85 = load i32, i32* %84
%86 = and i32 %85, %83
store i32 %86, i32* %84
%87 = load i32, i32* %6
%88 = load i32, i32* @TCSANOW
%89 = call i32 @tcsetattr(i32 %87, i32 %88, %struct.termios* %7)
store i32 0, i32* %3
br label %90
90: ; preds = %26, %10
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [28 x i8] c"open_port : Unable to open:\00"
@B500000 = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@IMAXBEL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ONLCR = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHOCTL = global i32 0
@ECHOKE = global i32 0
@NOFLSH = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@str = [29 x i8] c"Serial port wasn't provided!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = icmp eq i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %76
7: ; preds = %2
%8 = bitcast %struct.termios* %3 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_NOCTTY
%13 = or i32 %12, %11
%14 = load i32, i32* @O_NDELAY
%15 = or i32 %13, %14
%16 = tail call i32 @open(i8* %10, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %7
%21 = call i32 @tcgetattr(i32 %16, %struct.termios* %3)
%22 = load i32, i32* @B500000
%23 = call i32 @cfsetispeed(%struct.termios* %3, i32 %22)
%24 = load i32, i32* @B500000
%25 = call i32 @cfsetospeed(%struct.termios* %3, i32 %24)
%26 = load i32, i32* @CS8
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%28 = load i32, i32* %27
%29 = or i32 %28, %26
%30 = load i32, i32* @IGNBRK
%31 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%32 = load i32, i32* %31
%33 = or i32 %32, %30
%34 = load i32, i32* @BRKINT
%35 = load i32, i32* @ICRNL
%36 = or i32 %35, %34
%37 = load i32, i32* @IMAXBEL
%38 = or i32 %36, %37
%39 = load i32, i32* @IXON
%40 = or i32 %38, %39
%41 = xor i32 %40, -1
%42 = and i32 %33, %41
store i32 %42, i32* %31
%43 = load i32, i32* @OPOST
%44 = load i32, i32* @ONLCR
%45 = or i32 %44, %43
%46 = xor i32 %45, -1
%47 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%48 = load i32, i32* %47
%49 = and i32 %48, %46
store i32 %49, i32* %47
%50 = load i32, i32* @ISIG
%51 = load i32, i32* @ICANON
%52 = or i32 %51, %50
%53 = load i32, i32* @IEXTEN
%54 = or i32 %52, %53
%55 = load i32, i32* @ECHO
%56 = or i32 %54, %55
%57 = load i32, i32* @ECHOE
%58 = or i32 %56, %57
%59 = load i32, i32* @ECHOK
%60 = or i32 %58, %59
%61 = load i32, i32* @ECHOCTL
%62 = or i32 %60, %61
%63 = load i32, i32* @ECHOKE
%64 = or i32 %62, %63
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%67 = load i32, i32* %66
%68 = and i32 %67, %65
%69 = load i32, i32* @NOFLSH
%70 = or i32 %69, %68
store i32 %70, i32* %66
%71 = load i32, i32* @CRTSCTS
%72 = xor i32 %71, -1
%73 = and i32 %29, %72
store i32 %73, i32* %27
%74 = load i32, i32* @TCSANOW
%75 = call i32 @tcsetattr(i32 %16, i32 %74, %struct.termios* %3)
br label %76
76: ; preds = %20, %5
%77 = phi i32 [ 1, %5 ], [ 0, %20 ]
ret i32 %77
}