#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 CBAUD;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int cfsetospeed(struct termios *tio, speed_t speed) {
  if (speed & ~CBAUD) {
    errno = EINVAL;
    return -1;
  }
  tio->c_cflag &= ~CBAUD;
  tio->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    0x2eb3(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1143 <cfsetospeed+0x43>
mov    0x2eac(%rip),%rax
mov    (%rax),%ecx
mov    0x2eab(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1169 <cfsetospeed+0x69>
mov    0x2e7e(%rip),%rax
mov    (%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    0x2ec1(%rip),%rax
mov    (%rax),%eax
not    %eax
test   %esi,%eax
je     1127 <cfsetospeed+0x27>
mov    0x2ec2(%rip),%rax
mov    (%rax),%eax
mov    0x2ec1(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
and    (%rdi),%eax
or     %esi,%eax
mov    %eax,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CBAUD = global i32 0
@EINVAL = global i32 0
@errno = 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 %13
11: ; preds = %2
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
store i32 -1, i32* %3
br label %25
13: ; preds = %2
%14 = load i32, i32* @CBAUD
%15 = xor i32 %14, -1
%16 = load %struct.termios*, %struct.termios** %4
%17 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = and i32 %18, %15
store i32 %19, i32* %17
%20 = load i32, i32* %5
%21 = load %struct.termios*, %struct.termios** %4
%22 = getelementptr inbounds %struct.termios, %struct.termios* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = or i32 %23, %20
store i32 %24, i32* %22
store i32 0, i32* %3
br label %25
25: ; preds = %13, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CBAUD = global i32 0
@EINVAL = global i32 0
@errno = 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 %9, label %7
7: ; preds = %2
%8 = load i32, i32* @EINVAL
store i32 %8, i32* @errno
br label %14
9: ; preds = %2
%10 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %4
%13 = or i32 %12, %1
store i32 %13, i32* %10
br label %14
14: ; preds = %9, %7
%15 = phi i32 [ -1, %7 ], [ 0, %9 ]
ret i32 %15
}