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

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ IGNPAR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int wattsup_set_serial_attributes(int fd) {
  assert(fd > 0);
  struct termios t;
  if (tcgetattr(fd, &t)) {
    return -1;
  }
  cfmakeraw(&t);
  cfsetispeed(&t, B115200);
  cfsetospeed(&t, B115200);
  tcflush(fd, TCIFLUSH);
  t.c_iflag |= IGNPAR;
  t.c_cflag &= ~CSTOPB;
  return tcsetattr(fd, TCSANOW, &t);
}


x86 assembly (clang, -O0):
<wattsup_set_serial_attributes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1070 <tcgetattr@plt>
cmp    $0x0,%rax
je     11ae <wattsup_set_serial_attributes+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1225 <wattsup_set_serial_attributes+0xb5>
lea    -0x10(%rbp),%rdi
call   1060 <cfmakeraw@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x8(%rbp),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wattsup_set_serial_attributes>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1050 <assert@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1070 <tcgetattr@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    120a <wattsup_set_serial_attributes+0x9a>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1060 <cfmakeraw@plt>
mov    0x2e1b(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
or     %eax,0xc(%rsp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@B115200 = global i32 0
@TCIFLUSH = global i32 0
@IGNPAR = global i32 0
@CSTOPB = global i32 0
@TCSANOW = global i32 0
define i32 @wattsup_set_serial_attributes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %3
%10 = call i64 @tcgetattr(i32 %9, %struct.termios* %4)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %34
13: ; preds = %1
%14 = call i32 @cfmakeraw(%struct.termios* %4)
%15 = load i32, i32* @B115200
%16 = call i32 @cfsetispeed(%struct.termios* %4, i32 %15)
%17 = load i32, i32* @B115200
%18 = call i32 @cfsetospeed(%struct.termios* %4, i32 %17)
%19 = load i32, i32* %3
%20 = load i32, i32* @TCIFLUSH
%21 = call i32 @tcflush(i32 %19, i32 %20)
%22 = load i32, i32* @IGNPAR
%23 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%24 = load i32, i32* %23
%25 = or i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @CSTOPB
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* %3
%32 = load i32, i32* @TCSANOW
%33 = call i32 @tcsetattr(i32 %31, i32 %32, %struct.termios* %4)
store i32 %33, i32* %2
br label %34
34: ; preds = %13, %12
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@B115200 = global i32 0
@TCIFLUSH = global i32 0
@IGNPAR = global i32 0
@CSTOPB = global i32 0
@TCSANOW = global i32 0
define i32 @wattsup_set_serial_attributes(i32 %0) {
%2 = alloca %struct.termios
%3 = icmp sgt i32 %0, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = bitcast %struct.termios* %2 to i8*
%7 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = call i32 @cfmakeraw(%struct.termios* %2)
%11 = load i32, i32* @B115200
%12 = call i32 @cfsetispeed(%struct.termios* %2, i32 %11)
%13 = load i32, i32* @B115200
%14 = call i32 @cfsetospeed(%struct.termios* %2, i32 %13)
%15 = load i32, i32* @TCIFLUSH
%16 = call i32 @tcflush(i32 %0, i32 %15)
%17 = load i32, i32* @IGNPAR
%18 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%19 = load i32, i32* %18
%20 = or i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* @CSTOPB
%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* @TCSANOW
%27 = call i32 @tcsetattr(i32 %0, i32 %26, %struct.termios* %2)
br label %28
28: ; preds = %1, %9
%29 = phi i32 [ %27, %9 ], [ -1, %1 ]
ret i32 %29
}