#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 B110 146
#define B115200 145
#define B1200 144
#define B134 143
#define B150 142
#define B1800 141
#define B19200 140
#define B200 139
#define B230400 138
#define B2400 137
#define B300 136
#define B38400 135
#define B460800 134
#define B4800 133
#define B50 132
#define B57600 131
#define B600 130
#define B75 129
#define B9600 128
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ LogMsg(int /*<<< orphan*/, char *);
int cfgetispeed(struct termios *);
int cfgetospeed(struct termios *);
unsigned long int Termios2TncomSpeed(struct termios *ti) {
  speed_t ispeed, ospeed;
  ispeed = cfgetispeed(ti);
  ospeed = cfgetospeed(ti);
  if (ispeed != ospeed) {
    LogMsg(LOG_WARNING,
           "warning: different input and output speed, using output speed");
  }
  switch (ospeed) {
  case B50:
    return (50UL);
  case B75:
    return (75UL);
  case B110:
    return (110UL);
  case B134:
    return (134UL);
  case B150:
    return (150UL);
  case B200:
    return (200UL);
  case B300:
    return (300UL);
  case B600:
    return (600UL);
  case B1200:
    return (1200UL);
  case B1800:
    return (1800UL);
  case B2400:
    return (2400UL);
  case B4800:
    return (4800UL);
  case B9600:
    return (9600UL);
  case B19200:
    return (19200UL);
  case B38400:
    return (38400UL);
  case B57600:
    return (57600UL);
  case B115200:
    return (115200UL);
  case B230400:
    return (230400UL);
  case B460800:
    return (460800UL);
  default:
    return (0UL);
  }
}


x86 assembly (clang, -O0):
<Termios2TncomSpeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cfgetispeed@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <cfgetospeed@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1175 <Termios2TncomSpeed+0x45>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xedc(%rip),%rsi
call   1040 <LogMsg@plt>
mov    -0x18(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x12,%eax
ja     1295 <Termios2TncomSpeed+0x165>
mov    -0x20(%rbp),%rax
lea    0xe6b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x32,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x4b,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x6e,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x86,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x96,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0xc8,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x12c,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x258,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x4b0,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x708,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x960,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x12c0,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x2580,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x4b00,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x9600,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0xe100,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x1c200,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x38400,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x70800,-0x8(%rbp)
jmp    129d <Termios2TncomSpeed+0x16d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Termios2TncomSpeed>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <cfgetispeed@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <cfgetospeed@plt>
mov    %eax,%ebx
cmp    %eax,%ebp
je     1160 <Termios2TncomSpeed+0x30>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
call   1040 <LogMsg@plt>
add    $0xffffff80,%ebx
cmp    $0x12,%ebx
ja     1178 <Termios2TncomSpeed+0x48>
movslq %ebx,%rax
lea    0xece(%rip),%rcx
mov    (%rcx,%rax,8),%rax
jmp    117a <Termios2TncomSpeed+0x4a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@LOG_WARNING = global i32 0
@.str = [62 x i8] c"warning: different input and output speed, using output speed\00"
define i64 @Termios2TncomSpeed(%struct.termios* %0) {
%2 = alloca i64
%3 = alloca %struct.termios*
%4 = alloca i32
%5 = alloca i32
store %struct.termios* %0, %struct.termios** %3
%6 = load %struct.termios*, %struct.termios** %3
%7 = call i32 @cfgetispeed(%struct.termios* %6)
store i32 %7, i32* %4
%8 = load %struct.termios*, %struct.termios** %3
%9 = call i32 @cfgetospeed(%struct.termios* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @LOG_WARNING
%15 = call i32 @LogMsg(i32 %14, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %1
%17 = load i32, i32* %5
switch i32 %17, label %37 [
i32 132, label %18
i32 129, label %19
i32 146, label %20
i32 143, label %21
i32 142, label %22
i32 139, label %23
i32 136, label %24
i32 130, label %25
i32 144, label %26
i32 141, label %27
i32 137, label %28
i32 133, label %29
i32 128, label %30
i32 140, label %31
i32 135, label %32
i32 131, label %33
i32 145, label %34
i32 138, label %35
i32 134, label %36
]
18: ; preds = %16
store i64 50, i64* %2
br label %38
19: ; preds = %16
store i64 75, i64* %2
br label %38
20: ; preds = %16
store i64 110, i64* %2
br label %38
21: ; preds = %16
store i64 134, i64* %2
br label %38
22: ; preds = %16
store i64 150, i64* %2
br label %38
23: ; preds = %16
store i64 200, i64* %2
br label %38
24: ; preds = %16
store i64 300, i64* %2
br label %38
25: ; preds = %16
store i64 600, i64* %2
br label %38
26: ; preds = %16
store i64 1200, i64* %2
br label %38
27: ; preds = %16
store i64 1800, i64* %2
br label %38
28: ; preds = %16
store i64 2400, i64* %2
br label %38
29: ; preds = %16
store i64 4800, i64* %2
br label %38
30: ; preds = %16
store i64 9600, i64* %2
br label %38
31: ; preds = %16
store i64 19200, i64* %2
br label %38
32: ; preds = %16
store i64 38400, i64* %2
br label %38
33: ; preds = %16
store i64 57600, i64* %2
br label %38
34: ; preds = %16
store i64 115200, i64* %2
br label %38
35: ; preds = %16
store i64 230400, i64* %2
br label %38
36: ; preds = %16
store i64 460800, i64* %2
br label %38
37: ; preds = %16
store i64 0, i64* %2
br label %38
38: ; preds = %37, %36, %35, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18
%39 = load i64, i64* %2
ret i64 %39
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@LOG_WARNING = global i32 0
@.str = [62 x i8] c"warning: different input and output speed, using output speed\00"
@switch.table.Termios2TncomSpeed = [19 x i64] [i64 9600, i64 75, i64 600, i64 57600, i64 50, i64 4800, i64 460800, i64 38400, i64 300, i64 2400, i64 230400, i64 200, i64 19200, i64 1800, i64 150, i64 134, i64 1200, i64 115200, i64 110]
define i64 @Termios2TncomSpeed(%struct.termios* %0) {
%2 = tail call i32 @cfgetispeed(%struct.termios* %0)
%3 = tail call i32 @cfgetospeed(%struct.termios* %0)
%4 = icmp eq i32 %2, %3
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* @LOG_WARNING
%7 = tail call i32 @LogMsg(i32 %6, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %5, %1
%9 = add i32 %3, -128
%10 = icmp ult i32 %9, 19
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds [19 x i64], [19 x i64]* @switch.table.Termios2TncomSpeed, i64 0, i64 %12
%14 = load i64, i64* %13
br label %15
15: ; preds = %8, %11
%16 = phi i64 [ %14, %11 ], [ 0, %8 ]
ret i64 %16
}