#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*/ CRTSCTS;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCSANOW;
int cfsetispeed(struct termios *, int /*<<< orphan*/);
int cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sendDemo(int, int /*<<< orphan*/);
int /*<<< orphan*/ sendFull(int);
int /*<<< orphan*/ sendStart(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stdout, "Usage: %s [port]\n", argv[0]);
    return 1;
  }
  int fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("open()");
    exit(0);
  }
  struct termios options;
  tcgetattr(fd, &options);
  if (cfsetispeed(&options, B57600) == -1) {
    perror("cfsetispeed()");
    exit(0);
  }
  if (cfsetospeed(&options, B57600) == -1) {
    perror("cfsetispeed()");
    exit(0);
  }
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag &= ~CRTSCTS;
  options.c_cflag |= CS8;
  if (tcsetattr(fd, TCSANOW, &options) == -1) {
    perror("tcsetattr()");
    exit(0);
  }
  sendStart(fd);
  sendFull(fd);
  sendDemo(fd, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f8 <main+0x48>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe19(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1351 <main+0x1a1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    0x2da0(%rip),%rax
or     (%rax),%esi
mov    0x2d8f(%rip),%rax
or     (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1240 <main+0x90>
lea    0xdde(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1080 <tcgetattr@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   10b0 <cfsetispeed@plt>
cmp    $0xffffffff,%eax
jne    127a <main+0xca>
lea    0xdab(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
cmp    $0xffffffff,%eax
jne    12a8 <main+0xf8>
lea    0xd7d(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cab(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1330 <main+0x180>
lea    0xd03(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <sendStart@plt>
mov    -0x14(%rbp),%edi
call   1040 <sendFull@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1070 <sendDemo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     11df <main+0x2f>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe30(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    12b6 <main+0x106>
mov    0x2e02(%rip),%rcx
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x8(%rsi),%rdi
mov    0x2dac(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     12ca <main+0x11a>
mov    %eax,%ebx
lea    0x8(%rsp),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
call   1080 <tcgetattr@plt>
mov    0x2d9a(%rip),%r14
mov    (%r14),%esi
mov    %rbp,%rdi
call   10b0 <cfsetispeed@plt>
cmp    $0xffffffff,%eax
je     12c1 <main+0x111>
mov    (%r14),%esi
lea    0x8(%rsp),%rdi
call   1030 <cfsetospeed@plt>
cmp    $0xffffffff,%eax
je     12c1 <main+0x111>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    0x2d2c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d63(%rip),%rcx
or     (%rcx),%eax
mov    0x2d22(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2d53(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     12d3 <main+0x123>
mov    %ebx,%edi
call   1050 <sendStart@plt>
mov    %ebx,%edi
call   1040 <sendFull@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <sendDemo@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd51(%rip),%rdi
jmp    12da <main+0x12a>
lea    0xd41(%rip),%rdi
jmp    12da <main+0x12a>
lea    0xd4d(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdout = global i32 0
@.str = [18 x i8] c"Usage: %s [port]\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@B57600 = global i32 0
@.str.2 = [14 x i8] c"cfsetispeed()\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
@.str.3 = [12 x i8] c"tcsetattr()\00"
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 slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %86
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDWR
%21 = load i32, i32* @O_NOCTTY
%22 = or i32 %20, %21
%23 = load i32, i32* @O_NDELAY
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %19, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %16
%32 = load i32, i32* %6
%33 = call i32 @tcgetattr(i32 %32, %struct.termios* %7)
%34 = load i32, i32* @B57600
%35 = call i32 @cfsetispeed(%struct.termios* %7, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %31
%41 = load i32, i32* @B57600
%42 = call i32 @cfsetospeed(%struct.termios* %7, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %40
%48 = load i32, i32* @PARENB
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @CSTOPB
%54 = xor i32 %53, -1
%55 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%56 = load i32, i32* %55
%57 = and i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* @CSIZE
%59 = xor i32 %58, -1
%60 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%61 = load i32, i32* %60
%62 = and i32 %61, %59
store i32 %62, i32* %60
%63 = load i32, i32* @CRTSCTS
%64 = xor i32 %63, -1
%65 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%66 = load i32, i32* %65
%67 = and i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @CS8
%69 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%70 = load i32, i32* %69
%71 = or i32 %70, %68
store i32 %71, i32* %69
%72 = load i32, i32* %6
%73 = load i32, i32* @TCSANOW
%74 = call i32 @tcsetattr(i32 %72, i32 %73, %struct.termios* %7)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %47
%77 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%78 = call i32 @exit(i32 0)
unreachable
79: ; preds = %47
%80 = load i32, i32* %6
%81 = call i32 @sendStart(i32 %80)
%82 = load i32, i32* %6
%83 = call i32 @sendFull(i32 %82)
%84 = load i32, i32* %6
%85 = call i32 @sendDemo(i32 %84, i32 0)
store i32 0, i32* %3
br label %86
86: ; preds = %79, %10
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdout = global i32 0
@.str = [18 x i8] c"Usage: %s [port]\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@B57600 = global i32 0
@.str.2 = [14 x i8] c"cfsetispeed()\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
@.str.3 = [12 x i8] c"tcsetattr()\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stdout
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %62
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_NOCTTY
%14 = or i32 %13, %12
%15 = load i32, i32* @O_NDELAY
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* %11, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %9
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %9
%23 = bitcast %struct.termios* %3 to i8*
%24 = call i32 @tcgetattr(i32 %17, %struct.termios* %3)
%25 = load i32, i32* @B57600
%26 = call i32 @cfsetispeed(%struct.termios* %3, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %22
%32 = load i32, i32* @B57600
%33 = call i32 @cfsetospeed(%struct.termios* %3, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %31
%39 = load i32, i32* @PARENB
%40 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%41 = load i32, i32* %40
%42 = load i32, i32* @CSTOPB
%43 = or i32 %39, %42
%44 = load i32, i32* @CSIZE
%45 = or i32 %43, %44
%46 = load i32, i32* @CRTSCTS
%47 = or i32 %45, %46
%48 = xor i32 %47, -1
%49 = and i32 %41, %48
%50 = load i32, i32* @CS8
%51 = or i32 %50, %49
store i32 %51, i32* %40
%52 = load i32, i32* @TCSANOW
%53 = call i32 @tcsetattr(i32 %17, i32 %52, %struct.termios* %3)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %38
%56 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %38
%59 = call i32 @sendStart(i32 %17)
%60 = call i32 @sendFull(i32 %17)
%61 = call i32 @sendDemo(i32 %17, i32 0)
br label %62
62: ; preds = %58, %5
%63 = phi i32 [ 1, %5 ], [ 0, %58 ]
ret i32 %63
}