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

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ FNDELAY;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int /*<<< orphan*/ TCSADRAIN;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int setBaud(int fd, unsigned int baudrate) {
  struct termios options;
  tcgetattr(fd, &options);
  if (baudrate == 9600) {
    cfsetispeed(&options, B9600);
    cfsetospeed(&options, B9600);
  } else if (baudrate == 57600) {
    cfsetispeed(&options, B57600);
    cfsetospeed(&options, B57600);
  } else if (baudrate == 115200) {
    cfsetispeed(&options, B115200);
    cfsetospeed(&options, B115200);
  } else {
    printf("I didn't bother setting the port speed.\n");
  }
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~CRTSCTS;
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag &= ~OPOST;
  tcsetattr(fd, TCSADRAIN, &options);
  fcntl(fd, F_SETFL, FNDELAY);
}


x86 assembly (clang, -O0):
<setBaud>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmpl   $0x2580,-0xc(%rbp)
jne    11b0 <setBaud+0x50>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1040 <cfsetospeed@plt>
jmp    1232 <setBaud+0xd2>
cmpl   $0xe100,-0xc(%rbp)
jne    11e6 <setBaud+0x86>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1040 <cfsetospeed@plt>
jmp    122d <setBaud+0xcd>
cmpl   $0x1c200,-0xc(%rbp)
jne    121c <setBaud+0xbc>
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1040 <cfsetospeed@plt>
jmp    1228 <setBaud+0xc8>
lea    0xddd(%rip),%rdi
call   1050 <printf@plt>
jmp    122d <setBaud+0xcd>
jmp    1232 <setBaud+0xd2>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    0x2d66(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    0x2d37(%rip),%rcx
or     (%rcx),%eax
mov    0x2cc6(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    0x2cf3(%rip),%rcx
or     (%rcx),%eax
mov    0x2ce2(%rip),%rcx
or     (%rcx),%eax
mov    0x2cd1(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x8(%rbp),%edi
mov    0x2c55(%rip),%rax
mov    (%rax),%esi
mov    0x2c3c(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setBaud>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1060 <tcgetattr@plt>
cmp    $0x1c200,%ebp
je     1195 <setBaud+0x35>
cmp    $0xe100,%ebp
je     119e <setBaud+0x3e>
cmp    $0x2580,%ebp
jne    11c0 <setBaud+0x60>
mov    0x2e1d(%rip),%r14
jmp    11a5 <setBaud+0x45>
mov    0x2dc4(%rip),%r14
jmp    11a5 <setBaud+0x45>
mov    0x2deb(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1080 <cfsetispeed@plt>
mov    (%r14),%esi
mov    %rbp,%rdi
call   1050 <cfsetospeed@plt>
jmp    11cc <setBaud+0x6c>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d65(%rip),%rax
mov    0x2dce(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    0x2d4f(%rip),%rdx
or     (%rdx),%eax
mov    0x2d9e(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2d99(%rip),%rcx
or     (%rcx),%eax
mov    0x2d38(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x2db8(%rip),%rax
mov    0x2dc1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d4e(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d17(%rip),%rax
mov    0x2d80(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d6d(%rip),%rax
or     (%rax),%ecx
mov    0x2d5c(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1070 <tcsetattr@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
mov    0x2cd2(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1040 <fcntl@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@B9600 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@.str = [41 x i8] c"I didn't bother setting the port speed.\0A\00"
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@TCSADRAIN = global i32 0
@F_SETFL = global i32 0
@FNDELAY = global i32 0
define i32 @setBaud(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %6)
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 9600
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @B9600
%13 = call i32 @cfsetispeed(%struct.termios* %6, i32 %12)
%14 = load i32, i32* @B9600
%15 = call i32 @cfsetospeed(%struct.termios* %6, i32 %14)
br label %36
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 57600
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @B57600
%21 = call i32 @cfsetispeed(%struct.termios* %6, i32 %20)
%22 = load i32, i32* @B57600
%23 = call i32 @cfsetospeed(%struct.termios* %6, i32 %22)
br label %35
24: ; preds = %16
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 115200
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* @B115200
%29 = call i32 @cfsetispeed(%struct.termios* %6, i32 %28)
%30 = load i32, i32* @B115200
%31 = call i32 @cfsetospeed(%struct.termios* %6, i32 %30)
br label %34
32: ; preds = %24
%33 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
br label %35
35: ; preds = %34, %19
br label %36
36: ; preds = %35, %11
%37 = load i32, i32* @CLOCAL
%38 = load i32, i32* @CREAD
%39 = or i32 %37, %38
%40 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%41 = load i32, i32* %40
%42 = or i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @PARENB
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @CSTOPB
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @CSIZE
%54 = xor i32 %53, -1
%55 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%56 = load i32, i32* %55
%57 = and i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* @CS8
%59 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%60 = load i32, i32* %59
%61 = or i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @CRTSCTS
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @IXON
%68 = load i32, i32* @IXOFF
%69 = or i32 %67, %68
%70 = load i32, i32* @IXANY
%71 = or i32 %69, %70
%72 = xor i32 %71, -1
%73 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%74 = load i32, i32* %73
%75 = and i32 %74, %72
store i32 %75, i32* %73
%76 = load i32, i32* @ICANON
%77 = load i32, i32* @ECHO
%78 = or i32 %76, %77
%79 = load i32, i32* @ECHOE
%80 = or i32 %78, %79
%81 = load i32, i32* @ISIG
%82 = or i32 %80, %81
%83 = xor i32 %82, -1
%84 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%85 = load i32, i32* %84
%86 = and i32 %85, %83
store i32 %86, i32* %84
%87 = load i32, i32* @OPOST
%88 = xor i32 %87, -1
%89 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%90 = load i32, i32* %89
%91 = and i32 %90, %88
store i32 %91, i32* %89
%92 = load i32, i32* %4
%93 = load i32, i32* @TCSADRAIN
%94 = call i32 @tcsetattr(i32 %92, i32 %93, %struct.termios* %6)
%95 = load i32, i32* %4
%96 = load i32, i32* @F_SETFL
%97 = load i32, i32* @FNDELAY
%98 = call i32 @fcntl(i32 %95, i32 %96, i32 %97)
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@B9600 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@TCSADRAIN = global i32 0
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@str = [40 x i8] c"I didn't bother setting the port speed.\00"
define i32 @setBaud(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
switch i32 %1, label %21 [
i32 9600, label %6
i32 57600, label %11
i32 115200, label %16
]
6: ; preds = %2
%7 = load i32, i32* @B9600
%8 = call i32 @cfsetispeed(%struct.termios* %3, i32 %7)
%9 = load i32, i32* @B9600
%10 = call i32 @cfsetospeed(%struct.termios* %3, i32 %9)
br label %23
11: ; preds = %2
%12 = load i32, i32* @B57600
%13 = call i32 @cfsetispeed(%struct.termios* %3, i32 %12)
%14 = load i32, i32* @B57600
%15 = call i32 @cfsetospeed(%struct.termios* %3, i32 %14)
br label %23
16: ; preds = %2
%17 = load i32, i32* @B115200
%18 = call i32 @cfsetispeed(%struct.termios* %3, i32 %17)
%19 = load i32, i32* @B115200
%20 = call i32 @cfsetospeed(%struct.termios* %3, i32 %19)
br label %23
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %11, %21, %16, %6
%24 = load i32, i32* @CLOCAL
%25 = load i32, i32* @CREAD
%26 = or i32 %25, %24
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%28 = load i32, i32* %27
%29 = or i32 %26, %28
%30 = load i32, i32* @PARENB
%31 = load i32, i32* @CSTOPB
%32 = or i32 %30, %31
%33 = load i32, i32* @CSIZE
%34 = or i32 %32, %33
%35 = xor i32 %34, -1
%36 = and i32 %29, %35
%37 = load i32, i32* @CS8
%38 = or i32 %37, %36
%39 = load i32, i32* @CRTSCTS
%40 = xor i32 %39, -1
%41 = and i32 %38, %40
store i32 %41, i32* %27
%42 = load i32, i32* @IXON
%43 = load i32, i32* @IXOFF
%44 = or i32 %43, %42
%45 = load i32, i32* @IXANY
%46 = or i32 %44, %45
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @ICANON
%52 = load i32, i32* @ECHO
%53 = or i32 %52, %51
%54 = load i32, i32* @ECHOE
%55 = or i32 %53, %54
%56 = load i32, i32* @ISIG
%57 = or i32 %55, %56
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @OPOST
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @TCSADRAIN
%68 = call i32 @tcsetattr(i32 %0, i32 %67, %struct.termios* %3)
%69 = load i32, i32* @F_SETFL
%70 = load i32, i32* @FNDELAY
%71 = call i32 @fcntl(i32 %0, i32 %69, i32 %70)
ret i32 undef
}