#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 speed_t;

/* Variables and functions */
#define B0 143
#define B110 142
#define B115200 141
#define B1200 140
#define B134 139
#define B150 138
#define B1800 137
#define B19200 136
#define B200 135
#define B2400 134
#define B300 133
#define B38400 132
#define B4800 131
#define B50 130
#define B600 129
#define B9600 128
int cfgetispeed(struct termios *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int uarthandler_getBaud(int fd) {
  struct termios termAttr;
  int inRate = -1;
  speed_t baudRate;
  tcgetattr(fd, &termAttr);
  baudRate = cfgetispeed(&termAttr);
  switch (baudRate) {
  case B0:
    inRate = 0;
    break;
  case B50:
    inRate = 50;
    break;
  case B110:
    inRate = 110;
    break;
  case B134:
    inRate = 134;
    break;
  case B150:
    inRate = 150;
    break;
  case B200:
    inRate = 200;
    break;
  case B300:
    inRate = 300;
    break;
  case B600:
    inRate = 600;
    break;
  case B1200:
    inRate = 1200;
    break;
  case B1800:
    inRate = 1800;
    break;
  case B2400:
    inRate = 2400;
    break;
  case B4800:
    inRate = 4800;
    break;
  case B9600:
    inRate = 9600;
    break;
  case B19200:
    inRate = 19200;
    break;
  case B38400:
    inRate = 38400;
    break;
  case B115200:
    inRate = 115200;
    break;
  }
  return inRate;
}


x86 assembly (clang, -O0):
<uarthandler_getBaud>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    %rsi,-0x20(%rbp)
call   1040 <tcgetattr@plt>
mov    -0x20(%rbp),%rdi
call   1030 <cfgetispeed@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xf,%eax
ja     1232 <uarthandler_getBaud+0x112>
mov    -0x18(%rbp),%rax
lea    0xe92(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x32,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x6e,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x86,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x96,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0xc8,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x12c,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x258,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x4b0,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x708,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x960,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x12c0,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x2580,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x4b00,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x9600,-0xc(%rbp)
jmp    1232 <uarthandler_getBaud+0x112>
movl   $0x1c200,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uarthandler_getBaud>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
mov    %rbx,%rdi
call   1030 <cfgetispeed@plt>
add    $0xffffff80,%eax
mov    $0xffffffff,%ecx
cmp    $0xf,%eax
ja     1153 <uarthandler_getBaud+0x33>
cltq
lea    0xeb0(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
define i32 @uarthandler_getBaud(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %4
%6 = load i32, i32* %2
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %3)
%8 = call i32 @cfgetispeed(%struct.termios* %3)
store i32 %8, i32* %5
%9 = load i32, i32* %5
switch i32 %9, label %26 [
i32 143, label %10
i32 130, label %11
i32 142, label %12
i32 139, label %13
i32 138, label %14
i32 135, label %15
i32 133, label %16
i32 129, label %17
i32 140, label %18
i32 137, label %19
i32 134, label %20
i32 131, label %21
i32 128, label %22
i32 136, label %23
i32 132, label %24
i32 141, label %25
]
10: ; preds = %1
store i32 0, i32* %4
br label %26
11: ; preds = %1
store i32 50, i32* %4
br label %26
12: ; preds = %1
store i32 110, i32* %4
br label %26
13: ; preds = %1
store i32 134, i32* %4
br label %26
14: ; preds = %1
store i32 150, i32* %4
br label %26
15: ; preds = %1
store i32 200, i32* %4
br label %26
16: ; preds = %1
store i32 300, i32* %4
br label %26
17: ; preds = %1
store i32 600, i32* %4
br label %26
18: ; preds = %1
store i32 1200, i32* %4
br label %26
19: ; preds = %1
store i32 1800, i32* %4
br label %26
20: ; preds = %1
store i32 2400, i32* %4
br label %26
21: ; preds = %1
store i32 4800, i32* %4
br label %26
22: ; preds = %1
store i32 9600, i32* %4
br label %26
23: ; preds = %1
store i32 19200, i32* %4
br label %26
24: ; preds = %1
store i32 38400, i32* %4
br label %26
25: ; preds = %1
store i32 115200, i32* %4
br label %26
26: ; preds = %1, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@switch.table.uarthandler_getBaud = [16 x i32] [i32 9600, i32 600, i32 50, i32 4800, i32 38400, i32 300, i32 2400, i32 200, i32 19200, i32 1800, i32 150, i32 134, i32 1200, i32 115200, i32 110, i32 0]
define i32 @uarthandler_getBaud(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = call i32 @cfgetispeed(%struct.termios* %2)
%6 = add i32 %5, -128
%7 = icmp ult i32 %6, 16
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds [16 x i32], [16 x i32]* @switch.table.uarthandler_getBaud, i64 0, i64 %9
%11 = load i32, i32* %10
br label %12
12: ; preds = %8, %1
%13 = phi i32 [ -1, %1 ], [ %11, %8 ]
ret i32 %13
}