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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int termios_init(int fd) {
  struct termios options;
  if (tcgetattr(fd, &options) == -1) {
    perror("termios_init: ");
    return -1;
  }
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~CRTSCTS;
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag &= ~OPOST;
  if (tcsetattr(fd, TCSANOW, &options) == -1) {
    perror("termios_init: ");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<termios_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1188 <termios_init+0x38>
lea    0xe89(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bb <termios_init+0x16b>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    0x2dd5(%rip),%rcx
or     (%rcx),%eax
mov    0x2d64(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    0x2d69(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    0x2d71(%rip),%rcx
or     (%rcx),%eax
mov    0x2d60(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4f(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    12b4 <termios_init+0x164>
lea    0xd5d(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bb <termios_init+0x16b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<termios_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     1253 <termios_init+0x103>
mov    0x2e36(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    0x2dc7(%rip),%rcx
or     (%rcx),%eax
mov    0x2dee(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    0x2de8(%rip),%rcx
or     (%rcx),%eax
mov    0x2e1f(%rip),%rcx
mov    0x2e28(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2db5(%rip),%rcx
or     (%rcx),%edx
mov    0x2d94(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
not    %edx
and    %edx,0x4(%rsp)
and    %eax,%ecx
mov    0x2d71(%rip),%rax
or     (%rax),%ecx
mov    0x2db0(%rip),%rax
or     (%rax),%ecx
mov    0x2d7f(%rip),%rax
mov    0x2dc0(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2dad(%rip),%rax
or     (%rax),%edx
mov    %ecx,(%rsp)
mov    0x2d99(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x8(%rsp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1253 <termios_init+0x103>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xda6(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    124a <termios_init+0xfa>

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

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