#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 dummy;
};
typedef int /*<<< orphan*/ speed_t;

/* Variables and functions */
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int errno;
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int _osmo_serial_set_baudrate(int fd, speed_t baudrate) {
  int rc;
  struct termios tio;
  rc = tcgetattr(fd, &tio);
  if (rc < 0) {
    do {
    } while (0);
    return -errno;
  }
  cfsetispeed(&tio, baudrate);
  cfsetospeed(&tio, baudrate);
  rc = tcsetattr(fd, TCSANOW, &tio);
  if (rc < 0) {
    do {
    } while (0);
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_osmo_serial_set_baudrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1184 <_osmo_serial_set_baudrate+0x44>
jmp    116c <_osmo_serial_set_baudrate+0x2c>
jmp    1171 <_osmo_serial_set_baudrate+0x31>
xor    %eax,%eax
mov    0x2e5e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <_osmo_serial_set_baudrate+0xa2>
mov    -0xc(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x8(%rbp),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11db <_osmo_serial_set_baudrate+0x9b>
jmp    11c3 <_osmo_serial_set_baudrate+0x83>
jmp    11c8 <_osmo_serial_set_baudrate+0x88>
xor    %eax,%eax
mov    0x2e07(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <_osmo_serial_set_baudrate+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_osmo_serial_set_baudrate>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1040 <tcgetattr@plt>
test   %eax,%eax
js     118e <_osmo_serial_set_baudrate+0x4e>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jns    1199 <_osmo_serial_set_baudrate+0x59>
mov    0x2e43(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@errno = global i32 0
@TCSANOW = global i32 0
define i32 @_osmo_serial_set_baudrate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %7)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
br label %13
13: ; preds = %12
br label %14
14: ; preds = %13
%15 = load i32, i32* @errno
%16 = sub nsw i32 0, %15
store i32 %16, i32* %3
br label %33
17: ; preds = %2
%18 = load i32, i32* %5
%19 = call i32 @cfsetispeed(%struct.termios* %7, i32 %18)
%20 = load i32, i32* %5
%21 = call i32 @cfsetospeed(%struct.termios* %7, i32 %20)
%22 = load i32, i32* %4
%23 = load i32, i32* @TCSANOW
%24 = call i32 @tcsetattr(i32 %22, i32 %23, %struct.termios* %7)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %17
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
%30 = load i32, i32* @errno
%31 = sub nsw i32 0, %30
store i32 %31, i32* %3
br label %33
32: ; preds = %17
store i32 0, i32* %3
br label %33
33: ; preds = %32, %29, %14
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@errno = global i32 0
@TCSANOW = global i32 0
define i32 @_osmo_serial_set_baudrate(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %19
10: ; preds = %2
%11 = call i32 @cfsetispeed(%struct.termios* %3, i32 %1)
%12 = call i32 @cfsetospeed(%struct.termios* %3, i32 %1)
%13 = load i32, i32* @TCSANOW
%14 = call i32 @tcsetattr(i32 %0, i32 %13, %struct.termios* %3)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
br label %19
19: ; preds = %10, %16, %7
%20 = phi i32 [ %9, %7 ], [ %18, %16 ], [ 0, %10 ]
ret i32 %20
}