#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 B460800;
int B57600;
int CBAUD;
int CBAUDEX;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int cfsetospeed(struct termios *termios_p, speed_t speed) {
  if ((speed & (speed_t)~CBAUD) != 0 && (speed < B57600 || speed > B460800)) {
    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
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1167 <cfsetospeed+0x67>
mov    -0x14(%rbp),%eax
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%eax
jl     1149 <cfsetospeed+0x49>
mov    -0x14(%rbp),%eax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%eax
jle    1167 <cfsetospeed+0x67>
mov    0x2e70(%rip),%rax
mov    (%rax),%ecx
mov    0x2e77(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <cfsetospeed+0x96>
mov    0x2e42(%rip),%rax
mov    (%rax),%ecx
mov    0x2e61(%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
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfsetospeed>:
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
not    %ecx
test   %esi,%ecx
je     1127 <cfsetospeed+0x27>
mov    0x2ed0(%rip),%rcx
cmp    %esi,(%rcx)
jg     113b <cfsetospeed+0x3b>
mov    0x2ea5(%rip),%rcx
cmp    %esi,(%rcx)
jl     113b <cfsetospeed+0x3b>
mov    0x2eaa(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rdi),%eax
or     %esi,%eax
mov    %eax,(%rdi)
xor    %eax,%eax
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    0x2e85(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CBAUD = global i32 0
@B57600 = global i32 0
@B460800 = global i32 0
@EINVAL = global i32 0
@errno = 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 %21
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* @B460800
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15, %11
%20 = load i32, i32* @EINVAL
store i32 %20, i32* @errno
store i32 -1, i32* %3
br label %35
21: ; preds = %15, %2
%22 = load i32, i32* @CBAUD
%23 = load i32, i32* @CBAUDEX
%24 = or i32 %22, %23
%25 = xor i32 %24, -1
%26 = load %struct.termios*, %struct.termios** %4
%27 = getelementptr inbounds %struct.termios, %struct.termios* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %25
store i32 %29, i32* %27
%30 = load i32, i32* %5
%31 = load %struct.termios*, %struct.termios** %4
%32 = getelementptr inbounds %struct.termios, %struct.termios* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = or i32 %33, %30
store i32 %34, i32* %32
store i32 0, i32* %3
br label %35
35: ; preds = %21, %19
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CBAUD = global i32 0
@B57600 = global i32 0
@B460800 = global i32 0
@EINVAL = global i32 0
@errno = 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 %15, label %7
7: ; preds = %2
%8 = load i32, i32* @B57600
%9 = icmp sgt i32 %8, %1
%10 = load i32, i32* @B460800
%11 = icmp slt i32 %10, %1
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = load i32, i32* @EINVAL
store i32 %14, i32* @errno
br label %23
15: ; preds = %7, %2
%16 = load i32, i32* @CBAUDEX
%17 = or i32 %16, %3
%18 = xor i32 %17, -1
%19 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%20 = load i32, i32* %19
%21 = and i32 %20, %18
%22 = or i32 %21, %1
store i32 %22, i32* %19
br label %23
23: ; preds = %15, %13
%24 = phi i32 [ -1, %13 ], [ 0, %15 ]
ret i32 %24
}