#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 */
typedef int uint8_t;

/* Variables and functions */
int skytraq_write(int, int *, int);
int skytraq_setcomm(int fd, int baudrate) {
  uint8_t msg[11];
  int i;
  uint8_t cksum;
  int target_baudrate;
  switch (baudrate) {
  case 4800:
    target_baudrate = 0;
    break;
  case 9600:
    target_baudrate = 1;
    break;
  case 19200:
    target_baudrate = 2;
    break;
  case 38400:
    target_baudrate = 3;
    break;
  case 57600:
    target_baudrate = 4;
    break;
  case 115200:
    target_baudrate = 5;
    break;
  case 230400:
    target_baudrate = 6;
    break;
  }
  msg[0] = 0xa0;
  msg[1] = 0xa1;
  msg[2] = 0x00;
  msg[3] = 0x04;
  msg[4] = 0x05;
  msg[5] = 0x00;
  msg[6] = target_baudrate;
  msg[7] = 0x00;
  cksum = 0;
  for (i = 4; i < 8; i++)
    cksum ^= msg[i];
  msg[8] = cksum;
  msg[9] = 0x0d;
  msg[10] = 0x0a;
  return skytraq_write(fd, msg, 11);
}


x86 assembly (clang, -O0):
<skytraq_setcomm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x50(%rbp)
sub    $0x12c0,%eax
je     11a6 <skytraq_setcomm+0x96>
jmp    1134 <skytraq_setcomm+0x24>
mov    -0x50(%rbp),%eax
sub    $0x2580,%eax
je     11b2 <skytraq_setcomm+0xa2>
jmp    1147 <skytraq_setcomm+0x37>
mov    -0x50(%rbp),%eax
sub    $0x4b00,%eax
je     11be <skytraq_setcomm+0xae>
jmp    115a <skytraq_setcomm+0x4a>
mov    -0x50(%rbp),%eax
sub    $0x9600,%eax
je     11ca <skytraq_setcomm+0xba>
jmp    116d <skytraq_setcomm+0x5d>
mov    -0x50(%rbp),%eax
sub    $0xe100,%eax
je     11d6 <skytraq_setcomm+0xc6>
jmp    1180 <skytraq_setcomm+0x70>
mov    -0x50(%rbp),%eax
sub    $0x1c200,%eax
je     11e2 <skytraq_setcomm+0xd2>
jmp    1193 <skytraq_setcomm+0x83>
mov    -0x50(%rbp),%eax
sub    $0x38400,%eax
je     11ee <skytraq_setcomm+0xde>
jmp    11f5 <skytraq_setcomm+0xe5>
movl   $0x0,-0x4c(%rbp)
jmp    11f5 <skytraq_setcomm+0xe5>
movl   $0x1,-0x4c(%rbp)
jmp    11f5 <skytraq_setcomm+0xe5>
movl   $0x2,-0x4c(%rbp)
jmp    11f5 <skytraq_setcomm+0xe5>
movl   $0x3,-0x4c(%rbp)
jmp    11f5 <skytraq_setcomm+0xe5>
movl   $0x4,-0x4c(%rbp)
jmp    11f5 <skytraq_setcomm+0xe5>
movl   $0x5,-0x4c(%rbp)
jmp    11f5 <skytraq_setcomm+0xe5>
movl   $0x6,-0x4c(%rbp)
movl   $0xa0,-0x40(%rbp)
movl   $0xa1,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x4,-0x34(%rbp)
movl   $0x5,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x4,-0x44(%rbp)
cmpl   $0x8,-0x44(%rbp)
jge    1260 <skytraq_setcomm+0x150>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
xor    -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    123a <skytraq_setcomm+0x12a>
mov    -0x48(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0xd,-0x1c(%rbp)
movl   $0xa,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xb,%edx
call   1030 <skytraq_write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skytraq_setcomm>:
xor    %eax,%eax
cmp    $0xe0ff,%esi
jg     1139 <skytraq_setcomm+0x29>
cmp    $0x2580,%esi
je     1158 <skytraq_setcomm+0x48>
cmp    $0x4b00,%esi
je     115f <skytraq_setcomm+0x4f>
cmp    $0x9600,%esi
jne    1172 <skytraq_setcomm+0x62>
mov    $0x3,%eax
jmp    1172 <skytraq_setcomm+0x62>
cmp    $0xe100,%esi
je     1166 <skytraq_setcomm+0x56>
cmp    $0x1c200,%esi
je     116d <skytraq_setcomm+0x5d>
cmp    $0x38400,%esi
jne    1172 <skytraq_setcomm+0x62>
mov    $0x6,%eax
jmp    1172 <skytraq_setcomm+0x62>
mov    $0x1,%eax
jmp    1172 <skytraq_setcomm+0x62>
mov    $0x2,%eax
jmp    1172 <skytraq_setcomm+0x62>
mov    $0x4,%eax
jmp    1172 <skytraq_setcomm+0x62>
mov    $0x5,%eax
sub    $0x38,%rsp
movaps 0xe83(%rip),%xmm0
movaps %xmm0,(%rsp)
movq   $0x5,0x10(%rsp)
mov    %eax,0x18(%rsp)
movl   $0x0,0x1c(%rsp)
xor    $0x5,%eax
mov    %eax,0x20(%rsp)
movabs $0xa0000000d,%rax
mov    %rax,0x24(%rsp)
mov    %rsp,%rsi
mov    $0xb,%edx
call   1030 <skytraq_write@plt>
add    $0x38,%rsp
ret

LLVM IR (-O0):
define i32 @skytraq_setcomm(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [11 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
switch i32 %9, label %17 [
i32 4800, label %10
i32 9600, label %11
i32 19200, label %12
i32 38400, label %13
i32 57600, label %14
i32 115200, label %15
i32 230400, label %16
]
10: ; preds = %2
store i32 0, i32* %8
br label %17
11: ; preds = %2
store i32 1, i32* %8
br label %17
12: ; preds = %2
store i32 2, i32* %8
br label %17
13: ; preds = %2
store i32 3, i32* %8
br label %17
14: ; preds = %2
store i32 4, i32* %8
br label %17
15: ; preds = %2
store i32 5, i32* %8
br label %17
16: ; preds = %2
store i32 6, i32* %8
br label %17
17: ; preds = %2, %16, %15, %14, %13, %12, %11, %10
%18 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 0
store i32 160, i32* %18
%19 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 1
store i32 161, i32* %19
%20 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 2
store i32 0, i32* %20
%21 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 3
store i32 4, i32* %21
%22 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 4
store i32 5, i32* %22
%23 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 5
store i32 0, i32* %23
%24 = load i32, i32* %8
%25 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 6
store i32 %24, i32* %25
%26 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 7
store i32 0, i32* %26
store i32 0, i32* %7
store i32 4, i32* %6
br label %27
27: ; preds = %37, %17
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 8
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %7
%36 = xor i32 %35, %34
store i32 %36, i32* %7
br label %37
37: ; preds = %30
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %27
40: ; preds = %27
%41 = load i32, i32* %7
%42 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 8
store i32 %41, i32* %42
%43 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 9
store i32 13, i32* %43
%44 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 10
store i32 10, i32* %44
%45 = load i32, i32* %3
%46 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 0
%47 = call i32 @skytraq_write(i32 %45, i32* %46, i32 11)
ret i32 %47
}

LLVM IR (-O2):
define i32 @skytraq_setcomm(i32 %0, i32 %1) {
%3 = alloca [11 x i32]
%4 = bitcast [11 x i32]* %3 to i8*
switch i32 %1, label %11 [
i32 230400, label %10
i32 9600, label %5
i32 19200, label %6
i32 38400, label %7
i32 57600, label %8
i32 115200, label %9
]
5: ; preds = %2
br label %11
6: ; preds = %2
br label %11
7: ; preds = %2
br label %11
8: ; preds = %2
br label %11
9: ; preds = %2
br label %11
10: ; preds = %2
br label %11
11: ; preds = %2, %10, %9, %8, %7, %6, %5
%12 = phi i32 [ 6, %10 ], [ 5, %9 ], [ 4, %8 ], [ 3, %7 ], [ 2, %6 ], [ 1, %5 ], [ 0, %2 ]
%13 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 0
%14 = bitcast [11 x i32]* %3 to <4 x i32>*
store <4 x i32> <i32 160, i32 161, i32 0, i32 4>, <4 x i32>* %14
%15 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 4
store i32 5, i32* %15
%16 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 5
store i32 0, i32* %16
%17 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 6
store i32 %12, i32* %17
%18 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 7
store i32 0, i32* %18
%19 = xor i32 %12, 5
%20 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 8
store i32 %19, i32* %20
%21 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 9
store i32 13, i32* %21
%22 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 10
store i32 10, i32* %22
%23 = call i32 @skytraq_write(i32 %0, i32* %13, i32 11)
ret i32 %23
}