#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 */
typedef int /*<<< orphan*/ const speed_t;

/* Variables and functions */
#define B0 136
#define B115200 135
#define B19200 134
#define B230400 133
#define B2400 132
#define B38400 131
#define B4800 130
#define B57600 129
#define B9600 128
speed_t ttyParseSpeed(int speed) {
  struct speed_def {
    unsigned long val;
    speed_t arg;
  };
  static const struct speed_def sds[] = {
      {230400, B230400}, {115200, B115200}, {57600, B57600},
      {38400, B38400},   {19200, B19200},   {9600, B9600},
      {4800, B4800},     {2400, B2400},     {0, B0},
  };
  const struct speed_def *sdp;
  for (sdp = sds; sdp->val; ++sdp) {
    if (sdp->val == speed)
      return (sdp->arg);
  }
  return B0;
}


x86 assembly (clang, -O0):
<ttyParseSpeed>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
lea    0xef2(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1159 <ttyParseSpeed+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jne    1143 <ttyParseSpeed+0x43>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1160 <ttyParseSpeed+0x60>
jmp    1148 <ttyParseSpeed+0x48>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    1112 <ttyParseSpeed+0x12>
movl   $0x88,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ttyParseSpeed>:
mov    $0x88,%eax
cmp    $0x95ff,%edi
jg     1132 <ttyParseSpeed+0x32>
cmp    $0x257f,%edi
jg     1153 <ttyParseSpeed+0x53>
cmp    $0x960,%edi
je     1185 <ttyParseSpeed+0x85>
cmp    $0x12c0,%edi
jne    11aa <ttyParseSpeed+0xaa>
lea    0xf30(%rip),%rax
jmp    11a7 <ttyParseSpeed+0xa7>
cmp    $0x1c1ff,%edi
jg     116c <ttyParseSpeed+0x6c>
cmp    $0x9600,%edi
je     118e <ttyParseSpeed+0x8e>
cmp    $0xe100,%edi
jne    11aa <ttyParseSpeed+0xaa>
lea    0xecf(%rip),%rax
jmp    11a7 <ttyParseSpeed+0xa7>
cmp    $0x2580,%edi
je     1197 <ttyParseSpeed+0x97>
cmp    $0x4b00,%edi
jne    11aa <ttyParseSpeed+0xaa>
lea    0xed6(%rip),%rax
jmp    11a7 <ttyParseSpeed+0xa7>
cmp    $0x38400,%edi
je     11a0 <ttyParseSpeed+0xa0>
cmp    $0x1c200,%edi
jne    11aa <ttyParseSpeed+0xaa>
lea    0xe8d(%rip),%rax
jmp    11a7 <ttyParseSpeed+0xa7>
lea    0xee4(%rip),%rax
jmp    11a7 <ttyParseSpeed+0xa7>
lea    0xe9b(%rip),%rax
jmp    11a7 <ttyParseSpeed+0xa7>
lea    0xeb2(%rip),%rax
jmp    11a7 <ttyParseSpeed+0xa7>
lea    0xe59(%rip),%rax
mov    0x8(%rax),%eax
ret

LLVM IR (-O0):
%struct.speed_def = type { i64, i32 }
@ttyParseSpeed.sds = internal constant [9 x %struct.speed_def] [%struct.speed_def { i64 230400, i32 133 }, %struct.speed_def { i64 115200, i32 135 }, %struct.speed_def { i64 57600, i32 129 }, %struct.speed_def { i64 38400, i32 131 }, %struct.speed_def { i64 19200, i32 134 }, %struct.speed_def { i64 9600, i32 128 }, %struct.speed_def { i64 4800, i32 130 }, %struct.speed_def { i64 2400, i32 132 }, %struct.speed_def { i64 0, i32 136 }]
define i32 @ttyParseSpeed(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.speed_def*
store i32 %0, i32* %3
store %struct.speed_def* getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 0), %struct.speed_def** %4
br label %5
5: ; preds = %22, %1
%6 = load %struct.speed_def*, %struct.speed_def** %4
%7 = getelementptr inbounds %struct.speed_def, %struct.speed_def* %6, i32 0, i32 0
%8 = load i64, i64* %7
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %5
%11 = load %struct.speed_def*, %struct.speed_def** %4
%12 = getelementptr inbounds %struct.speed_def, %struct.speed_def* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = icmp eq i64 %13, %15
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load %struct.speed_def*, %struct.speed_def** %4
%19 = getelementptr inbounds %struct.speed_def, %struct.speed_def* %18, i32 0, i32 1
%20 = load i32, i32* %19
store i32 %20, i32* %2
br label %26
21: ; preds = %10
br label %22
22: ; preds = %21
%23 = load %struct.speed_def*, %struct.speed_def** %4
%24 = getelementptr inbounds %struct.speed_def, %struct.speed_def* %23, i32 1
store %struct.speed_def* %24, %struct.speed_def** %4
br label %5
25: ; preds = %5
store i32 136, i32* %2
br label %26
26: ; preds = %25, %17
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.speed_def = type { i64, i32 }
@ttyParseSpeed.sds = internal unnamed_addr constant [9 x %struct.speed_def] [%struct.speed_def { i64 230400, i32 133 }, %struct.speed_def { i64 115200, i32 135 }, %struct.speed_def { i64 57600, i32 129 }, %struct.speed_def { i64 38400, i32 131 }, %struct.speed_def { i64 19200, i32 134 }, %struct.speed_def { i64 9600, i32 128 }, %struct.speed_def { i64 4800, i32 130 }, %struct.speed_def { i64 2400, i32 132 }, %struct.speed_def { i64 0, i32 136 }]
define i32 @ttyParseSpeed(i32 %0) {
switch i32 %0, label %13 [
i32 230400, label %9
i32 115200, label %2
i32 57600, label %3
i32 38400, label %4
i32 19200, label %5
i32 9600, label %6
i32 4800, label %7
i32 2400, label %8
]
2: ; preds = %1
br label %9
3: ; preds = %1
br label %9
4: ; preds = %1
br label %9
5: ; preds = %1
br label %9
6: ; preds = %1
br label %9
7: ; preds = %1
br label %9
8: ; preds = %1
br label %9
9: ; preds = %1, %8, %7, %6, %5, %4, %3, %2
%10 = phi %struct.speed_def* [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 0), %1 ], [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 1), %2 ], [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 2), %3 ], [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 3), %4 ], [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 4), %5 ], [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 5), %6 ], [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 6), %7 ], [ getelementptr inbounds ([9 x %struct.speed_def], [9 x %struct.speed_def]* @ttyParseSpeed.sds, i64 0, i64 7), %8 ]
%11 = getelementptr inbounds %struct.speed_def, %struct.speed_def* %10, i64 0, i32 1
%12 = load i32, i32* %11
br label %13
13: ; preds = %1, %9
%14 = phi i32 [ %12, %9 ], [ 136, %1 ]
ret i32 %14
}