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

/* Variables and functions */
int BRKINT;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
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*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, int, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int SetInterfaceAttributes(int fd, int speed) {
  struct termios tty;
  if (tcgetattr(fd, &tty) < 0) {
    printf("Error from tcgetattr [%d]: %s\n", fd, strerror(errno));
    return -1;
  }
  cfsetospeed(&tty, (speed_t)speed);
  cfsetispeed(&tty, (speed_t)speed);
  tty.c_cflag |= (CLOCAL | CREAD);
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= CS8;
  tty.c_cflag |= PARENB;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_iflag &=
      ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
  tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  tty.c_oflag &= ~OPOST;
  tty.c_cc[VMIN] = 0;
  tty.c_cc[VTIME] = 1;
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    printf("Error from tcsetattr [%d]: %s\n", fd, strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<SetInterfaceAttributes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11b6 <SetInterfaceAttributes+0x56>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%esi
mov    %rax,%rdx
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1355 <SetInterfaceAttributes+0x1f5>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    0x2db2(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    0x2d4e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d9d(%rip),%rcx
or     (%rcx),%eax
mov    0x2cfc(%rip),%rcx
or     (%rcx),%eax
mov    0x2d73(%rip),%rcx
or     (%rcx),%eax
mov    0x2d62(%rip),%rcx
or     (%rcx),%eax
mov    0x2d69(%rip),%rcx
or     (%rcx),%eax
mov    0x2d40(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    0x2cb5(%rip),%rcx
or     (%rcx),%eax
mov    0x2c94(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf3(%rip),%rcx
or     (%rcx),%eax
mov    0x2cba(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2ca2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c4d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2ca9(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     134e <SetInterfaceAttributes+0x1ee>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%esi
mov    %rax,%rdx
lea    0xce2(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1355 <SetInterfaceAttributes+0x1f5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetInterfaceAttributes>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     12b9 <SetInterfaceAttributes+0x159>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    0x2d7d(%rip),%rax
mov    0x2dee(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
mov    0x2df2(%rip),%rcx
or     (%rcx),%eax
mov    0x2d51(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d50(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d67(%rip),%rdx
mov    0x2db0(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
mov    0x2dfd(%rip),%rdx
or     (%rdx),%esi
mov    0x2d5c(%rip),%rdx
or     (%rdx),%esi
mov    0x2dd3(%rip),%rdx
or     (%rdx),%esi
not    %ecx
and    %eax,%ecx
mov    0x2dbe(%rip),%rax
or     (%rax),%esi
mov    %ecx,(%rsp)
mov    0x2dc2(%rip),%rax
or     (%rax),%esi
mov    0x2d99(%rip),%rax
or     (%rax),%esi
not    %esi
and    %esi,0x4(%rsp)
mov    0x2d72(%rip),%rax
mov    0x2d13(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cf0(%rip),%rax
or     (%rax),%ecx
mov    0x2d4f(%rip),%rax
or     (%rax),%ecx
mov    0x2d16(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d03(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2cb2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
je     12e2 <SetInterfaceAttributes+0x182>
lea    0xd68(%rip),%rbp
jmp    12c0 <SetInterfaceAttributes+0x160>
lea    0xd40(%rip),%rbp
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    12e4 <SetInterfaceAttributes+0x184>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [31 x i8] c"Error from tcgetattr [%d]: %s\0A\00"
@errno = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@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
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [31 x i8] c"Error from tcsetattr [%d]: %s\0A\00"
define i32 @SetInterfaceAttributes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = call i64 @tcgetattr(i32 %7, %struct.termios* %6)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %13)
store i32 -1, i32* %3
br label %104
15: ; preds = %2
%16 = load i32, i32* %5
%17 = call i32 @cfsetospeed(%struct.termios* %6, i32 %16)
%18 = load i32, i32* %5
%19 = call i32 @cfsetispeed(%struct.termios* %6, i32 %18)
%20 = load i32, i32* @CLOCAL
%21 = load i32, i32* @CREAD
%22 = or i32 %20, %21
%23 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = or i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @CSIZE
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @CS8
%32 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%33 = load i32, i32* %32
%34 = or i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @PARENB
%36 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%37 = load i32, i32* %36
%38 = or i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @CSTOPB
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @CRTSCTS
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @IGNBRK
%50 = load i32, i32* @BRKINT
%51 = or i32 %49, %50
%52 = load i32, i32* @PARMRK
%53 = or i32 %51, %52
%54 = load i32, i32* @ISTRIP
%55 = or i32 %53, %54
%56 = load i32, i32* @INLCR
%57 = or i32 %55, %56
%58 = load i32, i32* @IGNCR
%59 = or i32 %57, %58
%60 = load i32, i32* @ICRNL
%61 = or i32 %59, %60
%62 = load i32, i32* @IXON
%63 = or i32 %61, %62
%64 = xor i32 %63, -1
%65 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%66 = load i32, i32* %65
%67 = and i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @ECHO
%69 = load i32, i32* @ECHONL
%70 = or i32 %68, %69
%71 = load i32, i32* @ICANON
%72 = or i32 %70, %71
%73 = load i32, i32* @ISIG
%74 = or i32 %72, %73
%75 = load i32, i32* @IEXTEN
%76 = or i32 %74, %75
%77 = xor i32 %76, -1
%78 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%79 = load i32, i32* %78
%80 = and i32 %79, %77
store i32 %80, i32* %78
%81 = load i32, i32* @OPOST
%82 = xor i32 %81, -1
%83 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%84 = load i32, i32* %83
%85 = and i32 %84, %82
store i32 %85, i32* %83
%86 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%87 = load i32*, i32** %86
%88 = load i64, i64* @VMIN
%89 = getelementptr inbounds i32, i32* %87, i64 %88
store i32 0, i32* %89
%90 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%91 = load i32*, i32** %90
%92 = load i64, i64* @VTIME
%93 = getelementptr inbounds i32, i32* %91, i64 %92
store i32 1, i32* %93
%94 = load i32, i32* %4
%95 = load i32, i32* @TCSANOW
%96 = call i64 @tcsetattr(i32 %94, i32 %95, %struct.termios* %6)
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %103
98: ; preds = %15
%99 = load i32, i32* %4
%100 = load i32, i32* @errno
%101 = call i8* @strerror(i32 %100)
%102 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %99, i8* %101)
store i32 -1, i32* %3
br label %104
103: ; preds = %15
store i32 0, i32* %3
br label %104
104: ; preds = %103, %98, %10
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [31 x i8] c"Error from tcgetattr [%d]: %s\0A\00"
@errno = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@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
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [31 x i8] c"Error from tcsetattr [%d]: %s\0A\00"
define i32 @SetInterfaceAttributes(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i64 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %74, label %7
7: ; preds = %2
%8 = call i32 @cfsetospeed(%struct.termios* %3, i32 %1)
%9 = call i32 @cfsetispeed(%struct.termios* %3, i32 %1)
%10 = load i32, i32* @CLOCAL
%11 = load i32, i32* @CREAD
%12 = or i32 %11, %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %12, %14
%16 = load i32, i32* @CSIZE
%17 = xor i32 %16, -1
%18 = and i32 %15, %17
%19 = load i32, i32* @CS8
%20 = or i32 %19, %18
%21 = load i32, i32* @PARENB
%22 = or i32 %21, %20
%23 = load i32, i32* @CSTOPB
%24 = load i32, i32* @CRTSCTS
%25 = or i32 %23, %24
%26 = xor i32 %25, -1
%27 = and i32 %22, %26
store i32 %27, i32* %13
%28 = load i32, i32* @IGNBRK
%29 = load i32, i32* @BRKINT
%30 = or i32 %29, %28
%31 = load i32, i32* @PARMRK
%32 = or i32 %30, %31
%33 = load i32, i32* @ISTRIP
%34 = or i32 %32, %33
%35 = load i32, i32* @INLCR
%36 = or i32 %34, %35
%37 = load i32, i32* @IGNCR
%38 = or i32 %36, %37
%39 = load i32, i32* @ICRNL
%40 = or i32 %38, %39
%41 = load i32, i32* @IXON
%42 = or i32 %40, %41
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%45 = load i32, i32* %44
%46 = and i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @ECHO
%48 = load i32, i32* @ECHONL
%49 = or i32 %48, %47
%50 = load i32, i32* @ICANON
%51 = or i32 %49, %50
%52 = load i32, i32* @ISIG
%53 = or i32 %51, %52
%54 = load i32, i32* @IEXTEN
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @OPOST
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%66 = load i32*, i32** %65
%67 = load i64, i64* @VMIN
%68 = getelementptr inbounds i32, i32* %66, i64 %67
store i32 0, i32* %68
%69 = load i64, i64* @VTIME
%70 = getelementptr inbounds i32, i32* %66, i64 %69
store i32 1, i32* %70
%71 = load i32, i32* @TCSANOW
%72 = call i64 @tcsetattr(i32 %0, i32 %71, %struct.termios* %3)
%73 = icmp eq i64 %72, 0
br i1 %73, label %79, label %74
74: ; preds = %7, %2
%75 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %7 ]
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 @printf(i8* %75, i32 %0, i8* %77)
br label %79
79: ; preds = %74, %7
%80 = phi i32 [ 0, %7 ], [ -1, %74 ]
ret i32 %80
}