#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_ospeed;
};

/* Variables and functions */
int CBAUD;
int CBAUDEX;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int cf2setospeed_custom(struct termios *tios, int speed) {
  if (speed <= 0) {
    errno = EINVAL;
    return -1;
  }
  tios->c_cflag &= ~(CBAUD | CBAUDEX);
  tios->c_cflag |= CBAUDEX;
  tios->c_ospeed = speed;
  return 0;
}


x86 assembly (clang, -O0):
<cf2setospeed_custom>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1133 <cf2setospeed_custom+0x33>
mov    0x2eb4(%rip),%rax
mov    (%rax),%ecx
mov    0x2eb3(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1172 <cf2setospeed_custom+0x72>
mov    0x2e86(%rip),%rax
mov    (%rax),%ecx
mov    0x2e9d(%rip),%rax
or     (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    0x2e89(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cf2setospeed_custom>:
test   %esi,%esi
jle    1126 <cf2setospeed_custom+0x26>
mov    0x2eb5(%rip),%rax
mov    0x2ece(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
not    %edx
and    (%rdi),%edx
mov    %edx,(%rdi)
or     (%rcx),%edx
mov    %edx,(%rdi)
mov    %esi,0x4(%rdi)
xor    %eax,%eax
ret
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    0x2ea2(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret

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

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
@CBAUD = global i32 0
@CBAUDEX = global i32 0
define i32 @cf2setospeed_custom(%struct.termios* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32, i32* @EINVAL
store i32 %5, i32* @errno
br label %17
6: ; preds = %2
%7 = load i32, i32* @CBAUD
%8 = load i32, i32* @CBAUDEX
%9 = or i32 %8, %7
%10 = xor i32 %9, -1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = and i32 %12, %10
store i32 %13, i32* %11
%14 = load i32, i32* @CBAUDEX
%15 = or i32 %14, %13
store i32 %15, i32* %11
%16 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 1
store i32 %1, i32* %16
br label %17
17: ; preds = %6, %4
%18 = phi i32 [ -1, %4 ], [ 0, %6 ]
ret i32 %18
}