#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 */

/* Variables and functions */
int /*<<< orphan*/ ENODEV;
int cc3_uart_get_count();
int /*<<< orphan*/ errno;
int process_uart_filename(char const *);
int uart_open(const char *name, int flags __attribute__((unused)),
              int mode __attribute__((unused))) {
  int uart_num = process_uart_filename(name);
  if (uart_num >= 0 && uart_num < cc3_uart_get_count()) {
    return uart_num + 16;
  } else {
    errno = ENODEV;
    return -1;
  }
}


x86 assembly (clang, -O0):
<uart_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <process_uart_filename@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1170 <uart_open+0x50>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <cc3_uart_get_count@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1170 <uart_open+0x50>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <uart_open+0x69>
mov    0x2e61(%rip),%rax
mov    (%rax),%ecx
mov    0x2e60(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_open>:
push   %rbx
call   1030 <process_uart_filename@plt>
test   %eax,%eax
js     113c <uart_open+0x1c>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <cc3_uart_get_count@plt>
cmp    %eax,%ebx
jge    113c <uart_open+0x1c>
add    $0x10,%ebx
jmp    1153 <uart_open+0x33>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    0x2e94(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@ENODEV = global i32 0
@errno = global i32 0
define i32 @uart_open(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @process_uart_filename(i8* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i32, i32* %8
%15 = call i32 (...) @cc3_uart_get_count()
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 16
store i32 %19, i32* %4
br label %22
20: ; preds = %13, %3
%21 = load i32, i32* @ENODEV
store i32 %21, i32* @errno
store i32 -1, i32* %4
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@ENODEV = global i32 0
@errno = global i32 0
define i32 @uart_open(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @process_uart_filename(i8* %0)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call i32 (...) @cc3_uart_get_count()
%8 = icmp slt i32 %4, %7
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = add nuw nsw i32 %4, 16
br label %13
11: ; preds = %6, %3
%12 = load i32, i32* @ENODEV
store i32 %12, i32* @errno
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %10, %9 ], [ -1, %11 ]
ret i32 %14
}