#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;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_packet(int, int, int, int *, int);
int read_console(FILE *source, int fd) {
  char buf[256];
  static uint8_t data, rec = 0;
  static int cmd = 0x0100;
  static int port = 0x08;
  fgets(buf, sizeof(buf), source);
  switch (buf[0]) {
  case '\n':
    printf("** Requesting 0x%02x00 at port 0x%02x\n", cmd, port);
    data = 0;
    if (send_packet(fd, port, cmd, &data, 1) < 0)
      return -1;
    cmd++;
    break;
  case '8':
    port = 0x08;
    cmd = 0x01;
    break;
  case 'A':
    port = 0x0a;
    cmd = 0x01;
    break;
  case 'B':
    port = 0x0b;
    cmd = 0x01;
    break;
  case 'C':
    printf("** Calibrating compass (0x9001)\n");
    data = 0x01;
    if (send_packet(fd, 0x0a, 0x90, &data, 1) < 0)
      return -1;
    break;
  case 'c':
    printf("** Taking picture\n");
    data = 0x01;
    if (send_packet(fd, 0x08, 0x01, &data, 1) < 0)
      return -1;
    break;
  case 'b':
    printf("** Sending command 0x1b00\n");
    data = 0x00;
    if (send_packet(fd, 0x0a, 0x1b, &data, 1) < 0)
      return -1;
    break;
  case 'd':
    printf("** Sending command 0x2d00\n");
    data = 0x00;
    if (send_packet(fd, 0x0a, 0x2d, &data, 1) < 0)
      return -1;
    break;
  case 'r':
    rec ^= 1;
    printf("** %s recording\n", rec ? "Starting" : "Stopping");
    if (send_packet(fd, 0x08, 0x02, &rec, 1) < 0)
      return -1;
    break;
  case '5':
    printf("** Sending command 0x2500\n");
    data = 0x00;
    if (send_packet(fd, 0x0b, 0x25, &data, 1) < 0)
      return -1;
    break;
  case '0':
    printf("*** Sending command 0x4000\n");
    data = 0x00;
    if (send_packet(fd, 0x08, 0x40, &data, 1) < 0)
      return -1;
    break;
  case '4':
    printf("*** Sending command 0x4400\n");
    data = 0x00;
    if (send_packet(fd, 0x08, 0x44, &data, 1) < 0)
      return -1;
    break;
  case 'p':
    printf("*** Sending command 0x32 (current position)\n");
    data = 0x00;
    if (send_packet(fd, 0x08, 0x32, &data, 1) < 0)
      return -1;
    break;
  case 'g':
    printf("*** Sending command 0x4900 (GPS telemetry)\n");
    data = 0x00;
    if (send_packet(fd, 0x0a, 0x49, &data, 1) < 0)
      return -1;
    break;
  case 'f':
    printf("*** Sending command 0x5200 (flight mode)\n");
    data = 0x00;
    if (send_packet(fd, 0x0a, 0x52, &data, 1) < 0)
      return -1;
    break;
  case '3':
    printf("*** Sending command 0x5300\n");
    data = 0x00;
    if (send_packet(fd, 0x0a, 0x53, &data, 1) < 0)
      return -1;
    break;
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
movsbl -0x120(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x128(%rbp)
sub    $0x68,%eax
ja     162d <read_console+0x4fd>
mov    -0x128(%rbp),%rax
lea    0xe7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2ea8(%rip),%esi
mov    0x2ea6(%rip),%edx
lea    0x1007(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2e96(%rip)
mov    -0x14(%rbp),%edi
mov    0x2e85(%rip),%esi
mov    0x2e7b(%rip),%edx
lea    0x2e80(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    11e4 <read_console+0xb4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
mov    0x2e4e(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e45(%rip)
jmp    1632 <read_console+0x502>
movl   $0x8,0x2e3a(%rip)
movl   $0x1,0x2e2c(%rip)
jmp    1632 <read_console+0x502>
movl   $0xa,0x2e21(%rip)
movl   $0x1,0x2e13(%rip)
jmp    1632 <read_console+0x502>
movl   $0xb,0x2e08(%rip)
movl   $0x1,0x2dfa(%rip)
jmp    1632 <read_console+0x502>
lea    0xf81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,0x2de9(%rip)
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x90,%edx
lea    0x2dd5(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    128f <read_console+0x15f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xf51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,0x2d98(%rip)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x1,%r8d
lea    0x2d83(%rip),%rcx
mov    %r8d,%edx
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    12de <read_console+0x1ae>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xf15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2d49(%rip)
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x1b,%edx
lea    0x2d35(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    132f <read_console+0x1ff>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2cf8(%rip)
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x2d,%edx
lea    0x2ce4(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    1380 <read_console+0x250>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
mov    0x2cbd(%rip),%eax
xor    $0x1,%eax
mov    %eax,0x2cb4(%rip)
mov    0x2cae(%rip),%ecx
lea    0xeae(%rip),%rsi
lea    0xe9e(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x2,%edx
lea    0x2c77(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    13f1 <read_console+0x2c1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2c36(%rip)
mov    -0x14(%rbp),%edi
mov    $0xb,%esi
mov    $0x25,%edx
lea    0x2c22(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    1442 <read_console+0x312>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2be5(%rip)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x40,%edx
lea    0x2bd1(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    1493 <read_console+0x363>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2b94(%rip)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x44,%edx
lea    0x2b80(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    14e4 <read_console+0x3b4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2b43(%rip)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x32,%edx
lea    0x2b2f(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    1535 <read_console+0x405>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2af2(%rip)
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x49,%edx
lea    0x2ade(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    1586 <read_console+0x456>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2aa1(%rip)
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x52,%edx
lea    0x2a8d(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    15d7 <read_console+0x4a7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2a50(%rip)
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x53,%edx
lea    0x2a3c(%rip),%rcx
mov    $0x1,%r8d
call   1050 <send_packet@plt>
cmp    $0x0,%eax
jge    1628 <read_console+0x4f8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1639 <read_console+0x509>
jmp    1632 <read_console+0x502>
jmp    1632 <read_console+0x502>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_console>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %esi,%ebx
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
movsbl (%rsp),%eax
add    $0xfffffff6,%eax
cmp    $0x68,%eax
ja     1448 <read_console+0x308>
lea    0xe8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2ebe(%rip),%esi
mov    0x2ebc(%rip),%edx
lea    0x1015(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0x2eac(%rip)
lea    0x2ea5(%rip),%rcx
mov    0x2e97(%rip),%esi
mov    0x2e8d(%rip),%edx
mov    %ebx,%edi
mov    $0x1,%r8d
call   1060 <send_packet@plt>
test   %eax,%eax
js     144c <read_console+0x30c>
mov    0x2e72(%rip),%eax
add    $0x1,%eax
jmp    12b5 <read_console+0x175>
lea    0x10c7(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2e60(%rip)
lea    0x2e59(%rip),%rcx
mov    %ebx,%edi
mov    $0x8,%esi
mov    $0x40,%edx
jmp    1439 <read_console+0x2f9>
lea    0xfe3(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2e32(%rip)
lea    0x2e2b(%rip),%rcx
mov    %ebx,%edi
mov    $0xa,%esi
mov    $0x53,%edx
jmp    1439 <read_console+0x2f9>
lea    0x1050(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2e04(%rip)
lea    0x2dfd(%rip),%rcx
mov    %ebx,%edi
mov    $0x8,%esi
mov    $0x44,%edx
jmp    1439 <read_console+0x2f9>
lea    0x1058(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2dd6(%rip)
lea    0x2dcf(%rip),%rcx
mov    %ebx,%edi
mov    $0xb,%esi
mov    $0x25,%edx
jmp    1439 <read_console+0x2f9>
movl   $0x8,0x2dac(%rip)
jmp    12b0 <read_console+0x170>
movl   $0xa,0x2da0(%rip)
jmp    12b0 <read_console+0x170>
movl   $0xb,0x2d94(%rip)
mov    $0x1,%eax
mov    %eax,0x2d85(%rip)
jmp    1448 <read_console+0x308>
lea    0x1058(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,0x2d76(%rip)
lea    0x2d6f(%rip),%rcx
mov    %ebx,%edi
mov    $0xa,%esi
mov    $0x90,%edx
jmp    1439 <read_console+0x2f9>
lea    0xffe(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2d48(%rip)
lea    0x2d41(%rip),%rcx
mov    %ebx,%edi
mov    $0xa,%esi
mov    $0x1b,%edx
jmp    1439 <read_console+0x2f9>
lea    0xfea(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,0x2d1a(%rip)
lea    0x2d13(%rip),%rcx
mov    %ebx,%edi
mov    $0x8,%esi
mov    $0x1,%edx
jmp    1439 <read_console+0x2f9>
lea    0xf88(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2cec(%rip)
lea    0x2ce5(%rip),%rcx
mov    %ebx,%edi
mov    $0xa,%esi
mov    $0x2d,%edx
jmp    1439 <read_console+0x2f9>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2cbe(%rip)
lea    0x2cb7(%rip),%rcx
mov    %ebx,%edi
mov    $0xa,%esi
mov    $0x52,%edx
jmp    1439 <read_console+0x2f9>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2c90(%rip)
lea    0x2c89(%rip),%rcx
mov    %ebx,%edi
mov    $0xa,%esi
mov    $0x49,%edx
jmp    1439 <read_console+0x2f9>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x2c65(%rip)
lea    0x2c5e(%rip),%rcx
mov    %ebx,%edi
mov    $0x8,%esi
mov    $0x32,%edx
jmp    1439 <read_console+0x2f9>
lea    0x2c4d(%rip),%r14
xorl   $0x1,0x2c46(%rip)
lea    0xdd4(%rip),%rax
lea    0xdc4(%rip),%rsi
cmove  %rax,%rsi
lea    0xda8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
mov    $0x8,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
call   1060 <send_packet@plt>
test   %eax,%eax
js     144c <read_console+0x30c>
xor    %eax,%eax
jmp    1451 <read_console+0x311>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@read_console.data = internal global i32 0
@read_console.rec = internal global i32 0
@read_console.cmd = internal global i32 256
@read_console.port = internal global i32 8
@.str = [39 x i8] c"** Requesting 0x%02x00 at port 0x%02x\0A\00"
@.str.1 = [33 x i8] c"** Calibrating compass (0x9001)\0A\00"
@.str.2 = [19 x i8] c"** Taking picture\0A\00"
@.str.3 = [27 x i8] c"** Sending command 0x1b00\0A\00"
@.str.4 = [27 x i8] c"** Sending command 0x2d00\0A\00"
@.str.5 = [17 x i8] c"** %s recording\0A\00"
@.str.6 = [9 x i8] c"Starting\00"
@.str.7 = [9 x i8] c"Stopping\00"
@.str.8 = [27 x i8] c"** Sending command 0x2500\0A\00"
@.str.9 = [28 x i8] c"*** Sending command 0x4000\0A\00"
@.str.10 = [28 x i8] c"*** Sending command 0x4400\0A\00"
@.str.11 = [45 x i8] c"*** Sending command 0x32 (current position)\0A\00"
@.str.12 = [44 x i8] c"*** Sending command 0x4900 (GPS telemetry)\0A\00"
@.str.13 = [42 x i8] c"*** Sending command 0x5200 (flight mode)\0A\00"
@.str.14 = [28 x i8] c"*** Sending command 0x5300\0A\00"
define i32 @read_console(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [256 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = load i32*, i32** %4
%9 = call i32 @fgets(i8* %7, i32 256, i32* %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %119 [
i32 10, label %13
i32 56, label %26
i32 65, label %27
i32 66, label %28
i32 67, label %29
i32 99, label %36
i32 98, label %43
i32 100, label %50
i32 114, label %57
i32 53, label %70
i32 48, label %77
i32 52, label %84
i32 112, label %91
i32 103, label %98
i32 102, label %105
i32 51, label %112
]
13: ; preds = %2
%14 = load i32, i32* @read_console.cmd
%15 = load i32, i32* @read_console.port
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
store i32 0, i32* @read_console.data
%17 = load i32, i32* %5
%18 = load i32, i32* @read_console.port
%19 = load i32, i32* @read_console.cmd
%20 = call i32 @send_packet(i32 %17, i32 %18, i32 %19, i32* @read_console.data, i32 1)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 -1, i32* %3
br label %121
23: ; preds = %13
%24 = load i32, i32* @read_console.cmd
%25 = add nsw i32 %24, 1
store i32 %25, i32* @read_console.cmd
br label %120
26: ; preds = %2
store i32 8, i32* @read_console.port
store i32 1, i32* @read_console.cmd
br label %120
27: ; preds = %2
store i32 10, i32* @read_console.port
store i32 1, i32* @read_console.cmd
br label %120
28: ; preds = %2
store i32 11, i32* @read_console.port
store i32 1, i32* @read_console.cmd
br label %120
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* @read_console.data
%31 = load i32, i32* %5
%32 = call i32 @send_packet(i32 %31, i32 10, i32 144, i32* @read_console.data, i32 1)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 -1, i32* %3
br label %121
35: ; preds = %29
br label %120
36: ; preds = %2
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* @read_console.data
%38 = load i32, i32* %5
%39 = call i32 @send_packet(i32 %38, i32 8, i32 1, i32* @read_console.data, i32 1)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36
store i32 -1, i32* %3
br label %121
42: ; preds = %36
br label %120
43: ; preds = %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* @read_console.data
%45 = load i32, i32* %5
%46 = call i32 @send_packet(i32 %45, i32 10, i32 27, i32* @read_console.data, i32 1)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 -1, i32* %3
br label %121
49: ; preds = %43
br label %120
50: ; preds = %2
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* @read_console.data
%52 = load i32, i32* %5
%53 = call i32 @send_packet(i32 %52, i32 10, i32 45, i32* @read_console.data, i32 1)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %50
store i32 -1, i32* %3
br label %121
56: ; preds = %50
br label %120
57: ; preds = %2
%58 = load i32, i32* @read_console.rec
%59 = xor i32 %58, 1
store i32 %59, i32* @read_console.rec
%60 = load i32, i32* @read_console.rec
%61 = icmp ne i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %5
%66 = call i32 @send_packet(i32 %65, i32 8, i32 2, i32* @read_console.rec, i32 1)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %57
store i32 -1, i32* %3
br label %121
69: ; preds = %57
br label %120
70: ; preds = %2
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @read_console.data
%72 = load i32, i32* %5
%73 = call i32 @send_packet(i32 %72, i32 11, i32 37, i32* @read_console.data, i32 1)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %70
store i32 -1, i32* %3
br label %121
76: ; preds = %70
br label %120
77: ; preds = %2
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* @read_console.data
%79 = load i32, i32* %5
%80 = call i32 @send_packet(i32 %79, i32 8, i32 64, i32* @read_console.data, i32 1)
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %77
store i32 -1, i32* %3
br label %121
83: ; preds = %77
br label %120
84: ; preds = %2
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* @read_console.data
%86 = load i32, i32* %5
%87 = call i32 @send_packet(i32 %86, i32 8, i32 68, i32* @read_console.data, i32 1)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %84
store i32 -1, i32* %3
br label %121
90: ; preds = %84
br label %120
91: ; preds = %2
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* @read_console.data
%93 = load i32, i32* %5
%94 = call i32 @send_packet(i32 %93, i32 8, i32 50, i32* @read_console.data, i32 1)
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %91
store i32 -1, i32* %3
br label %121
97: ; preds = %91
br label %120
98: ; preds = %2
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* @read_console.data
%100 = load i32, i32* %5
%101 = call i32 @send_packet(i32 %100, i32 10, i32 73, i32* @read_console.data, i32 1)
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %104
103: ; preds = %98
store i32 -1, i32* %3
br label %121
104: ; preds = %98
br label %120
105: ; preds = %2
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* @read_console.data
%107 = load i32, i32* %5
%108 = call i32 @send_packet(i32 %107, i32 10, i32 82, i32* @read_console.data, i32 1)
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %105
store i32 -1, i32* %3
br label %121
111: ; preds = %105
br label %120
112: ; preds = %2
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* @read_console.data
%114 = load i32, i32* %5
%115 = call i32 @send_packet(i32 %114, i32 10, i32 83, i32* @read_console.data, i32 1)
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %118
117: ; preds = %112
store i32 -1, i32* %3
br label %121
118: ; preds = %112
br label %120
119: ; preds = %2
br label %120
120: ; preds = %119, %118, %111, %104, %97, %90, %83, %76, %69, %56, %49, %42, %35, %28, %27, %26, %23
store i32 0, i32* %3
br label %121
121: ; preds = %120, %117, %110, %103, %96, %89, %82, %75, %68, %55, %48, %41, %34, %22
%122 = load i32, i32* %3
ret i32 %122
}

LLVM IR (-O2):
@read_console.data = internal global i32 0
@read_console.rec = internal global i32 0
@read_console.cmd = internal unnamed_addr global i32 256
@read_console.port = internal unnamed_addr global i32 8
@.str = [39 x i8] c"** Requesting 0x%02x00 at port 0x%02x\0A\00"
@.str.5 = [17 x i8] c"** %s recording\0A\00"
@.str.6 = [9 x i8] c"Starting\00"
@.str.7 = [9 x i8] c"Stopping\00"
@str = [27 x i8] c"*** Sending command 0x5300\00"
@str.15 = [41 x i8] c"*** Sending command 0x5200 (flight mode)\00"
@str.16 = [43 x i8] c"*** Sending command 0x4900 (GPS telemetry)\00"
@str.17 = [44 x i8] c"*** Sending command 0x32 (current position)\00"
@str.18 = [27 x i8] c"*** Sending command 0x4400\00"
@str.19 = [27 x i8] c"*** Sending command 0x4000\00"
@str.20 = [26 x i8] c"** Sending command 0x2500\00"
@str.21 = [26 x i8] c"** Sending command 0x2d00\00"
@str.22 = [26 x i8] c"** Sending command 0x1b00\00"
@str.23 = [18 x i8] c"** Taking picture\00"
@str.24 = [32 x i8] c"** Calibrating compass (0x9001)\00"
define i32 @read_console(i32* nocapture %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @fgets(i8* %4, i32 256, i32* %0)
%6 = load i8, i8* %4
%7 = sext i8 %6 to i32
switch i32 %7, label %76 [
i32 10, label %8
i32 56, label %19
i32 65, label %20
i32 66, label %21
i32 67, label %22
i32 99, label %26
i32 98, label %30
i32 100, label %34
i32 114, label %38
i32 53, label %46
i32 48, label %50
i32 52, label %54
i32 112, label %58
i32 103, label %62
i32 102, label %66
i32 51, label %70
]
8: ; preds = %2
%9 = load i32, i32* @read_console.cmd
%10 = load i32, i32* @read_console.port
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
store i32 0, i32* @read_console.data
%12 = load i32, i32* @read_console.port
%13 = load i32, i32* @read_console.cmd
%14 = call i32 @send_packet(i32 %1, i32 %12, i32 %13, i32* @read_console.data, i32 1)
%15 = icmp slt i32 %14, 0
br i1 %15, label %77, label %16
16: ; preds = %8
%17 = load i32, i32* @read_console.cmd
%18 = add nsw i32 %17, 1
br label %74
19: ; preds = %2
store i32 8, i32* @read_console.port
br label %74
20: ; preds = %2
store i32 10, i32* @read_console.port
br label %74
21: ; preds = %2
store i32 11, i32* @read_console.port
br label %74
22: ; preds = %2
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.24, i64 0, i64 0))
store i32 1, i32* @read_console.data
%24 = call i32 @send_packet(i32 %1, i32 10, i32 144, i32* @read_console.data, i32 1)
%25 = icmp slt i32 %24, 0
br i1 %25, label %77, label %76
26: ; preds = %2
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.23, i64 0, i64 0))
store i32 1, i32* @read_console.data
%28 = call i32 @send_packet(i32 %1, i32 8, i32 1, i32* @read_console.data, i32 1)
%29 = icmp slt i32 %28, 0
br i1 %29, label %77, label %76
30: ; preds = %2
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.22, i64 0, i64 0))
store i32 0, i32* @read_console.data
%32 = call i32 @send_packet(i32 %1, i32 10, i32 27, i32* @read_console.data, i32 1)
%33 = icmp slt i32 %32, 0
br i1 %33, label %77, label %76
34: ; preds = %2
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.21, i64 0, i64 0))
store i32 0, i32* @read_console.data
%36 = call i32 @send_packet(i32 %1, i32 10, i32 45, i32* @read_console.data, i32 1)
%37 = icmp slt i32 %36, 0
br i1 %37, label %77, label %76
38: ; preds = %2
%39 = load i32, i32* @read_console.rec
%40 = xor i32 %39, 1
store i32 %40, i32* @read_console.rec
%41 = icmp eq i32 %40, 0
%42 = select i1 %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%44 = call i32 @send_packet(i32 %1, i32 8, i32 2, i32* @read_console.rec, i32 1)
%45 = icmp slt i32 %44, 0
br i1 %45, label %77, label %76
46: ; preds = %2
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.20, i64 0, i64 0))
store i32 0, i32* @read_console.data
%48 = call i32 @send_packet(i32 %1, i32 11, i32 37, i32* @read_console.data, i32 1)
%49 = icmp slt i32 %48, 0
br i1 %49, label %77, label %76
50: ; preds = %2
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.19, i64 0, i64 0))
store i32 0, i32* @read_console.data
%52 = call i32 @send_packet(i32 %1, i32 8, i32 64, i32* @read_console.data, i32 1)
%53 = icmp slt i32 %52, 0
br i1 %53, label %77, label %76
54: ; preds = %2
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.18, i64 0, i64 0))
store i32 0, i32* @read_console.data
%56 = call i32 @send_packet(i32 %1, i32 8, i32 68, i32* @read_console.data, i32 1)
%57 = icmp slt i32 %56, 0
br i1 %57, label %77, label %76
58: ; preds = %2
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.17, i64 0, i64 0))
store i32 0, i32* @read_console.data
%60 = call i32 @send_packet(i32 %1, i32 8, i32 50, i32* @read_console.data, i32 1)
%61 = icmp slt i32 %60, 0
br i1 %61, label %77, label %76
62: ; preds = %2
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.16, i64 0, i64 0))
store i32 0, i32* @read_console.data
%64 = call i32 @send_packet(i32 %1, i32 10, i32 73, i32* @read_console.data, i32 1)
%65 = icmp slt i32 %64, 0
br i1 %65, label %77, label %76
66: ; preds = %2
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.15, i64 0, i64 0))
store i32 0, i32* @read_console.data
%68 = call i32 @send_packet(i32 %1, i32 10, i32 82, i32* @read_console.data, i32 1)
%69 = icmp slt i32 %68, 0
br i1 %69, label %77, label %76
70: ; preds = %2
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
store i32 0, i32* @read_console.data
%72 = call i32 @send_packet(i32 %1, i32 10, i32 83, i32* @read_console.data, i32 1)
%73 = icmp slt i32 %72, 0
br i1 %73, label %77, label %76
74: ; preds = %16, %19, %20, %21
%75 = phi i32 [ 1, %21 ], [ 1, %20 ], [ 1, %19 ], [ %18, %16 ]
store i32 %75, i32* @read_console.cmd
br label %76
76: ; preds = %74, %2, %70, %66, %62, %58, %54, %50, %46, %38, %34, %30, %26, %22
br label %77
77: ; preds = %70, %66, %62, %58, %54, %50, %46, %38, %34, %30, %26, %22, %8, %76
%78 = phi i32 [ 0, %76 ], [ -1, %8 ], [ -1, %22 ], [ -1, %26 ], [ -1, %30 ], [ -1, %34 ], [ -1, %38 ], [ -1, %46 ], [ -1, %50 ], [ -1, %54 ], [ -1, %58 ], [ -1, %62 ], [ -1, %66 ], [ -1, %70 ]
ret i32 %78
}