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

/* Variables and functions */
int /*<<< orphan*/ B57600;
int BRKINT;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int ECHO;
int ECHONL;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int INLCR;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int PARMRK;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int initialise_port(int fd) {
  struct termios options;
  if (tcgetattr(fd, &options) < 0) {
    return -1;
  }
  options.c_iflag &=
      ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
  options.c_oflag &= ~OPOST;
  options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  options.c_cflag &= ~(CSIZE | PARENB | CRTSCTS);
  options.c_cflag |= CS8 | CREAD | CLOCAL;
  cfsetispeed(&options, B57600);
  cfsetospeed(&options, B57600);
  if (tcsetattr(fd, TCSAFLUSH, &options) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<initialise_port>:
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    $0x0,%rax
jge    116d <initialise_port+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <initialise_port+0x161>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    0x2e1b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6a(%rip),%rcx
or     (%rcx),%eax
mov    0x2dd1(%rip),%rcx
or     (%rcx),%eax
mov    0x2e40(%rip),%rcx
or     (%rcx),%eax
mov    0x2e27(%rip),%rcx
or     (%rcx),%eax
mov    0x2e36(%rip),%rcx
or     (%rcx),%eax
mov    0x2e05(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    0x2d78(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5f(%rip),%rcx
or     (%rcx),%eax
mov    0x2dae(%rip),%rcx
or     (%rcx),%eax
mov    0x2d75(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    0x2d9a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d19(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    0x2d56(%rip),%rcx
or     (%rcx),%eax
mov    0x2ced(%rip),%rcx
or     (%rcx),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x8(%rbp),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
jge    129a <initialise_port+0x15a>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <initialise_port+0x161>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialise_port>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    %rsp,%rsi
call   1040 <tcgetattr@plt>
test   %rax,%rax
js     1265 <initialise_port+0x125>
mov    0x2ded(%rip),%rax
mov    0x2e2e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e7b(%rip),%rax
or     (%rax),%ecx
mov    0x2de2(%rip),%rax
or     (%rax),%ecx
mov    0x2e51(%rip),%rax
or     (%rax),%ecx
mov    0x2e38(%rip),%rax
or     (%rax),%ecx
mov    0x2e47(%rip),%rax
or     (%rax),%ecx
mov    0x2e16(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2de9(%rip),%rax
mov    0x2d92(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d77(%rip),%rax
or     (%rax),%ecx
mov    0x2dc6(%rip),%rax
or     (%rax),%ecx
mov    0x2d8d(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d8e(%rip),%rax
mov    0x2db7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d34(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x8(%rsp),%ecx
mov    0x2d75(%rip),%rax
mov    0x2d76(%rip),%rdx
mov    0x2d0f(%rip),%rsi
or     (%rax),%ecx
or     (%rdx),%ecx
or     (%rsi),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d46(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
sar    $0x3f,%rax
jmp    126a <initialise_port+0x12a>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@B57600 = global i32 0
@TCSAFLUSH = global i32 0
define i32 @initialise_port(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %74
9: ; preds = %1
%10 = load i32, i32* @IGNBRK
%11 = load i32, i32* @BRKINT
%12 = or i32 %10, %11
%13 = load i32, i32* @PARMRK
%14 = or i32 %12, %13
%15 = load i32, i32* @ISTRIP
%16 = or i32 %14, %15
%17 = load i32, i32* @INLCR
%18 = or i32 %16, %17
%19 = load i32, i32* @IGNCR
%20 = or i32 %18, %19
%21 = load i32, i32* @ICRNL
%22 = or i32 %20, %21
%23 = load i32, i32* @IXON
%24 = or i32 %22, %23
%25 = xor i32 %24, -1
%26 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = and i32 %27, %25
store i32 %28, i32* %26
%29 = load i32, i32* @OPOST
%30 = xor i32 %29, -1
%31 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
%32 = load i32, i32* %31
%33 = and i32 %32, %30
store i32 %33, i32* %31
%34 = load i32, i32* @ECHO
%35 = load i32, i32* @ECHONL
%36 = or i32 %34, %35
%37 = load i32, i32* @ICANON
%38 = or i32 %36, %37
%39 = load i32, i32* @ISIG
%40 = or i32 %38, %39
%41 = load i32, i32* @IEXTEN
%42 = or i32 %40, %41
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%45 = load i32, i32* %44
%46 = and i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @CSIZE
%48 = load i32, i32* @PARENB
%49 = or i32 %47, %48
%50 = load i32, i32* @CRTSCTS
%51 = or i32 %49, %50
%52 = xor i32 %51, -1
%53 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
%54 = load i32, i32* %53
%55 = and i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* @CS8
%57 = load i32, i32* @CREAD
%58 = or i32 %56, %57
%59 = load i32, i32* @CLOCAL
%60 = or i32 %58, %59
%61 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
%62 = load i32, i32* %61
%63 = or i32 %62, %60
store i32 %63, i32* %61
%64 = load i32, i32* @B57600
%65 = call i32 @cfsetispeed(%struct.termios* %4, i32 %64)
%66 = load i32, i32* @B57600
%67 = call i32 @cfsetospeed(%struct.termios* %4, i32 %66)
%68 = load i32, i32* %3
%69 = load i32, i32* @TCSAFLUSH
%70 = call i64 @tcsetattr(i32 %68, i32 %69, %struct.termios* %4)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %9
store i32 -1, i32* %2
br label %74
73: ; preds = %9
store i32 0, i32* %2
br label %74
74: ; preds = %73, %72, %8
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@B57600 = global i32 0
@TCSAFLUSH = global i32 0
define i32 @initialise_port(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %67, label %6
6: ; preds = %1
%7 = load i32, i32* @IGNBRK
%8 = load i32, i32* @BRKINT
%9 = or i32 %8, %7
%10 = load i32, i32* @PARMRK
%11 = or i32 %9, %10
%12 = load i32, i32* @ISTRIP
%13 = or i32 %11, %12
%14 = load i32, i32* @INLCR
%15 = or i32 %13, %14
%16 = load i32, i32* @IGNCR
%17 = or i32 %15, %16
%18 = load i32, i32* @ICRNL
%19 = or i32 %17, %18
%20 = load i32, i32* @IXON
%21 = or i32 %19, %20
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @OPOST
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @ECHO
%32 = load i32, i32* @ECHONL
%33 = or i32 %32, %31
%34 = load i32, i32* @ICANON
%35 = or i32 %33, %34
%36 = load i32, i32* @ISIG
%37 = or i32 %35, %36
%38 = load i32, i32* @IEXTEN
%39 = or i32 %37, %38
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @CSIZE
%45 = load i32, i32* @PARENB
%46 = or i32 %45, %44
%47 = load i32, i32* @CRTSCTS
%48 = or i32 %46, %47
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%51 = load i32, i32* %50
%52 = and i32 %51, %49
%53 = load i32, i32* @CS8
%54 = load i32, i32* @CREAD
%55 = load i32, i32* @CLOCAL
%56 = or i32 %53, %52
%57 = or i32 %56, %54
%58 = or i32 %57, %55
store i32 %58, i32* %50
%59 = load i32, i32* @B57600
%60 = call i32 @cfsetispeed(%struct.termios* %2, i32 %59)
%61 = load i32, i32* @B57600
%62 = call i32 @cfsetospeed(%struct.termios* %2, i32 %61)
%63 = load i32, i32* @TCSAFLUSH
%64 = call i64 @tcsetattr(i32 %0, i32 %63, %struct.termios* %2)
%65 = ashr i64 %64, 63
%66 = trunc i64 %65 to i32
br label %67
67: ; preds = %6, %1
%68 = phi i32 [ -1, %1 ], [ %66, %6 ]
ret i32 %68
}