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

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B230400;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B9600;
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ HUPCL;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TIOCMBIS;
int TIOCM_DTR;
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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ stderr;
int tcflush(int, int /*<<< orphan*/);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int stty_telos(int fd, int baudrate) {
  struct termios tty;
  speed_t speed;
  int i;
  switch (baudrate) {
  case -2:
    break;
  case 9600:
    speed = B9600;
    break;
  case 19200:
    speed = B19200;
    break;
  case 38400:
    speed = B38400;
    break;
  case 57600:
    speed = B57600;
    break;
  case 115200:
    speed = B115200;
    break;
  case 230400:
    speed = B230400;
    break;
  default:
    fprintf(stderr, "unknown baudrate %d", baudrate);
    return -1;
  }
  if (tcflush(fd, TCIOFLUSH) == -1)
    fprintf(stderr, "Error: tcflush()\n");
  if (tcgetattr(fd, &tty) == -1)
    fprintf(stderr, "Error: tcgetattr()\n");
  cfmakeraw(&tty);
  tty.c_cc[VTIME] = 0;
  tty.c_cc[VMIN] = 0;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_cflag &= ~HUPCL;
  tty.c_cflag &= ~CLOCAL;
  cfsetispeed(&tty, speed);
  cfsetospeed(&tty, speed);
  if (tcsetattr(fd, TCSAFLUSH, &tty) == -1)
    fprintf(stderr, "Error: tcsetattr()\n");
  tty.c_cflag |= CLOCAL;
  if (tcsetattr(fd, TCSAFLUSH, &tty) == -1)
    fprintf(stderr, "Error: tcsetattr()\n");
  i = TIOCM_DTR;
  if (ioctl(fd, TIOCMBIS, &i) == -1)
    fprintf(stderr, "Error: ioctl()\n");
  usleep(10 * 1000);
  if (tcflush(fd, TCIOFLUSH) == -1)
    fprintf(stderr, "Error: tcflush()\n");
  return 0;
}


x86 assembly (clang, -O0):
<stty_telos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xfffffffe,%eax
je     1224 <stty_telos+0x94>
jmp    11b2 <stty_telos+0x22>
mov    -0x2c(%rbp),%eax
sub    $0x2580,%eax
je     1229 <stty_telos+0x99>
jmp    11c5 <stty_telos+0x35>
mov    -0x2c(%rbp),%eax
sub    $0x4b00,%eax
je     123a <stty_telos+0xaa>
jmp    11d8 <stty_telos+0x48>
mov    -0x2c(%rbp),%eax
sub    $0x9600,%eax
je     124b <stty_telos+0xbb>
jmp    11eb <stty_telos+0x5b>
mov    -0x2c(%rbp),%eax
sub    $0xe100,%eax
je     125c <stty_telos+0xcc>
jmp    11fe <stty_telos+0x6e>
mov    -0x2c(%rbp),%eax
sub    $0x1c200,%eax
je     126d <stty_telos+0xdd>
jmp    1211 <stty_telos+0x81>
mov    -0x2c(%rbp),%eax
sub    $0x38400,%eax
je     127e <stty_telos+0xee>
jmp    128f <stty_telos+0xff>
jmp    12b5 <stty_telos+0x125>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12b5 <stty_telos+0x125>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12b5 <stty_telos+0x125>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12b5 <stty_telos+0x125>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12b5 <stty_telos+0x125>
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12b5 <stty_telos+0x125>
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12b5 <stty_telos+0x125>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xd5e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1491 <stty_telos+0x301>
mov    -0x8(%rbp),%edi
mov    0x2ce1(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
cmp    $0xffffffff,%eax
jne    12e6 <stty_telos+0x156>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1312 <stty_telos+0x182>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1070 <cfmakeraw@plt>
mov    -0x18(%rbp),%rax
mov    0x2c6a(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    0x2c8c(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c2a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c28(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2bf6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   10a0 <cfsetispeed@plt>
mov    -0x24(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x8(%rbp),%edi
mov    0x2c41(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    13ca <stty_telos+0x23a>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
lea    0xc77(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2bfd(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    140e <stty_telos+0x27e>
mov    0x2baa(%rip),%rax
mov    (%rax),%edi
lea    0xc33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2bc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2b8c(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    144f <stty_telos+0x2bf>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
mov    -0x8(%rbp),%edi
mov    0x2b3d(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
cmp    $0xffffffff,%eax
jne    148a <stty_telos+0x2fa>
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
lea    0xb91(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stty_telos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%edx
mov    %edi,%r13d
cmp    $0x95ff,%esi
jle    11cc <stty_telos+0x3c>
cmp    $0x1c1ff,%edx
jg     11ea <stty_telos+0x5a>
cmp    $0x9600,%edx
je     1203 <stty_telos+0x73>
cmp    $0xe100,%edx
jne    1217 <stty_telos+0x87>
mov    0x2df6(%rip),%rax
jmp    123f <stty_telos+0xaf>
cmp    $0xfffffffe,%edx
je     120c <stty_telos+0x7c>
cmp    $0x2580,%edx
je     1238 <stty_telos+0xa8>
cmp    $0x4b00,%edx
jne    1217 <stty_telos+0x87>
mov    0x2e08(%rip),%rax
jmp    123f <stty_telos+0xaf>
cmp    $0x1c200,%edx
je     120e <stty_telos+0x7e>
cmp    $0x38400,%edx
jne    1217 <stty_telos+0x87>
mov    0x2d6f(%rip),%rax
jmp    123f <stty_telos+0xaf>
mov    0x2d56(%rip),%rax
jmp    123f <stty_telos+0xaf>
jmp    1242 <stty_telos+0xb2>
mov    0x2d83(%rip),%rax
jmp    123f <stty_telos+0xaf>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    13df <stty_telos+0x24f>
mov    0x2d91(%rip),%rax
mov    (%rax),%r14d
mov    0x2d57(%rip),%r15
mov    (%r15),%esi
mov    %r13d,%edi
call   1040 <tcflush@plt>
cmp    $0xffffffff,%eax
jne    1270 <stty_telos+0xe0>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r13d,%edi
call   1080 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1299 <stty_telos+0x109>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <cfmakeraw@plt>
mov    0x10(%rsp),%rax
mov    0x2cde(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d04(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2ca2(%rip),%rax
mov    (%rax),%eax
mov    0x2ca9(%rip),%rcx
or     (%rcx),%eax
mov    0x2c80(%rip),%r12
or     (%r12),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    %rbp,%rdi
mov    %r14d,%esi
call   10a0 <cfsetispeed@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1030 <cfsetospeed@plt>
mov    0x2cd1(%rip),%rbx
mov    (%rbx),%esi
mov    %r13d,%edi
mov    %rbp,%rdx
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1338 <stty_telos+0x1a8>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
lea    0xd09(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r12),%eax
or     %eax,0x8(%rsp)
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
mov    %r13d,%edi
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    136b <stty_telos+0x1db>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
lea    0xcd6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2c66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2c31(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %r13d,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    13aa <stty_telos+0x21a>
mov    0x2c0e(%rip),%rax
mov    (%rax),%edi
lea    0xcab(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
mov    (%r15),%esi
mov    %r13d,%edi
call   1040 <tcflush@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    13df <stty_telos+0x24f>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
lea    0xc3e(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i64* }
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"unknown baudrate %d\00"
@TCIOFLUSH = global i32 0
@.str.1 = [18 x i8] c"Error: tcflush()\0A\00"
@.str.2 = [20 x i8] c"Error: tcgetattr()\0A\00"
@VTIME = global i64 0
@VMIN = global i64 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@TCSAFLUSH = global i32 0
@.str.3 = [20 x i8] c"Error: tcsetattr()\0A\00"
@TIOCM_DTR = global i32 0
@TIOCMBIS = global i32 0
@.str.4 = [16 x i8] c"Error: ioctl()\0A\00"
define i32 @stty_telos(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
switch i32 %9, label %23 [
i32 -2, label %10
i32 9600, label %11
i32 19200, label %13
i32 38400, label %15
i32 57600, label %17
i32 115200, label %19
i32 230400, label %21
]
10: ; preds = %2
br label %27
11: ; preds = %2
%12 = load i32, i32* @B9600
store i32 %12, i32* %7
br label %27
13: ; preds = %2
%14 = load i32, i32* @B19200
store i32 %14, i32* %7
br label %27
15: ; preds = %2
%16 = load i32, i32* @B38400
store i32 %16, i32* %7
br label %27
17: ; preds = %2
%18 = load i32, i32* @B57600
store i32 %18, i32* %7
br label %27
19: ; preds = %2
%20 = load i32, i32* @B115200
store i32 %20, i32* %7
br label %27
21: ; preds = %2
%22 = load i32, i32* @B230400
store i32 %22, i32* %7
br label %27
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i32, i32* %5
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 -1, i32* %3
br label %109
27: ; preds = %21, %19, %17, %15, %13, %11, %10
%28 = load i32, i32* %4
%29 = load i32, i32* @TCIOFLUSH
%30 = call i32 @tcflush(i32 %28, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %32, %27
%36 = load i32, i32* %4
%37 = call i32 @tcgetattr(i32 %36, %struct.termios* %6)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %39, %35
%43 = call i32 @cfmakeraw(%struct.termios* %6)
%44 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%45 = load i64*, i64** %44
%46 = load i64, i64* @VTIME
%47 = getelementptr inbounds i64, i64* %45, i64 %46
store i64 0, i64* %47
%48 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%49 = load i64*, i64** %48
%50 = load i64, i64* @VMIN
%51 = getelementptr inbounds i64, i64* %49, i64 %50
store i64 0, i64* %51
%52 = load i32, i32* @CRTSCTS
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @HUPCL
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @CLOCAL
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* %7
%68 = call i32 @cfsetispeed(%struct.termios* %6, i32 %67)
%69 = load i32, i32* %7
%70 = call i32 @cfsetospeed(%struct.termios* %6, i32 %69)
%71 = load i32, i32* %4
%72 = load i32, i32* @TCSAFLUSH
%73 = call i32 @tcsetattr(i32 %71, i32 %72, %struct.termios* %6)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %42
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %78
78: ; preds = %75, %42
%79 = load i32, i32* @CLOCAL
%80 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%81 = load i32, i32* %80
%82 = or i32 %81, %79
store i32 %82, i32* %80
%83 = load i32, i32* %4
%84 = load i32, i32* @TCSAFLUSH
%85 = call i32 @tcsetattr(i32 %83, i32 %84, %struct.termios* %6)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %90
87: ; preds = %78
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %90
90: ; preds = %87, %78
%91 = load i32, i32* @TIOCM_DTR
store i32 %91, i32* %8
%92 = load i32, i32* %4
%93 = load i32, i32* @TIOCMBIS
%94 = call i32 @ioctl(i32 %92, i32 %93, i32* %8)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %99
96: ; preds = %90
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %99
99: ; preds = %96, %90
%100 = call i32 @usleep(i32 10000)
%101 = load i32, i32* %4
%102 = load i32, i32* @TCIOFLUSH
%103 = call i32 @tcflush(i32 %101, i32 %102)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %108
105: ; preds = %99
%106 = load i32, i32* @stderr
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %108
108: ; preds = %105, %99
store i32 0, i32* %3
br label %109
109: ; preds = %108, %23
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
%struct.termios = type { i32, i64* }
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"unknown baudrate %d\00"
@TCIOFLUSH = global i32 0
@.str.1 = [18 x i8] c"Error: tcflush()\0A\00"
@.str.2 = [20 x i8] c"Error: tcgetattr()\0A\00"
@VTIME = global i64 0
@VMIN = global i64 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@TCSAFLUSH = global i32 0
@.str.3 = [20 x i8] c"Error: tcsetattr()\0A\00"
@TIOCM_DTR = global i32 0
@TIOCMBIS = global i32 0
@.str.4 = [16 x i8] c"Error: ioctl()\0A\00"
define i32 @stty_telos(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = alloca i32
%5 = bitcast %struct.termios* %3 to i8*
%6 = bitcast i32* %4 to i8*
switch i32 %1, label %19 [
i32 -2, label %22
i32 9600, label %7
i32 19200, label %9
i32 38400, label %11
i32 57600, label %13
i32 115200, label %15
i32 230400, label %17
]
7: ; preds = %2
%8 = load i32, i32* @B9600
br label %22
9: ; preds = %2
%10 = load i32, i32* @B19200
br label %22
11: ; preds = %2
%12 = load i32, i32* @B38400
br label %22
13: ; preds = %2
%14 = load i32, i32* @B57600
br label %22
15: ; preds = %2
%16 = load i32, i32* @B115200
br label %22
17: ; preds = %2
%18 = load i32, i32* @B230400
br label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %87
22: ; preds = %17, %15, %13, %11, %9, %7, %2
%23 = phi i32 [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ undef, %2 ]
%24 = load i32, i32* @TCIOFLUSH
%25 = tail call i32 @tcflush(i32 %0, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %22
%31 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %33, %30
%37 = call i32 @cfmakeraw(%struct.termios* %3)
%38 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%39 = load i64*, i64** %38
%40 = load i64, i64* @VTIME
%41 = getelementptr inbounds i64, i64* %39, i64 %40
store i64 0, i64* %41
%42 = load i64, i64* @VMIN
%43 = getelementptr inbounds i64, i64* %39, i64 %42
store i64 0, i64* %43
%44 = load i32, i32* @CRTSCTS
%45 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%46 = load i32, i32* %45
%47 = load i32, i32* @HUPCL
%48 = or i32 %44, %47
%49 = load i32, i32* @CLOCAL
%50 = or i32 %48, %49
%51 = xor i32 %50, -1
%52 = and i32 %46, %51
store i32 %52, i32* %45
%53 = call i32 @cfsetispeed(%struct.termios* %3, i32 %23)
%54 = call i32 @cfsetospeed(%struct.termios* %3, i32 %23)
%55 = load i32, i32* @TCSAFLUSH
%56 = call i32 @tcsetattr(i32 %0, i32 %55, %struct.termios* %3)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %36
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %58, %36
%62 = load i32, i32* @CLOCAL
%63 = load i32, i32* %45
%64 = or i32 %63, %62
store i32 %64, i32* %45
%65 = load i32, i32* @TCSAFLUSH
%66 = call i32 @tcsetattr(i32 %0, i32 %65, %struct.termios* %3)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %61
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %71
71: ; preds = %68, %61
%72 = load i32, i32* @TIOCM_DTR
store i32 %72, i32* %4
%73 = load i32, i32* @TIOCMBIS
%74 = call i32 @ioctl(i32 %0, i32 %73, i32* %4)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %79
79: ; preds = %76, %71
%80 = call i32 @usleep(i32 10000)
%81 = load i32, i32* @TCIOFLUSH
%82 = call i32 @tcflush(i32 %0, i32 %81)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %79
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %87
87: ; preds = %79, %84, %19
%88 = phi i32 [ -1, %19 ], [ 0, %84 ], [ 0, %79 ]
ret i32 %88
}