#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 144
#define B110 143
#define B115200 142
#define B1200 141
#define B134 140
#define B150 139
#define B1800 138
#define B19200 137
#define B200 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 *);
long int getbaud(int fd) {
  struct termios termAttr;
  long 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 = 57600;
    break;
  case B115200:
    inputSpeed = 115200;
    break;
  }
  return inputSpeed;
}


x86 assembly (clang, -O0):
<getbaud>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    %rsi,-0x28(%rbp)
call   1040 <tcgetattr@plt>
mov    -0x28(%rbp),%rdi
call   1030 <cfgetispeed@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x10,%eax
ja     1250 <getbaud+0x130>
mov    -0x20(%rbp),%rax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x0,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x32,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x6e,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x86,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x96,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0xc8,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x12c,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x258,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x4b0,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x708,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x960,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x12c0,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x2580,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x4b00,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x9600,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0xe100,-0x10(%rbp)
jmp    1250 <getbaud+0x130>
movq   $0x1c200,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%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    $0xffffffffffffffff,%rcx
cmp    $0x10,%eax
ja     1156 <getbaud+0x36>
cltq
lea    0xeae(%rip),%rcx
mov    (%rcx,%rax,8),%rcx
mov    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

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

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