#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;
};
typedef int speed_t;

/* Variables and functions */
int B57600;
int CBAUD;
int CBAUDEX;
int /*<<< orphan*/ EINVAL;
int __MAX_BAUD;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int cfsetospeed(struct termios *termios_p, speed_t speed) {
  if ((speed & ~CBAUD) != 0 && (speed < B57600 || speed > __MAX_BAUD)) {
    __set_errno(EINVAL);
    return -1;
  }
  termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
  termios_p->c_cflag |= speed;
  return 0;
}


x86 assembly (clang, -O0):
<cfsetospeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1177 <cfsetospeed+0x67>
mov    -0x14(%rbp),%eax
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%eax
jl     115d <cfsetospeed+0x4d>
mov    -0x14(%rbp),%eax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%eax
jle    1177 <cfsetospeed+0x67>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <cfsetospeed+0x96>
mov    0x2e3a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e49(%rip),%rax
or     (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfsetospeed>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
not    %ecx
test   %esi,%ecx
je     1138 <cfsetospeed+0x28>
mov    0x2ebf(%rip),%rcx
cmp    %esi,(%rcx)
jg     114d <cfsetospeed+0x3d>
mov    0x2ea4(%rip),%rcx
cmp    %esi,(%rcx)
jl     114d <cfsetospeed+0x3d>
mov    0x2e91(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rdi),%eax
or     %esi,%eax
mov    %eax,(%rdi)
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CBAUD = global i32 0
@B57600 = global i32 0
@__MAX_BAUD = global i32 0
@EINVAL = global i32 0
@CBAUDEX = global i32 0
define i32 @cfsetospeed(%struct.termios* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.termios*
%5 = alloca i32
store %struct.termios* %0, %struct.termios** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = load i32, i32* @CBAUD
%8 = xor i32 %7, -1
%9 = and i32 %6, %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = load i32, i32* %5
%13 = load i32, i32* @B57600
%14 = icmp slt i32 %12, %13
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i32, i32* %5
%17 = load i32, i32* @__MAX_BAUD
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15, %11
%20 = load i32, i32* @EINVAL
%21 = call i32 @__set_errno(i32 %20)
store i32 -1, i32* %3
br label %36
22: ; preds = %15, %2
%23 = load i32, i32* @CBAUD
%24 = load i32, i32* @CBAUDEX
%25 = or i32 %23, %24
%26 = xor i32 %25, -1
%27 = load %struct.termios*, %struct.termios** %4
%28 = getelementptr inbounds %struct.termios, %struct.termios* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %26
store i32 %30, i32* %28
%31 = load i32, i32* %5
%32 = load %struct.termios*, %struct.termios** %4
%33 = getelementptr inbounds %struct.termios, %struct.termios* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = or i32 %34, %31
store i32 %35, i32* %33
store i32 0, i32* %3
br label %36
36: ; preds = %22, %19
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CBAUD = global i32 0
@B57600 = global i32 0
@__MAX_BAUD = global i32 0
@EINVAL = global i32 0
@CBAUDEX = global i32 0
define i32 @cfsetospeed(%struct.termios* nocapture %0, i32 %1) {
%3 = load i32, i32* @CBAUD
%4 = xor i32 %3, -1
%5 = and i32 %4, %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = load i32, i32* @B57600
%9 = icmp sgt i32 %8, %1
%10 = load i32, i32* @__MAX_BAUD
%11 = icmp slt i32 %10, %1
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i32, i32* @EINVAL
%15 = tail call i32 @__set_errno(i32 %14)
br label %24
16: ; preds = %7, %2
%17 = load i32, i32* @CBAUDEX
%18 = or i32 %17, %3
%19 = xor i32 %18, -1
%20 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, %19
%23 = or i32 %22, %1
store i32 %23, i32* %20
br label %24
24: ; preds = %16, %13
%25 = phi i32 [ -1, %13 ], [ 0, %16 ]
ret i32 %25
}