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

/* Variables and functions */
int /*<<< orphan*/ B110;
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B1200;
int /*<<< orphan*/ B134;
int /*<<< orphan*/ B150;
int /*<<< orphan*/ B1800;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B200;
int /*<<< orphan*/ B230400;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B300;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B460800;
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ B50;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B600;
int /*<<< orphan*/ B75;
int /*<<< orphan*/ B9600;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ LogMsg(int /*<<< orphan*/, char *);
int /*<<< orphan*/ TCSADRAIN;
int /*<<< orphan*/ UnixLogPortSettings(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void SetPortSpeed(int PortFd, unsigned long BaudRate) {
  struct termios PortSettings;
  speed_t Speed;
  switch (BaudRate) {
  case 50UL:
    Speed = B50;
    break;
  case 75UL:
    Speed = B75;
    break;
  case 110UL:
    Speed = B110;
    break;
  case 134UL:
    Speed = B134;
    break;
  case 150UL:
    Speed = B150;
    break;
  case 200UL:
    Speed = B200;
    break;
  case 300UL:
    Speed = B300;
    break;
  case 600UL:
    Speed = B600;
    break;
  case 1200UL:
    Speed = B1200;
    break;
  case 1800UL:
    Speed = B1800;
    break;
  case 2400UL:
    Speed = B2400;
    break;
  case 4800UL:
    Speed = B4800;
    break;
  case 9600UL:
    Speed = B9600;
    break;
  case 19200UL:
    Speed = B19200;
    break;
  case 38400UL:
    Speed = B38400;
    break;
  case 57600UL:
    Speed = B57600;
    break;
  case 115200UL:
    Speed = B115200;
    break;
  case 230400UL:
    Speed = B230400;
    break;
  case 460800UL:
    Speed = B460800;
    break;
  default:
    LogMsg(LOG_WARNING, "Unknwon baud rate requested, setting to 9600.");
    Speed = B9600;
    break;
  }
  tcgetattr(PortFd, &PortSettings);
  cfsetospeed(&PortSettings, Speed);
  cfsetispeed(&PortSettings, Speed);
  tcsetattr(PortFd, TCSADRAIN, &PortSettings);
  UnixLogPortSettings(&PortSettings);
}


x86 assembly (clang, -O0):
<SetPortSpeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
sub    $0x32,%rax
je     12fc <SetPortSpeed+0x19c>
jmp    1186 <SetPortSpeed+0x26>
mov    -0x28(%rbp),%rax
sub    $0x4b,%rax
je     130d <SetPortSpeed+0x1ad>
jmp    1199 <SetPortSpeed+0x39>
mov    -0x28(%rbp),%rax
sub    $0x6e,%rax
je     131e <SetPortSpeed+0x1be>
jmp    11ac <SetPortSpeed+0x4c>
mov    -0x28(%rbp),%rax
sub    $0x86,%rax
je     132f <SetPortSpeed+0x1cf>
jmp    11c1 <SetPortSpeed+0x61>
mov    -0x28(%rbp),%rax
sub    $0x96,%rax
je     1340 <SetPortSpeed+0x1e0>
jmp    11d6 <SetPortSpeed+0x76>
mov    -0x28(%rbp),%rax
sub    $0xc8,%rax
je     1351 <SetPortSpeed+0x1f1>
jmp    11eb <SetPortSpeed+0x8b>
mov    -0x28(%rbp),%rax
sub    $0x12c,%rax
je     1362 <SetPortSpeed+0x202>
jmp    1200 <SetPortSpeed+0xa0>
mov    -0x28(%rbp),%rax
sub    $0x258,%rax
je     1373 <SetPortSpeed+0x213>
jmp    1215 <SetPortSpeed+0xb5>
mov    -0x28(%rbp),%rax
sub    $0x4b0,%rax
je     1384 <SetPortSpeed+0x224>
jmp    122a <SetPortSpeed+0xca>
mov    -0x28(%rbp),%rax
sub    $0x708,%rax
je     1395 <SetPortSpeed+0x235>
jmp    123f <SetPortSpeed+0xdf>
mov    -0x28(%rbp),%rax
sub    $0x960,%rax
je     13a6 <SetPortSpeed+0x246>
jmp    1254 <SetPortSpeed+0xf4>
mov    -0x28(%rbp),%rax
sub    $0x12c0,%rax
je     13b7 <SetPortSpeed+0x257>
jmp    1269 <SetPortSpeed+0x109>
mov    -0x28(%rbp),%rax
sub    $0x2580,%rax
je     13c8 <SetPortSpeed+0x268>
jmp    127e <SetPortSpeed+0x11e>
mov    -0x28(%rbp),%rax
sub    $0x4b00,%rax
je     13d9 <SetPortSpeed+0x279>
jmp    1293 <SetPortSpeed+0x133>
mov    -0x28(%rbp),%rax
sub    $0x9600,%rax
je     13ea <SetPortSpeed+0x28a>
jmp    12a8 <SetPortSpeed+0x148>
mov    -0x28(%rbp),%rax
sub    $0xe100,%rax
je     13fb <SetPortSpeed+0x29b>
jmp    12bd <SetPortSpeed+0x15d>
mov    -0x28(%rbp),%rax
sub    $0x1c200,%rax
je     140c <SetPortSpeed+0x2ac>
jmp    12d2 <SetPortSpeed+0x172>
mov    -0x28(%rbp),%rax
sub    $0x38400,%rax
je     141d <SetPortSpeed+0x2bd>
jmp    12e7 <SetPortSpeed+0x187>
mov    -0x28(%rbp),%rax
sub    $0x70800,%rax
je     142e <SetPortSpeed+0x2ce>
jmp    143f <SetPortSpeed+0x2df>
mov    0x2c9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2c92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2c29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2c40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2c56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2bcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2be4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2bcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2c02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2c10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2b47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2b8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2b3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2b1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2b2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1460 <SetPortSpeed+0x300>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
lea    0xbb1(%rip),%rsi
call   1040 <LogMsg@plt>
mov    0x2b5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x1c(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x1c(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2ada(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
lea    -0x18(%rbp),%rdi
call   1080 <UnixLogPortSettings@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetPortSpeed>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
cmp    $0x707,%rsi
jle    11c1 <SetPortSpeed+0x61>
cmp    $0x95ff,%rsi
jg     120e <SetPortSpeed+0xae>
cmp    $0x12bf,%rsi
jle    1278 <SetPortSpeed+0x118>
cmp    $0x12c0,%rsi
je     12fa <SetPortSpeed+0x19a>
cmp    $0x2580,%rsi
je     1369 <SetPortSpeed+0x209>
cmp    $0x4b00,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2e34(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
cmp    $0x95,%rsi
jle    124e <SetPortSpeed+0xee>
cmp    $0x12b,%rsi
jle    129e <SetPortSpeed+0x13e>
cmp    $0x12c,%rsi
je     1303 <SetPortSpeed+0x1a3>
cmp    $0x258,%rsi
je     130c <SetPortSpeed+0x1ac>
cmp    $0x4b0,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2d4f(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
cmp    $0x1c1ff,%rsi
jle    12c4 <SetPortSpeed+0x164>
cmp    $0x1c200,%rsi
je     1315 <SetPortSpeed+0x1b5>
cmp    $0x38400,%rsi
je     131e <SetPortSpeed+0x1be>
cmp    $0x70800,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2d17(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
cmp    $0x6d,%rsi
jg     12e2 <SetPortSpeed+0x182>
cmp    $0x32,%rsi
je     1327 <SetPortSpeed+0x1c7>
cmp    $0x4b,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2d65(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
cmp    $0x708,%rsi
je     1330 <SetPortSpeed+0x1d0>
cmp    $0x960,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2cdf(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
cmp    $0x96,%rsi
je     1339 <SetPortSpeed+0x1d9>
cmp    $0xc8,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2cd9(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
cmp    $0x9600,%rsi
je     1342 <SetPortSpeed+0x1e2>
cmp    $0xe100,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2cb3(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
cmp    $0x6e,%rsi
je     134b <SetPortSpeed+0x1eb>
cmp    $0x86,%rsi
jne    1354 <SetPortSpeed+0x1f4>
mov    0x2cd0(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2cbf(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c9e(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2cbd(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c34(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c1b(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c72(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c49(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c30(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2bef(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c8e(%rip),%rax
jmp    1370 <SetPortSpeed+0x210>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
lea    0xc9c(%rip),%rsi
call   1040 <LogMsg@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%ebp
lea    0x8(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <tcgetattr@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    0x2bcb(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
mov    %rbx,%rdi
call   1080 <UnixLogPortSettings@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B134 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@B460800 = global i32 0
@LOG_WARNING = global i32 0
@.str = [46 x i8] c"Unknwon baud rate requested, setting to 9600.\00"
@TCSADRAIN = global i32 0
define void @SetPortSpeed(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca %struct.termios
%6 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
switch i64 %7, label %46 [
i64 50, label %8
i64 75, label %10
i64 110, label %12
i64 134, label %14
i64 150, label %16
i64 200, label %18
i64 300, label %20
i64 600, label %22
i64 1200, label %24
i64 1800, label %26
i64 2400, label %28
i64 4800, label %30
i64 9600, label %32
i64 19200, label %34
i64 38400, label %36
i64 57600, label %38
i64 115200, label %40
i64 230400, label %42
i64 460800, label %44
]
8: ; preds = %2
%9 = load i32, i32* @B50
store i32 %9, i32* %6
br label %50
10: ; preds = %2
%11 = load i32, i32* @B75
store i32 %11, i32* %6
br label %50
12: ; preds = %2
%13 = load i32, i32* @B110
store i32 %13, i32* %6
br label %50
14: ; preds = %2
%15 = load i32, i32* @B134
store i32 %15, i32* %6
br label %50
16: ; preds = %2
%17 = load i32, i32* @B150
store i32 %17, i32* %6
br label %50
18: ; preds = %2
%19 = load i32, i32* @B200
store i32 %19, i32* %6
br label %50
20: ; preds = %2
%21 = load i32, i32* @B300
store i32 %21, i32* %6
br label %50
22: ; preds = %2
%23 = load i32, i32* @B600
store i32 %23, i32* %6
br label %50
24: ; preds = %2
%25 = load i32, i32* @B1200
store i32 %25, i32* %6
br label %50
26: ; preds = %2
%27 = load i32, i32* @B1800
store i32 %27, i32* %6
br label %50
28: ; preds = %2
%29 = load i32, i32* @B2400
store i32 %29, i32* %6
br label %50
30: ; preds = %2
%31 = load i32, i32* @B4800
store i32 %31, i32* %6
br label %50
32: ; preds = %2
%33 = load i32, i32* @B9600
store i32 %33, i32* %6
br label %50
34: ; preds = %2
%35 = load i32, i32* @B19200
store i32 %35, i32* %6
br label %50
36: ; preds = %2
%37 = load i32, i32* @B38400
store i32 %37, i32* %6
br label %50
38: ; preds = %2
%39 = load i32, i32* @B57600
store i32 %39, i32* %6
br label %50
40: ; preds = %2
%41 = load i32, i32* @B115200
store i32 %41, i32* %6
br label %50
42: ; preds = %2
%43 = load i32, i32* @B230400
store i32 %43, i32* %6
br label %50
44: ; preds = %2
%45 = load i32, i32* @B460800
store i32 %45, i32* %6
br label %50
46: ; preds = %2
%47 = load i32, i32* @LOG_WARNING
%48 = call i32 @LogMsg(i32 %47, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%49 = load i32, i32* @B9600
store i32 %49, i32* %6
br label %50
50: ; preds = %46, %44, %42, %40, %38, %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10, %8
%51 = load i32, i32* %3
%52 = call i32 @tcgetattr(i32 %51, %struct.termios* %5)
%53 = load i32, i32* %6
%54 = call i32 @cfsetospeed(%struct.termios* %5, i32 %53)
%55 = load i32, i32* %6
%56 = call i32 @cfsetispeed(%struct.termios* %5, i32 %55)
%57 = load i32, i32* %3
%58 = load i32, i32* @TCSADRAIN
%59 = call i32 @tcsetattr(i32 %57, i32 %58, %struct.termios* %5)
%60 = call i32 @UnixLogPortSettings(%struct.termios* %5)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B134 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@B460800 = global i32 0
@LOG_WARNING = global i32 0
@.str = [46 x i8] c"Unknwon baud rate requested, setting to 9600.\00"
@TCSADRAIN = global i32 0
define void @SetPortSpeed(i32 %0, i64 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
switch i64 %1, label %23 [
i64 50, label %26
i64 75, label %5
i64 110, label %6
i64 134, label %7
i64 150, label %8
i64 200, label %9
i64 300, label %10
i64 600, label %11
i64 1200, label %12
i64 1800, label %13
i64 2400, label %14
i64 4800, label %15
i64 9600, label %16
i64 19200, label %17
i64 38400, label %18
i64 57600, label %19
i64 115200, label %20
i64 230400, label %21
i64 460800, label %22
]
5: ; preds = %2
br label %26
6: ; preds = %2
br label %26
7: ; preds = %2
br label %26
8: ; preds = %2
br label %26
9: ; preds = %2
br label %26
10: ; preds = %2
br label %26
11: ; preds = %2
br label %26
12: ; preds = %2
br label %26
13: ; preds = %2
br label %26
14: ; preds = %2
br label %26
15: ; preds = %2
br label %26
16: ; preds = %2
br label %26
17: ; preds = %2
br label %26
18: ; preds = %2
br label %26
19: ; preds = %2
br label %26
20: ; preds = %2
br label %26
21: ; preds = %2
br label %26
22: ; preds = %2
br label %26
23: ; preds = %2
%24 = load i32, i32* @LOG_WARNING
%25 = tail call i32 @LogMsg(i32 %24, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %2, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%27 = phi i32* [ @B9600, %23 ], [ @B460800, %22 ], [ @B230400, %21 ], [ @B115200, %20 ], [ @B57600, %19 ], [ @B38400, %18 ], [ @B19200, %17 ], [ @B9600, %16 ], [ @B4800, %15 ], [ @B2400, %14 ], [ @B1800, %13 ], [ @B1200, %12 ], [ @B600, %11 ], [ @B300, %10 ], [ @B200, %9 ], [ @B150, %8 ], [ @B134, %7 ], [ @B110, %6 ], [ @B75, %5 ], [ @B50, %2 ]
%28 = load i32, i32* %27
%29 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%30 = call i32 @cfsetospeed(%struct.termios* %3, i32 %28)
%31 = call i32 @cfsetispeed(%struct.termios* %3, i32 %28)
%32 = load i32, i32* @TCSADRAIN
%33 = call i32 @tcsetattr(i32 %0, i32 %32, %struct.termios* %3)
%34 = call i32 @UnixLogPortSettings(%struct.termios* %3)
ret void
}