#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;
scalar_t__ cfsetispeed(struct termios *, int /*<<< orphan*/);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int irm_set_uart_speed(int uart, struct termios *uart_config, speed_t speed) {
  if (cfsetispeed(uart_config, speed) < 0) {
    return -1;
  }
  if (tcsetattr(uart, TCSANOW, uart_config) < 0) {
    return -1;
  }
  return uart;
}


x86 assembly (clang, -O0):
<irm_set_uart_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cfsetispeed@plt>
cmp    $0x0,%rax
jge    1154 <irm_set_uart_speed+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    1185 <irm_set_uart_speed+0x65>
mov    -0x8(%rbp),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <tcsetattr@plt>
cmp    $0x0,%rax
jge    117f <irm_set_uart_speed+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1185 <irm_set_uart_speed+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irm_set_uart_speed>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
mov    %edx,%esi
call   1040 <cfsetispeed@plt>
test   %rax,%rax
js     1157 <irm_set_uart_speed+0x37>
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1030 <tcsetattr@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovns %ebp,%eax
jmp    115c <irm_set_uart_speed+0x3c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCSANOW = global i32 0
define i32 @irm_set_uart_speed(i32 %0, %struct.termios* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios*
%7 = alloca i32
store i32 %0, i32* %5
store %struct.termios* %1, %struct.termios** %6
store i32 %2, i32* %7
%8 = load %struct.termios*, %struct.termios** %6
%9 = load i32, i32* %7
%10 = call i64 @cfsetispeed(%struct.termios* %8, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %22
13: ; preds = %3
%14 = load i32, i32* %5
%15 = load i32, i32* @TCSANOW
%16 = load %struct.termios*, %struct.termios** %6
%17 = call i64 @tcsetattr(i32 %14, i32 %15, %struct.termios* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -1, i32* %4
br label %22
20: ; preds = %13
%21 = load i32, i32* %5
store i32 %21, i32* %4
br label %22
22: ; preds = %20, %19, %12
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCSANOW = global i32 0
define i32 @irm_set_uart_speed(i32 %0, %struct.termios* %1, i32 %2) {
%4 = tail call i64 @cfsetispeed(%struct.termios* %1, i32 %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = load i32, i32* @TCSANOW
%8 = tail call i64 @tcsetattr(i32 %0, i32 %7, %struct.termios* %1)
%9 = icmp slt i64 %8, 0
%10 = select i1 %9, i32 -1, i32 %0
br label %11
11: ; preds = %6, %3
%12 = phi i32 [ -1, %3 ], [ %10, %6 ]
ret i32 %12
}