#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_lflag;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int /*<<< orphan*/ B115200;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int /*<<< orphan*/ INPCK;
int ISIG;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCIFLUSH;
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*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int init_serial(void) {
  int serial_fd = 0;
  serial_fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (serial_fd < 0) {
    perror("open");
    return -1;
  }
  struct termios options;
  tcgetattr(serial_fd, &options);
  cfsetispeed(&options, B115200);
  cfsetospeed(&options, B115200);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~CRTSCTS;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~PARENB;
  options.c_iflag &= ~INPCK;
  options.c_oflag &= ~OPOST;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag = 0;
  options.c_lflag = 0;
  tcflush(serial_fd, TCIFLUSH);
  if (tcsetattr(serial_fd, TCSANOW, &options) != 0) {
    perror("tcsetattr error");
    return -1;
  }
  printf("configure complete\n");
  return serial_fd;
}


x86 assembly (clang, -O0):
<init_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
mov    0x2dd0(%rip),%rax
or     (%rax),%esi
lea    0xe4f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11db <init_serial+0x5b>
lea    0xe43(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1333 <init_serial+0x1b3>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
mov    0x2d95(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
mov    0x2d1a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d09(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf8(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cad(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     1321 <init_serial+0x1a1>
lea    0xd02(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1333 <init_serial+0x1b3>
lea    0xcfa(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_serial>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e58(%rip),%rax
mov    0x2e11(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df6(%rip),%rax
or     (%rax),%esi
lea    0xe55(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1289 <init_serial+0x109>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2dc2(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d85(%rip),%rax
mov    0x2dde(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2dbb(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6a(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d59(%rip),%rdx
or     (%rdx),%ecx
mov    0x2db8(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
movq   $0x0,0x4(%rsp)
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <tcflush@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
jne    1292 <init_serial+0x112>
lea    0xdaa(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd7d(%rip),%rdi
jmp    1299 <init_serial+0x119>
lea    0xd79(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%ebx
jmp    127d <init_serial+0xfd>

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

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CSTOPB = global i32 0
@PARENB = global i32 0
@INPCK = global i32 0
@OPOST = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.2 = [16 x i8] c"tcsetattr error\00"
@str = [19 x i8] c"configure complete\00"
define i32 @init_serial() {
%1 = alloca %struct.termios
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = load i32, i32* @O_NDELAY
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %54
11: ; preds = %0
%12 = bitcast %struct.termios* %1 to i8*
%13 = call i32 @tcgetattr(i32 %7, %struct.termios* %1)
%14 = load i32, i32* @B115200
%15 = call i32 @cfsetispeed(%struct.termios* %1, i32 %14)
%16 = load i32, i32* @B115200
%17 = call i32 @cfsetospeed(%struct.termios* %1, i32 %16)
%18 = load i32, i32* @CLOCAL
%19 = load i32, i32* @CREAD
%20 = or i32 %19, %18
%21 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%22 = load i32, i32* %21
%23 = or i32 %20, %22
%24 = load i32, i32* @CSIZE
%25 = xor i32 %24, -1
%26 = and i32 %23, %25
%27 = load i32, i32* @CS8
%28 = or i32 %27, %26
%29 = load i32, i32* @CRTSCTS
%30 = load i32, i32* @CSTOPB
%31 = or i32 %29, %30
%32 = load i32, i32* @PARENB
%33 = or i32 %31, %32
%34 = xor i32 %33, -1
%35 = and i32 %28, %34
store i32 %35, i32* %21
%36 = load i32, i32* @INPCK
%37 = xor i32 %36, -1
%38 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 3
%39 = load i32, i32* %38
%40 = and i32 %39, %37
store i32 %40, i32* %38
%41 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%42 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
store i32 0, i32* %41
store i32 0, i32* %42
%43 = load i32, i32* @TCIFLUSH
%44 = call i32 @tcflush(i32 %7, i32 %43)
%45 = load i32, i32* @TCSANOW
%46 = call i64 @tcsetattr(i32 %7, i32 %45, %struct.termios* %1)
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %11
%49 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %52
50: ; preds = %11
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %52
52: ; preds = %50, %48
%53 = phi i32 [ -1, %48 ], [ %7, %50 ]
br label %54
54: ; preds = %52, %9
%55 = phi i32 [ -1, %9 ], [ %53, %52 ]
ret i32 %55
}