#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;
};

/* Variables and functions */
int B115200;
int B1200;
int B19200;
int B2400;
int B300;
int B38400;
int B4800;
int B57600;
int B9600;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int tty_setbaud(int fd, int baud) {
  struct termios options;
  int speed;
  switch (baud) {
  case 300:
    speed = B300;
    break;
  case 1200:
    speed = B1200;
    break;
  case 2400:
    speed = B2400;
    break;
  case 4800:
    speed = B4800;
    break;
  case 9600:
    speed = B9600;
    break;
  case 19200:
    speed = B19200;
    break;
  case 38400:
    speed = B38400;
    break;
  case 57600:
    speed = B57600;
    break;
  case 115200:
    speed = B115200;
    break;
  default:
    do {
    } while (0);
    return (0);
  }
  if (tcgetattr(fd, &options) == -1) {
    do {
    } while (0);
    do {
    } while (0);
    return (0);
  }
  (void)cfsetispeed(&options, speed);
  (void)cfsetospeed(&options, speed);
  if (tcsetattr(fd, TCSAFLUSH, &options) == -1) {
    do {
    } while (0);
    do {
    } while (0);
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<tty_setbaud>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x12c,%eax
je     11fc <tty_setbaud+0xbc>
jmp    1164 <tty_setbaud+0x24>
mov    -0x18(%rbp),%eax
sub    $0x4b0,%eax
je     120d <tty_setbaud+0xcd>
jmp    1177 <tty_setbaud+0x37>
mov    -0x18(%rbp),%eax
sub    $0x960,%eax
je     121e <tty_setbaud+0xde>
jmp    118a <tty_setbaud+0x4a>
mov    -0x18(%rbp),%eax
sub    $0x12c0,%eax
je     122f <tty_setbaud+0xef>
jmp    119d <tty_setbaud+0x5d>
mov    -0x18(%rbp),%eax
sub    $0x2580,%eax
je     1240 <tty_setbaud+0x100>
jmp    11b0 <tty_setbaud+0x70>
mov    -0x18(%rbp),%eax
sub    $0x4b00,%eax
je     1251 <tty_setbaud+0x111>
jmp    11c3 <tty_setbaud+0x83>
mov    -0x18(%rbp),%eax
sub    $0x9600,%eax
je     1262 <tty_setbaud+0x122>
jmp    11d6 <tty_setbaud+0x96>
mov    -0x18(%rbp),%eax
sub    $0xe100,%eax
je     1273 <tty_setbaud+0x133>
jmp    11e9 <tty_setbaud+0xa9>
mov    -0x18(%rbp),%eax
sub    $0x1c200,%eax
je     1284 <tty_setbaud+0x144>
jmp    1295 <tty_setbaud+0x155>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12ab <tty_setbaud+0x16b>
jmp    129a <tty_setbaud+0x15a>
jmp    129f <tty_setbaud+0x15f>
movl   $0x0,-0x4(%rbp)
jmp    133d <tty_setbaud+0x1fd>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    12e0 <tty_setbaud+0x1a0>
jmp    12c5 <tty_setbaud+0x185>
jmp    12ca <tty_setbaud+0x18a>
jmp    12cf <tty_setbaud+0x18f>
jmp    12d4 <tty_setbaud+0x194>
movl   $0x0,-0x4(%rbp)
jmp    133d <tty_setbaud+0x1fd>
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x8(%rbp),%edi
mov    0x2cde(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1336 <tty_setbaud+0x1f6>
jmp    131b <tty_setbaud+0x1db>
jmp    1320 <tty_setbaud+0x1e0>
jmp    1325 <tty_setbaud+0x1e5>
jmp    132a <tty_setbaud+0x1ea>
movl   $0x0,-0x4(%rbp)
jmp    133d <tty_setbaud+0x1fd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_setbaud>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
xor    %ebx,%ebx
cmp    $0x257f,%esi
jle    1185 <tty_setbaud+0x45>
cmp    $0x95ff,%esi
jle    11aa <tty_setbaud+0x6a>
cmp    $0x9600,%esi
je     11e0 <tty_setbaud+0xa0>
cmp    $0xe100,%esi
je     11e9 <tty_setbaud+0xa9>
cmp    $0x1c200,%esi
jne    1254 <tty_setbaud+0x114>
mov    0x2e20(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
cmp    $0x95f,%esi
jg     11c7 <tty_setbaud+0x87>
cmp    $0x12c,%esi
je     11f2 <tty_setbaud+0xb2>
cmp    $0x4b0,%esi
jne    1254 <tty_setbaud+0x114>
mov    0x2e00(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
cmp    $0x2580,%esi
je     11fb <tty_setbaud+0xbb>
cmp    $0x4b00,%esi
jne    1254 <tty_setbaud+0x114>
mov    0x2e2b(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
cmp    $0x960,%esi
je     1204 <tty_setbaud+0xc4>
cmp    $0x12c0,%esi
jne    1254 <tty_setbaud+0x114>
mov    0x2dfa(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
mov    0x2da9(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
mov    0x2dd0(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
mov    0x2dcf(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
mov    0x2dce(%rip),%rax
jmp    120b <tty_setbaud+0xcb>
mov    0x2da5(%rip),%rax
mov    (%rax),%ebp
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     1254 <tty_setbaud+0x114>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <cfsetispeed@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
setne  %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@B300 = global i32 0
@B1200 = 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
@TCSAFLUSH = global i32 0
define i32 @tty_setbaud(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
switch i32 %8, label %27 [
i32 300, label %9
i32 1200, label %11
i32 2400, label %13
i32 4800, label %15
i32 9600, label %17
i32 19200, label %19
i32 38400, label %21
i32 57600, label %23
i32 115200, label %25
]
9: ; preds = %2
%10 = load i32, i32* @B300
store i32 %10, i32* %7
br label %30
11: ; preds = %2
%12 = load i32, i32* @B1200
store i32 %12, i32* %7
br label %30
13: ; preds = %2
%14 = load i32, i32* @B2400
store i32 %14, i32* %7
br label %30
15: ; preds = %2
%16 = load i32, i32* @B4800
store i32 %16, i32* %7
br label %30
17: ; preds = %2
%18 = load i32, i32* @B9600
store i32 %18, i32* %7
br label %30
19: ; preds = %2
%20 = load i32, i32* @B19200
store i32 %20, i32* %7
br label %30
21: ; preds = %2
%22 = load i32, i32* @B38400
store i32 %22, i32* %7
br label %30
23: ; preds = %2
%24 = load i32, i32* @B57600
store i32 %24, i32* %7
br label %30
25: ; preds = %2
%26 = load i32, i32* @B115200
store i32 %26, i32* %7
br label %30
27: ; preds = %2
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
store i32 0, i32* %3
br label %54
30: ; preds = %25, %23, %21, %19, %17, %15, %13, %11, %9
%31 = load i32, i32* %4
%32 = call i32 @tcgetattr(i32 %31, %struct.termios* %6)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %30
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
store i32 0, i32* %3
br label %54
39: ; preds = %30
%40 = load i32, i32* %7
%41 = call i32 @cfsetispeed(%struct.termios* %6, i32 %40)
%42 = load i32, i32* %7
%43 = call i32 @cfsetospeed(%struct.termios* %6, i32 %42)
%44 = load i32, i32* %4
%45 = load i32, i32* @TCSAFLUSH
%46 = call i32 @tcsetattr(i32 %44, i32 %45, %struct.termios* %6)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %53
48: ; preds = %39
br label %49
49: ; preds = %48
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51
store i32 0, i32* %3
br label %54
53: ; preds = %39
store i32 1, i32* %3
br label %54
54: ; preds = %53, %52, %38, %29
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@B300 = global i32 0
@B1200 = 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
@TCSAFLUSH = global i32 0
define i32 @tty_setbaud(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
switch i32 %1, label %25 [
i32 300, label %13
i32 1200, label %5
i32 2400, label %6
i32 4800, label %7
i32 9600, label %8
i32 19200, label %9
i32 38400, label %10
i32 57600, label %11
i32 115200, label %12
]
5: ; preds = %2
br label %13
6: ; preds = %2
br label %13
7: ; preds = %2
br label %13
8: ; preds = %2
br label %13
9: ; preds = %2
br label %13
10: ; preds = %2
br label %13
11: ; preds = %2
br label %13
12: ; preds = %2
br label %13
13: ; preds = %2, %12, %11, %10, %9, %8, %7, %6, %5
%14 = phi i32* [ @B115200, %12 ], [ @B57600, %11 ], [ @B38400, %10 ], [ @B19200, %9 ], [ @B9600, %8 ], [ @B4800, %7 ], [ @B2400, %6 ], [ @B1200, %5 ], [ @B300, %2 ]
%15 = load i32, i32* %14
%16 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %25, label %18
18: ; preds = %13
%19 = call i32 @cfsetispeed(%struct.termios* %3, i32 %15)
%20 = call i32 @cfsetospeed(%struct.termios* %3, i32 %15)
%21 = load i32, i32* @TCSAFLUSH
%22 = call i32 @tcsetattr(i32 %0, i32 %21, %struct.termios* %3)
%23 = icmp ne i32 %22, -1
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %18, %13, %2
%26 = phi i32 [ 0, %2 ], [ 0, %13 ], [ %24, %18 ]
ret i32 %26
}