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


x86 assembly (clang, -O0):
<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    $0x11,%eax
ja     124a <getbaud+0x12a>
mov    -0x18(%rbp),%rax
lea    0xe92(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x32,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x6e,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x86,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x96,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0xc8,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x12c,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x258,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x4b0,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x708,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x960,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x12c0,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x2580,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x4b00,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x9600,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x9600,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x9600,-0xc(%rbp)
jmp    124a <getbaud+0x12a>
movl   $0x38400,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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    $0x11,%eax
ja     1153 <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 @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 %28 [
i32 145, label %10
i32 131, label %11
i32 144, label %12
i32 141, label %13
i32 140, label %14
i32 137, label %15
i32 134, label %16
i32 129, label %17
i32 142, label %18
i32 139, label %19
i32 135, label %20
i32 132, label %21
i32 128, label %22
i32 138, label %23
i32 133, label %24
i32 130, label %25
i32 143, label %26
i32 136, label %27
]
10: ; preds = %1
store i32 0, i32* %4
br label %28
11: ; preds = %1
store i32 50, i32* %4
br label %28
12: ; preds = %1
store i32 110, i32* %4
br label %28
13: ; preds = %1
store i32 134, i32* %4
br label %28
14: ; preds = %1
store i32 150, i32* %4
br label %28
15: ; preds = %1
store i32 200, i32* %4
br label %28
16: ; preds = %1
store i32 300, i32* %4
br label %28
17: ; preds = %1
store i32 600, i32* %4
br label %28
18: ; preds = %1
store i32 1200, i32* %4
br label %28
19: ; preds = %1
store i32 1800, i32* %4
br label %28
20: ; preds = %1
store i32 2400, i32* %4
br label %28
21: ; preds = %1
store i32 4800, i32* %4
br label %28
22: ; preds = %1
store i32 9600, i32* %4
br label %28
23: ; preds = %1
store i32 19200, i32* %4
br label %28
24: ; preds = %1
store i32 38400, i32* %4
br label %28
25: ; preds = %1
store i32 38400, i32* %4
br label %28
26: ; preds = %1
store i32 38400, i32* %4
br label %28
27: ; preds = %1
store i32 230400, i32* %4
br label %28
28: ; preds = %1, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@switch.table.getbaud = [18 x i32] [i32 9600, i32 600, i32 38400, i32 50, i32 4800, i32 38400, i32 300, i32 2400, i32 230400, i32 200, i32 19200, i32 1800, i32 150, i32 134, i32 1200, i32 38400, i32 110, i32 0]
define i32 @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, 18
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds [18 x i32], [18 x i32]* @switch.table.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
}