#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 c_cflag;
  int c_lflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
};

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B1200;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS7;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int /*<<< orphan*/ OPOST;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set(int fd, int baud, int timeout) {
  printf("Setting baud rate to %d\n", baud);
  struct termios options;
  tcgetattr(fd, &options);
  switch (baud) {
  case 0:
    cfsetispeed(&options, B1200);
    cfsetospeed(&options, B1200);
    break;
  case 1:
    cfsetispeed(&options, B2400);
    cfsetospeed(&options, B2400);
    break;
  case 4:
    cfsetispeed(&options, B4800);
    cfsetospeed(&options, B4800);
    break;
  case 5:
    cfsetispeed(&options, B9600);
    cfsetospeed(&options, B9600);
    break;
  case 6:
    cfsetispeed(&options, B19200);
    cfsetospeed(&options, B19200);
    break;
  case 7:
    cfsetispeed(&options, B38400);
    cfsetospeed(&options, B38400);
    break;
  case 8:
    cfsetispeed(&options, B115200);
    cfsetospeed(&options, B115200);
    break;
  }
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag |= PARENB;
  options.c_cflag &= ~PARODD;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS7;
  options.c_cflag |= CRTSCTS;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag &= ~OPOST;
  if (timeout == 1) {
    options.c_cc[VMIN] = 0;
    options.c_cc[VTIME] = 10;
  } else {
    options.c_cc[VMIN] = 1;
    options.c_cc[VTIME] = 0;
  }
  tcsetattr(fd, TCSANOW, &options);
  return 0;
}


x86 assembly (clang, -O0):
<set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeb9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x8,%rax
ja     12bb <set+0x16b>
mov    -0x30(%rbp),%rax
lea    0xe68(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    12bb <set+0x16b>
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    12bb <set+0x16b>
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    12bb <set+0x16b>
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    12bb <set+0x16b>
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    12bb <set+0x16b>
mov    0x2cb3(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    12bb <set+0x16b>
mov    0x2cca(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%eax
mov    0x2ccd(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c45(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c7b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c19(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c1a(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
mov    0x2c82(%rip),%rcx
or     (%rcx),%eax
mov    0x2c71(%rip),%rcx
or     (%rcx),%eax
mov    0x2c58(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2c76(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    13ae <set+0x25e>
mov    -0x20(%rbp),%rax
mov    0x2c06(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2bc1(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
jmp    13d8 <set+0x288>
mov    -0x20(%rbp),%rax
mov    0x2bd7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2b92(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2bee(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1050 <tcgetattr@plt>
cmp    $0x8,%ebp
ja     11ad <set+0x5d>
mov    $0x1f3,%eax
bt     %ebp,%eax
jae    11ad <set+0x5d>
movslq %ebp,%rax
lea    0x2bc8(%rip),%rcx
mov    (%rcx,%rax,8),%rbp
mov    0x0(%rbp),%esi
mov    %rsp,%r15
mov    %r15,%rdi
call   1070 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %r15,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dac(%rip),%rax
mov    0x2df5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2e17(%rip),%rax
or     (%rax),%ecx
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    0x2d95(%rip),%rdx
or     (%rdx),%eax
mov    0x2dbc(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2d77(%rip),%rcx
or     (%rcx),%eax
mov    0x2d7e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d85(%rip),%rcx
mov    0x2dc6(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2db3(%rip),%rcx
or     (%rcx),%edx
mov    %eax,(%rsp)
mov    0x2d97(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    $0x1,%r14d
setne  %cl
mov    0x8(%rsp),%rdx
mov    $0xa,%esi
cmovne %eax,%esi
mov    0x2d51(%rip),%rax
mov    (%rax),%rax
mov    %ecx,(%rdx,%rax,4)
mov    0x2d2c(%rip),%rax
mov    (%rax),%rax
mov    %esi,(%rdx,%rax,4)
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1060 <tcsetattr@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i32 }
@.str = [25 x i8] c"Setting baud rate to %d\0A\00"
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS7 = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define i32 @set(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %4
%11 = call i32 @tcgetattr(i32 %10, %struct.termios* %7)
%12 = load i32, i32* %5
switch i32 %12, label %48 [
i32 0, label %13
i32 1, label %18
i32 4, label %23
i32 5, label %28
i32 6, label %33
i32 7, label %38
i32 8, label %43
]
13: ; preds = %3
%14 = load i32, i32* @B1200
%15 = call i32 @cfsetispeed(%struct.termios* %7, i32 %14)
%16 = load i32, i32* @B1200
%17 = call i32 @cfsetospeed(%struct.termios* %7, i32 %16)
br label %48
18: ; preds = %3
%19 = load i32, i32* @B2400
%20 = call i32 @cfsetispeed(%struct.termios* %7, i32 %19)
%21 = load i32, i32* @B2400
%22 = call i32 @cfsetospeed(%struct.termios* %7, i32 %21)
br label %48
23: ; preds = %3
%24 = load i32, i32* @B4800
%25 = call i32 @cfsetispeed(%struct.termios* %7, i32 %24)
%26 = load i32, i32* @B4800
%27 = call i32 @cfsetospeed(%struct.termios* %7, i32 %26)
br label %48
28: ; preds = %3
%29 = load i32, i32* @B9600
%30 = call i32 @cfsetispeed(%struct.termios* %7, i32 %29)
%31 = load i32, i32* @B9600
%32 = call i32 @cfsetospeed(%struct.termios* %7, i32 %31)
br label %48
33: ; preds = %3
%34 = load i32, i32* @B19200
%35 = call i32 @cfsetispeed(%struct.termios* %7, i32 %34)
%36 = load i32, i32* @B19200
%37 = call i32 @cfsetospeed(%struct.termios* %7, i32 %36)
br label %48
38: ; preds = %3
%39 = load i32, i32* @B38400
%40 = call i32 @cfsetispeed(%struct.termios* %7, i32 %39)
%41 = load i32, i32* @B38400
%42 = call i32 @cfsetospeed(%struct.termios* %7, i32 %41)
br label %48
43: ; preds = %3
%44 = load i32, i32* @B115200
%45 = call i32 @cfsetispeed(%struct.termios* %7, i32 %44)
%46 = load i32, i32* @B115200
%47 = call i32 @cfsetospeed(%struct.termios* %7, i32 %46)
br label %48
48: ; preds = %3, %43, %38, %33, %28, %23, %18, %13
%49 = load i32, i32* @CLOCAL
%50 = load i32, i32* @CREAD
%51 = or i32 %49, %50
%52 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%53 = load i32, i32* %52
%54 = or i32 %53, %51
store i32 %54, i32* %52
%55 = load i32, i32* @PARENB
%56 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%57 = load i32, i32* %56
%58 = or i32 %57, %55
store i32 %58, i32* %56
%59 = load i32, i32* @PARODD
%60 = xor i32 %59, -1
%61 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%62 = load i32, i32* %61
%63 = and i32 %62, %60
store i32 %63, i32* %61
%64 = load i32, i32* @CSTOPB
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @CSIZE
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* @CS7
%75 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%76 = load i32, i32* %75
%77 = or i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* @CRTSCTS
%79 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%80 = load i32, i32* %79
%81 = or i32 %80, %78
store i32 %81, i32* %79
%82 = load i32, i32* @ICANON
%83 = load i32, i32* @ECHO
%84 = or i32 %82, %83
%85 = load i32, i32* @ECHOE
%86 = or i32 %84, %85
%87 = load i32, i32* @ISIG
%88 = or i32 %86, %87
%89 = xor i32 %88, -1
%90 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%91 = load i32, i32* %90
%92 = and i32 %91, %89
store i32 %92, i32* %90
%93 = load i32, i32* @OPOST
%94 = xor i32 %93, -1
%95 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%96 = load i32, i32* %95
%97 = and i32 %96, %94
store i32 %97, i32* %95
%98 = load i32, i32* %6
%99 = icmp eq i32 %98, 1
br i1 %99, label %100, label %109
100: ; preds = %48
%101 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%102 = load i32*, i32** %101
%103 = load i64, i64* @VMIN
%104 = getelementptr inbounds i32, i32* %102, i64 %103
store i32 0, i32* %104
%105 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%106 = load i32*, i32** %105
%107 = load i64, i64* @VTIME
%108 = getelementptr inbounds i32, i32* %106, i64 %107
store i32 10, i32* %108
br label %118
109: ; preds = %48
%110 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%111 = load i32*, i32** %110
%112 = load i64, i64* @VMIN
%113 = getelementptr inbounds i32, i32* %111, i64 %112
store i32 1, i32* %113
%114 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%115 = load i32*, i32** %114
%116 = load i64, i64* @VTIME
%117 = getelementptr inbounds i32, i32* %115, i64 %116
store i32 0, i32* %117
br label %118
118: ; preds = %109, %100
%119 = load i32, i32* %4
%120 = load i32, i32* @TCSANOW
%121 = call i32 @tcsetattr(i32 %119, i32 %120, %struct.termios* %7)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i32 }
@.str = [25 x i8] c"Setting baud rate to %d\0A\00"
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS7 = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@switch.table.set = [9 x i32*] [i32* @B1200, i32* @B2400, i32* @B1200, i32* @B1200, i32* @B4800, i32* @B9600, i32* @B19200, i32* @B38400, i32* @B115200]
define i32 @set(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.termios
%5 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = bitcast %struct.termios* %4 to i8*
%7 = call i32 @tcgetattr(i32 %0, %struct.termios* %4)
%8 = icmp ult i32 %1, 9
br i1 %8, label %9, label %22
9: ; preds = %3
%10 = trunc i32 %1 to i16
%11 = lshr i16 499, %10
%12 = and i16 %11, 1
%13 = icmp eq i16 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = sext i32 %1 to i64
%16 = getelementptr inbounds [9 x i32*], [9 x i32*]* @switch.table.set, i64 0, i64 %15
%17 = load i32*, i32** %16
%18 = load i32, i32* %17
%19 = call i32 @cfsetispeed(%struct.termios* %4, i32 %18)
%20 = load i32, i32* %17
%21 = call i32 @cfsetospeed(%struct.termios* %4, i32 %20)
br label %22
22: ; preds = %9, %3, %14
%23 = load i32, i32* @CLOCAL
%24 = load i32, i32* @CREAD
%25 = or i32 %24, %23
%26 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%27 = load i32, i32* %26
%28 = or i32 %25, %27
%29 = load i32, i32* @PARENB
%30 = or i32 %29, %28
%31 = load i32, i32* @PARODD
%32 = load i32, i32* @CSTOPB
%33 = or i32 %31, %32
%34 = load i32, i32* @CSIZE
%35 = or i32 %33, %34
%36 = xor i32 %35, -1
%37 = and i32 %30, %36
%38 = load i32, i32* @CS7
%39 = or i32 %38, %37
%40 = load i32, i32* @CRTSCTS
%41 = or i32 %40, %39
store i32 %41, i32* %26
%42 = load i32, i32* @ICANON
%43 = load i32, i32* @ECHO
%44 = or i32 %43, %42
%45 = load i32, i32* @ECHOE
%46 = or i32 %44, %45
%47 = load i32, i32* @ISIG
%48 = or i32 %46, %47
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @OPOST
%54 = xor i32 %53, -1
%55 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 3
%56 = load i32, i32* %55
%57 = and i32 %56, %54
store i32 %57, i32* %55
%58 = icmp eq i32 %2, 1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%60 = load i32*, i32** %59
%61 = xor i1 %58, true
%62 = zext i1 %61 to i32
%63 = select i1 %58, i32 10, i32 0
%64 = load i64, i64* @VMIN
%65 = getelementptr inbounds i32, i32* %60, i64 %64
store i32 %62, i32* %65
%66 = load i64, i64* @VTIME
%67 = getelementptr inbounds i32, i32* %60, i64 %66
store i32 %63, i32* %67
%68 = load i32, i32* @TCSANOW
%69 = call i32 @tcsetattr(i32 %0, i32 %68, %struct.termios* %4)
ret i32 0
}