#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 142
#define B110 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 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;
  }
  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    $0xe,%eax
ja     1226 <getbaud+0x106>
mov    -0x18(%rbp),%rax
lea    0xe92(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x32,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x6e,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x86,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x96,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0xc8,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x12c,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x258,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x4b0,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x708,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x960,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x12c0,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x2580,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x4b00,-0xc(%rbp)
jmp    1226 <getbaud+0x106>
movl   $0x9600,-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    $0xe,%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 %25 [
i32 142, label %10
i32 130, label %11
i32 141, 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
]
10: ; preds = %1
store i32 0, i32* %4
br label %25
11: ; preds = %1
store i32 50, i32* %4
br label %25
12: ; preds = %1
store i32 110, i32* %4
br label %25
13: ; preds = %1
store i32 134, i32* %4
br label %25
14: ; preds = %1
store i32 150, i32* %4
br label %25
15: ; preds = %1
store i32 200, i32* %4
br label %25
16: ; preds = %1
store i32 300, i32* %4
br label %25
17: ; preds = %1
store i32 600, i32* %4
br label %25
18: ; preds = %1
store i32 1200, i32* %4
br label %25
19: ; preds = %1
store i32 1800, i32* %4
br label %25
20: ; preds = %1
store i32 2400, i32* %4
br label %25
21: ; preds = %1
store i32 4800, i32* %4
br label %25
22: ; preds = %1
store i32 9600, i32* %4
br label %25
23: ; preds = %1
store i32 19200, i32* %4
br label %25
24: ; preds = %1
store i32 38400, i32* %4
br label %25
25: ; preds = %1, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@switch.table.getbaud = [15 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 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, 15
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds [15 x i32], [15 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
}