#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*/ B1200;
int /*<<< orphan*/ B2400;
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);
  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);
  }
  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    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    1252 <set+0x102>
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    124d <set+0xfd>
cmpl   $0x4,-0x8(%rbp)
jne    1215 <set+0xc5>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1248 <set+0xf8>
cmpl   $0x5,-0x8(%rbp)
jne    1243 <set+0xf3>
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1248 <set+0xf8>
jmp    124d <set+0xfd>
jmp    1252 <set+0x102>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    0x2d3e(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c92(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c93(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
mov    0x2cf3(%rip),%rcx
or     (%rcx),%eax
mov    0x2ce2(%rip),%rcx
or     (%rcx),%eax
mov    0x2cc9(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1345 <set+0x1f5>
mov    -0x20(%rbp),%rax
mov    0x2c77(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c3a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
jmp    136f <set+0x21f>
mov    -0x20(%rbp),%rax
mov    0x2c48(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c0b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2c5f(%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    $0x5,%ebp
ja     11ad <set+0x5d>
mov    $0x33,%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    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
@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
%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 %46
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 %45
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 %44
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 %43
43: ; preds = %38, %35
br label %44
44: ; preds = %43, %30
br label %45
45: ; preds = %44, %22
br label %46
46: ; preds = %45, %14
%47 = load i32, i32* @CLOCAL
%48 = load i32, i32* @CREAD
%49 = or i32 %47, %48
%50 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%51 = load i32, i32* %50
%52 = or i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @PARENB
%54 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%55 = load i32, i32* %54
%56 = or i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @PARODD
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @CSTOPB
%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* @CSIZE
%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* @CS7
%73 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%74 = load i32, i32* %73
%75 = or i32 %74, %72
store i32 %75, i32* %73
%76 = load i32, i32* @CRTSCTS
%77 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%78 = load i32, i32* %77
%79 = or i32 %78, %76
store i32 %79, i32* %77
%80 = load i32, i32* @ICANON
%81 = load i32, i32* @ECHO
%82 = or i32 %80, %81
%83 = load i32, i32* @ECHOE
%84 = or i32 %82, %83
%85 = load i32, i32* @ISIG
%86 = or i32 %84, %85
%87 = xor i32 %86, -1
%88 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%89 = load i32, i32* %88
%90 = and i32 %89, %87
store i32 %90, i32* %88
%91 = load i32, i32* @OPOST
%92 = xor i32 %91, -1
%93 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%94 = load i32, i32* %93
%95 = and i32 %94, %92
store i32 %95, i32* %93
%96 = load i32, i32* %6
%97 = icmp eq i32 %96, 1
br i1 %97, label %98, label %107
98: ; preds = %46
%99 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%100 = load i32*, i32** %99
%101 = load i64, i64* @VMIN
%102 = getelementptr inbounds i32, i32* %100, i64 %101
store i32 0, i32* %102
%103 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%104 = load i32*, i32** %103
%105 = load i64, i64* @VTIME
%106 = getelementptr inbounds i32, i32* %104, i64 %105
store i32 10, i32* %106
br label %116
107: ; preds = %46
%108 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%109 = load i32*, i32** %108
%110 = load i64, i64* @VMIN
%111 = getelementptr inbounds i32, i32* %109, i64 %110
store i32 1, i32* %111
%112 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%113 = load i32*, i32** %112
%114 = load i64, i64* @VTIME
%115 = getelementptr inbounds i32, i32* %113, i64 %114
store i32 0, i32* %115
br label %116
116: ; preds = %107, %98
%117 = load i32, i32* %4
%118 = load i32, i32* @TCSANOW
%119 = call i32 @tcsetattr(i32 %117, i32 %118, %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
@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 = [6 x i32*] [i32* @B1200, i32* @B2400, i32* @B1200, i32* @B1200, i32* @B4800, i32* @B9600]
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, 6
br i1 %8, label %9, label %22
9: ; preds = %3
%10 = trunc i32 %1 to i8
%11 = lshr i8 51, %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 [6 x i32*], [6 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
}