#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*/ B2400;
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int /*<<< orphan*/ OPOST;
int PARENB;
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);
  if (baud == 0) {
    cfsetispeed(&options, B1200);
    cfsetospeed(&options, B1200);
  } else if (baud == 1) {
    cfsetispeed(&options, B2400);
    cfsetospeed(&options, B2400);
  } else if (baud == 4) {
    cfsetispeed(&options, B4800);
    cfsetospeed(&options, B4800);
  } else if (baud == 5) {
    cfsetispeed(&options, B9600);
    cfsetospeed(&options, B9600);
  } else if (baud == 6) {
    cfsetispeed(&options, B115200);
    cfsetospeed(&options, B115200);
  }
  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_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    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11af <set+0x5f>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    128a <set+0x13a>
cmpl   $0x1,-0x8(%rbp)
jne    11e2 <set+0x92>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1285 <set+0x135>
cmpl   $0x4,-0x8(%rbp)
jne    1215 <set+0xc5>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1280 <set+0x130>
cmpl   $0x5,-0x8(%rbp)
jne    1248 <set+0xf8>
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    127b <set+0x12b>
cmpl   $0x6,-0x8(%rbp)
jne    1276 <set+0x126>
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    127b <set+0x12b>
jmp    1280 <set+0x130>
jmp    1285 <set+0x135>
jmp    128a <set+0x13a>
mov    0x2caf(%rip),%rax
mov    (%rax),%eax
mov    0x2d0e(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c8d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c62(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c60(%rip),%rax
mov    (%rax),%eax
mov    0x2cc7(%rip),%rcx
or     (%rcx),%eax
mov    0x2cb6(%rip),%rcx
or     (%rcx),%eax
mov    0x2ca5(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1371 <set+0x221>
mov    -0x20(%rbp),%rax
mov    0x2c4b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c06(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
jmp    139b <set+0x24b>
mov    -0x20(%rbp),%rax
mov    0x2c1c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2bd7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2c33(%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    $0x6,%ebp
ja     11ad <set+0x5d>
mov    $0x73,%eax
bt     %ebp,%eax
jae    11ad <set+0x5d>
movslq %ebp,%rax
lea    0x2be0(%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    0x2db4(%rip),%rax
mov    0x2dfd(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    0x2d9e(%rip),%rdx
or     (%rdx),%eax
mov    0x2dc5(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2dc8(%rip),%rcx
or     (%rcx),%eax
mov    0x2d97(%rip),%rcx
mov    0x2dd8(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2d75(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2db8(%rip),%rax
or     (%rax),%edx
mov    %ecx,(%rsp)
mov    0x2da4(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2dbd(%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    0x2d56(%rip),%rax
mov    (%rax),%rax
mov    %ecx,(%rdx,%rax,4)
mov    0x2d31(%rip),%rax
mov    (%rax),%rax
mov    %esi,(%rdx,%rax,4)
mov    0x2d6c(%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
@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
@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
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @B1200
%16 = call i32 @cfsetispeed(%struct.termios* %7, i32 %15)
%17 = load i32, i32* @B1200
%18 = call i32 @cfsetospeed(%struct.termios* %7, i32 %17)
br label %55
19: ; preds = %3
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* @B2400
%24 = call i32 @cfsetispeed(%struct.termios* %7, i32 %23)
%25 = load i32, i32* @B2400
%26 = call i32 @cfsetospeed(%struct.termios* %7, i32 %25)
br label %54
27: ; preds = %19
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 4
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* @B4800
%32 = call i32 @cfsetispeed(%struct.termios* %7, i32 %31)
%33 = load i32, i32* @B4800
%34 = call i32 @cfsetospeed(%struct.termios* %7, i32 %33)
br label %53
35: ; preds = %27
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 5
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* @B9600
%40 = call i32 @cfsetispeed(%struct.termios* %7, i32 %39)
%41 = load i32, i32* @B9600
%42 = call i32 @cfsetospeed(%struct.termios* %7, i32 %41)
br label %52
43: ; preds = %35
%44 = load i32, i32* %5
%45 = icmp eq i32 %44, 6
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i32, i32* @B115200
%48 = call i32 @cfsetispeed(%struct.termios* %7, i32 %47)
%49 = load i32, i32* @B115200
%50 = call i32 @cfsetospeed(%struct.termios* %7, i32 %49)
br label %51
51: ; preds = %46, %43
br label %52
52: ; preds = %51, %38
br label %53
53: ; preds = %52, %30
br label %54
54: ; preds = %53, %22
br label %55
55: ; preds = %54, %14
%56 = load i32, i32* @CLOCAL
%57 = load i32, i32* @CREAD
%58 = or i32 %56, %57
%59 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%60 = load i32, i32* %59
%61 = or i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @PARENB
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @CSTOPB
%68 = xor i32 %67, -1
%69 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%70 = load i32, i32* %69
%71 = and i32 %70, %68
store i32 %71, i32* %69
%72 = load i32, i32* @CSIZE
%73 = xor i32 %72, -1
%74 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%75 = load i32, i32* %74
%76 = and i32 %75, %73
store i32 %76, i32* %74
%77 = load i32, i32* @CS8
%78 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%79 = load i32, i32* %78
%80 = or i32 %79, %77
store i32 %80, i32* %78
%81 = load i32, i32* @CRTSCTS
%82 = xor i32 %81, -1
%83 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%84 = load i32, i32* %83
%85 = and i32 %84, %82
store i32 %85, i32* %83
%86 = load i32, i32* @ICANON
%87 = load i32, i32* @ECHO
%88 = or i32 %86, %87
%89 = load i32, i32* @ECHOE
%90 = or i32 %88, %89
%91 = load i32, i32* @ISIG
%92 = or i32 %90, %91
%93 = xor i32 %92, -1
%94 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%95 = load i32, i32* %94
%96 = and i32 %95, %93
store i32 %96, i32* %94
%97 = load i32, i32* @OPOST
%98 = xor i32 %97, -1
%99 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%100 = load i32, i32* %99
%101 = and i32 %100, %98
store i32 %101, i32* %99
%102 = load i32, i32* %6
%103 = icmp eq i32 %102, 1
br i1 %103, label %104, label %113
104: ; preds = %55
%105 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%106 = load i32*, i32** %105
%107 = load i64, i64* @VMIN
%108 = getelementptr inbounds i32, i32* %106, i64 %107
store i32 0, i32* %108
%109 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%110 = load i32*, i32** %109
%111 = load i64, i64* @VTIME
%112 = getelementptr inbounds i32, i32* %110, i64 %111
store i32 10, i32* %112
br label %122
113: ; preds = %55
%114 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%115 = load i32*, i32** %114
%116 = load i64, i64* @VMIN
%117 = getelementptr inbounds i32, i32* %115, i64 %116
store i32 1, i32* %117
%118 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%119 = load i32*, i32** %118
%120 = load i64, i64* @VTIME
%121 = getelementptr inbounds i32, i32* %119, i64 %120
store i32 0, i32* %121
br label %122
122: ; preds = %113, %104
%123 = load i32, i32* %4
%124 = load i32, i32* @TCSANOW
%125 = call i32 @tcsetattr(i32 %123, i32 %124, %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
@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
@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 = [7 x i32*] [i32* @B1200, i32* @B2400, i32* @B1200, i32* @B1200, i32* @B4800, i32* @B9600, 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, 7
br i1 %8, label %9, label %22
9: ; preds = %3
%10 = trunc i32 %1 to i8
%11 = lshr i8 115, %10
%12 = and i8 %11, 1
%13 = icmp eq i8 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = sext i32 %1 to i64
%16 = getelementptr inbounds [7 x i32*], [7 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 = load i32, i32* @CSTOPB
%31 = or i32 %29, %30
%32 = load i32, i32* @CSIZE
%33 = or i32 %31, %32
%34 = xor i32 %33, -1
%35 = and i32 %28, %34
%36 = load i32, i32* @CS8
%37 = or i32 %36, %35
%38 = load i32, i32* @CRTSCTS
%39 = xor i32 %38, -1
%40 = and i32 %37, %39
store i32 %40, i32* %26
%41 = load i32, i32* @ICANON
%42 = load i32, i32* @ECHO
%43 = or i32 %42, %41
%44 = load i32, i32* @ECHOE
%45 = or i32 %43, %44
%46 = load i32, i32* @ISIG
%47 = or i32 %45, %46
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @OPOST
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 3
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = icmp eq i32 %2, 1
%58 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%59 = load i32*, i32** %58
%60 = xor i1 %57, true
%61 = zext i1 %60 to i32
%62 = select i1 %57, i32 10, i32 0
%63 = load i64, i64* @VMIN
%64 = getelementptr inbounds i32, i32* %59, i64 %63
store i32 %61, i32* %64
%65 = load i64, i64* @VTIME
%66 = getelementptr inbounds i32, i32* %59, i64 %65
store i32 %62, i32* %66
%67 = load i32, i32* @TCSANOW
%68 = call i32 @tcsetattr(i32 %0, i32 %67, %struct.termios* %4)
ret i32 0
}