#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 dummy;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B9600;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int changebaud(int, int, int /*<<< orphan*/);
int checkhoffset(int, int);
int /*<<< orphan*/ checkrom(int);
int /*<<< orphan*/ closecpu(int *, struct termios *);
int /*<<< orphan*/ closestdin(int *, struct termios *);
int /*<<< orphan*/ getcpuinfo(int);
int /*<<< orphan*/ opencpu(int *, struct termios *, struct termios *);
int /*<<< orphan*/ openstdin(int *, struct termios *, struct termios *);
int /*<<< orphan*/ plotimage();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printinstructions();
int read(int, unsigned char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sethoffset(int, int);
int takedarkimage(int);
int takeimage(int);
int /*<<< orphan*/ toggleshutter(int, int *);
int main(void) {
  unsigned char buf[1024];
  int len = 0;
  int fdcpu, fdstdin;
  struct termios oldcputio, newcputio, oldstdintio, newstdintio;
  int STOP = 0;
  int SHUTTER = 1;
  opencpu(&fdcpu, &oldcputio, &newcputio);
  openstdin(&fdstdin, &oldstdintio, &newstdintio);
  if (!checkrom(fdcpu)) {
    closestdin(&fdstdin, &oldstdintio);
    closecpu(&fdcpu, &oldcputio);
    return -1;
  }
  getcpuinfo(fdcpu);
  printf("\n");
  if (SHUTTER == 1)
    toggleshutter(fdcpu, &SHUTTER);
  printf("Trying head_offset of %d:\n", 163);
  if (checkhoffset(fdcpu, 163) == 1)
    printf("That's fine.  It should be between 1000 and 10,000.\n");
  else {
    printf("NOT within range.  Shutting down.\n");
    closestdin(&fdstdin, &oldstdintio);
    closecpu(&fdcpu, &oldcputio);
    return -1;
  }
  toggleshutter(fdcpu, &SHUTTER);
  printf("\n");
  sethoffset(fdcpu, 163);
  printf("Set head offset to %d.\n", 163);
  fd_set readfs;
  int maxfd = fdstdin + 1;
  FD_ZERO(&readfs);
  while (STOP == 0) {
    printinstructions();
    FD_SET(fdstdin, &readfs);
    select(maxfd, &readfs, NULL, NULL, NULL);
    if (FD_ISSET(fdstdin, &readfs)) {
      len = read(fdstdin, buf, 1);
      if (len > 0) {
        if (buf[0] == 'x')
          STOP = 1;
        if (buf[0] == 's')
          toggleshutter(fdcpu, &SHUTTER);
        if (buf[0] == 'i')
          if (takeimage(fdcpu) == 1) {
            printf("\nWrote pixel array to %s.\n", "image.dat");
            plotimage();
          } else
            printf("\nNo image taken.\n");
        if (buf[0] == 'b')
          if (changebaud(fdcpu, 115200, B115200) == 1)
            printf("Baud rate now %ld.\n", (long int)115200);
          else
            printf("Higher baud rate failed.\n");
        if (buf[0] == 'd') {
          if (takedarkimage(fdcpu) == 1)
            printf("Stored dark image in buffer.\n");
          else
            printf("Dark image failed.\n");
        }
      }
    }
  }
  if (SHUTTER == 0)
    toggleshutter(fdcpu, &SHUTTER);
  changebaud(fdcpu, 9600, B9600);
  closestdin(&fdstdin, &oldstdintio);
  closecpu(&fdcpu, &oldcputio);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x414(%rbp)
movl   $0x0,-0x43c(%rbp)
movl   $0x1,-0x440(%rbp)
lea    -0x418(%rbp),%rdi
lea    -0x420(%rbp),%rsi
lea    -0x428(%rbp),%rdx
call   1060 <opencpu@plt>
lea    -0x41c(%rbp),%rdi
lea    -0x430(%rbp),%rsi
lea    -0x438(%rbp),%rdx
call   1040 <openstdin@plt>
mov    -0x418(%rbp),%edi
call   1110 <checkrom@plt>
cmp    $0x0,%eax
jne    12ea <main+0xaa>
lea    -0x41c(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1160 <closestdin@plt>
lea    -0x418(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1120 <closecpu@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1637 <main+0x3f7>
mov    -0x418(%rbp),%edi
call   1070 <getcpuinfo@plt>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x1,-0x440(%rbp)
jne    1322 <main+0xe2>
mov    -0x418(%rbp),%edi
lea    -0x440(%rbp),%rsi
call   1090 <toggleshutter@plt>
lea    0xcd7(%rip),%rdi
mov    $0xa3,%esi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x418(%rbp),%edi
mov    $0xa3,%esi
call   1130 <checkhoffset@plt>
cmp    $0x1,%eax
jne    1361 <main+0x121>
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    13a1 <main+0x161>
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x41c(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1160 <closestdin@plt>
lea    -0x418(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1120 <closecpu@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1637 <main+0x3f7>
mov    -0x418(%rbp),%edi
lea    -0x440(%rbp),%rsi
call   1090 <toggleshutter@plt>
lea    0xc94(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x418(%rbp),%edi
mov    $0xa3,%esi
call   10c0 <sethoffset@plt>
lea    0xc9b(%rip),%rdi
mov    $0xa3,%esi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
lea    -0x444(%rbp),%rdi
call   10e0 <FD_ZERO@plt>
cmpl   $0x0,-0x43c(%rbp)
jne    15d2 <main+0x392>
mov    $0x0,%al
call   1100 <printinstructions@plt>
mov    -0x41c(%rbp),%edi
lea    -0x444(%rbp),%rsi
call   1150 <FD_SET@plt>
mov    -0x448(%rbp),%edi
lea    -0x444(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10f0 <select@plt>
mov    -0x41c(%rbp),%edi
lea    -0x444(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15cd <main+0x38d>
mov    -0x41c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    15c8 <main+0x388>
movzbl -0x410(%rbp),%eax
cmp    $0x78,%eax
jne    14a2 <main+0x262>
movl   $0x1,-0x43c(%rbp)
movzbl -0x410(%rbp),%eax
cmp    $0x73,%eax
jne    14c4 <main+0x284>
mov    -0x418(%rbp),%edi
lea    -0x440(%rbp),%rsi
call   1090 <toggleshutter@plt>
movzbl -0x410(%rbp),%eax
cmp    $0x69,%eax
jne    151c <main+0x2dc>
mov    -0x418(%rbp),%edi
call   10a0 <takeimage@plt>
cmp    $0x1,%eax
jne    1509 <main+0x2c9>
lea    0xb9c(%rip),%rdi
lea    0xbb0(%rip),%rsi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1030 <plotimage@plt>
jmp    1517 <main+0x2d7>
lea    0xba0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    151c <main+0x2dc>
movzbl -0x410(%rbp),%eax
cmp    $0x62,%eax
jne    1579 <main+0x339>
mov    -0x418(%rbp),%edi
mov    0x2a9f(%rip),%rax
mov    (%rax),%edx
mov    $0x1c200,%esi
call   1140 <changebaud@plt>
cmp    $0x1,%eax
jne    1566 <main+0x326>
lea    0xb6d(%rip),%rdi
mov    $0x1c200,%esi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1574 <main+0x334>
lea    0xb69(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1579 <main+0x339>
movzbl -0x410(%rbp),%eax
cmp    $0x64,%eax
jne    15c3 <main+0x383>
mov    -0x418(%rbp),%edi
call   10d0 <takedarkimage@plt>
cmp    $0x1,%eax
jne    15b0 <main+0x370>
lea    0xb4c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15be <main+0x37e>
lea    0xb57(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15c3 <main+0x383>
jmp    15c8 <main+0x388>
jmp    15cd <main+0x38d>
jmp    13ff <main+0x1bf>
cmpl   $0x0,-0x440(%rbp)
jne    15f1 <main+0x3b1>
mov    -0x418(%rbp),%edi
lea    -0x440(%rbp),%rsi
call   1090 <toggleshutter@plt>
mov    -0x418(%rbp),%edi
mov    0x29ea(%rip),%rax
mov    (%rax),%edx
mov    $0x2580,%esi
call   1140 <changebaud@plt>
lea    -0x41c(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1160 <closestdin@plt>
lea    -0x418(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1120 <closecpu@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
movl   $0x1,0xc(%rsp)
lea    0x4(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x28(%rsp),%rdx
call   1080 <opencpu@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1050 <openstdin@plt>
mov    0x4(%rsp),%edi
call   1130 <checkrom@plt>
test   %eax,%eax
je     149e <main+0x23e>
mov    0x4(%rsp),%edi
call   1090 <getcpuinfo@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%edi
lea    0xc(%rsp),%rsi
call   10b0 <toggleshutter@plt>
lea    0xd82(%rip),%rdi
mov    $0xa3,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x4(%rsp),%edi
mov    $0xa3,%esi
call   1150 <checkhoffset@plt>
cmp    $0x1,%eax
jne    1492 <main+0x232>
lea    0xde6(%rip),%rdi
call   1060 <puts@plt>
mov    0x4(%rsp),%edi
lea    0xc(%rsp),%r14
mov    %r14,%rsi
call   10b0 <toggleshutter@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%edi
mov    $0xa3,%esi
call   10e0 <sethoffset@plt>
lea    0xd3e(%rip),%rdi
mov    $0xa3,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x8(%rsp),%ebp
add    $0x1,%ebp
lea    0x2c(%rsp),%rbx
mov    %rbx,%rdi
call   1100 <FD_ZERO@plt>
lea    0x30(%rsp),%r15
lea    0xc9b(%rip),%r13
mov    0x2c6c(%rip),%r12
jmp    1380 <main+0x120>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   10b0 <toggleshutter@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1120 <printinstructions@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1170 <FD_SET@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1110 <select@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     1380 <main+0x120>
mov    0x8(%rsp),%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   10d0 <read@plt>
test   %eax,%eax
jle    1380 <main+0x120>
movzbl 0x30(%rsp),%eax
add    $0x9e,%al
cmp    $0x16,%al
ja     1380 <main+0x120>
movzbl %al,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x4(%rsp),%edi
mov    (%r12),%edx
mov    $0x1c200,%esi
call   1160 <changebaud@plt>
cmp    $0x1,%eax
jne    145f <main+0x1ff>
mov    $0x1c200,%esi
lea    0xcaf(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    1380 <main+0x120>
mov    0x4(%rsp),%edi
call   10f0 <takedarkimage@plt>
cmp    $0x1,%eax
jne    1470 <main+0x210>
lea    0xd0b(%rip),%rdi
call   1060 <puts@plt>
jmp    1380 <main+0x120>
mov    0x4(%rsp),%edi
call   10c0 <takeimage@plt>
cmp    $0x1,%eax
jne    1481 <main+0x221>
lea    0xc4a(%rip),%rdi
lea    0xc5e(%rip),%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
xor    %eax,%eax
call   1040 <plotimage@plt>
jmp    1380 <main+0x120>
lea    0xce8(%rip),%rdi
call   1060 <puts@plt>
jmp    1380 <main+0x120>
lea    0xca7(%rip),%rdi
call   1060 <puts@plt>
jmp    1380 <main+0x120>
lea    0xcdf(%rip),%rdi
call   1060 <puts@plt>
jmp    1380 <main+0x120>
lea    0xc2f(%rip),%rdi
call   1060 <puts@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1180 <closestdin@plt>
lea    0x4(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1140 <closecpu@plt>
mov    $0xffffffff,%eax
jmp    150f <main+0x2af>
cmpl   $0x0,0xc(%rsp)
jne    14d8 <main+0x278>
mov    0x4(%rsp),%edi
lea    0xc(%rsp),%rsi
call   10b0 <toggleshutter@plt>
mov    0x4(%rsp),%edi
mov    0x2b05(%rip),%rax
mov    (%rax),%edx
mov    $0x2580,%esi
call   1160 <changebaud@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1180 <closestdin@plt>
lea    0x4(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1140 <closecpu@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [2 x i8] c"\0A\00"
@.str.1 = [27 x i8] c"Trying head_offset of %d:\0A\00"
@.str.2 = [53 x i8] c"That's fine. It should be between 1000 and 10,000.\0A\00"
@.str.3 = [35 x i8] c"NOT within range. Shutting down.\0A\00"
@.str.4 = [24 x i8] c"Set head offset to %d.\0A\00"
@.str.5 = [27 x i8] c"\0AWrote pixel array to %s.\0A\00"
@.str.6 = [10 x i8] c"image.dat\00"
@.str.7 = [18 x i8] c"\0ANo image taken.\0A\00"
@B115200 = global i32 0
@.str.8 = [20 x i8] c"Baud rate now %ld.\0A\00"
@.str.9 = [26 x i8] c"Higher baud rate failed.\0A\00"
@.str.10 = [30 x i8] c"Stored dark image in buffer.\0A\00"
@.str.11 = [20 x i8] c"Dark image failed.\0A\00"
@B9600 = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca %struct.termios
%8 = alloca %struct.termios
%9 = alloca %struct.termios
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %10
store i32 1, i32* %11
%14 = call i32 @opencpu(i32* %4, %struct.termios* %6, %struct.termios* %7)
%15 = call i32 @openstdin(i32* %5, %struct.termios* %8, %struct.termios* %9)
%16 = load i32, i32* %4
%17 = call i32 @checkrom(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %0
%20 = call i32 @closestdin(i32* %5, %struct.termios* %8)
%21 = call i32 @closecpu(i32* %4, %struct.termios* %6)
store i32 -1, i32* %1
br label %143
22: ; preds = %0
%23 = load i32, i32* %4
%24 = call i32 @getcpuinfo(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %4
%30 = call i32 @toggleshutter(i32 %29, i32* %11)
br label %31
31: ; preds = %28, %22
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 163)
%33 = load i32, i32* %4
%34 = call i32 @checkhoffset(i32 %33, i32 163)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %42
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @closestdin(i32* %5, %struct.termios* %8)
%41 = call i32 @closecpu(i32* %4, %struct.termios* %6)
store i32 -1, i32* %1
br label %143
42: ; preds = %36
%43 = load i32, i32* %4
%44 = call i32 @toggleshutter(i32 %43, i32* %11)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%46 = load i32, i32* %4
%47 = call i32 @sethoffset(i32 %46, i32 163)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 163)
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
%51 = call i32 @FD_ZERO(i32* %12)
br label %52
52: ; preds = %130, %42
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %131
55: ; preds = %52
%56 = call i32 (...) @printinstructions()
%57 = load i32, i32* %5
%58 = call i32 @FD_SET(i32 %57, i32* %12)
%59 = load i32, i32* %13
%60 = call i32 @select(i32 %59, i32* %12, i32* null, i32* null, i32* null)
%61 = load i32, i32* %5
%62 = call i64 @FD_ISSET(i32 %61, i32* %12)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %130
64: ; preds = %55
%65 = load i32, i32* %5
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%67 = call i32 @read(i32 %65, i8* %66, i32 1)
store i32 %67, i32* %3
%68 = load i32, i32* %3
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %129
70: ; preds = %64
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = icmp eq i32 %73, 120
br i1 %74, label %75, label %76
75: ; preds = %70
store i32 1, i32* %10
br label %76
76: ; preds = %75, %70
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = icmp eq i32 %79, 115
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = load i32, i32* %4
%83 = call i32 @toggleshutter(i32 %82, i32* %11)
br label %84
84: ; preds = %81, %76
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = icmp eq i32 %87, 105
br i1 %88, label %89, label %99
89: ; preds = %84
%90 = load i32, i32* %4
%91 = call i32 @takeimage(i32 %90)
%92 = icmp eq i32 %91, 1
br i1 %92, label %93, label %96
93: ; preds = %89
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%95 = call i32 (...) @plotimage()
br label %98
96: ; preds = %89
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %98
98: ; preds = %96, %93
br label %99
99: ; preds = %98, %84
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = icmp eq i32 %102, 98
br i1 %103, label %104, label %114
104: ; preds = %99
%105 = load i32, i32* %4
%106 = load i32, i32* @B115200
%107 = call i32 @changebaud(i32 %105, i32 115200, i32 %106)
%108 = icmp eq i32 %107, 1
br i1 %108, label %109, label %111
109: ; preds = %104
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i64 115200)
br label %113
111: ; preds = %104
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %113
113: ; preds = %111, %109
br label %114
114: ; preds = %113, %99
%115 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%116 = load i8, i8* %115
%117 = zext i8 %116 to i32
%118 = icmp eq i32 %117, 100
br i1 %118, label %119, label %128
119: ; preds = %114
%120 = load i32, i32* %4
%121 = call i32 @takedarkimage(i32 %120)
%122 = icmp eq i32 %121, 1
br i1 %122, label %123, label %125
123: ; preds = %119
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
br label %127
125: ; preds = %119
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0))
br label %127
127: ; preds = %125, %123
br label %128
128: ; preds = %127, %114
br label %129
129: ; preds = %128, %64
br label %130
130: ; preds = %129, %55
br label %52
131: ; preds = %52
%132 = load i32, i32* %11
%133 = icmp eq i32 %132, 0
br i1 %133, label %134, label %137
134: ; preds = %131
%135 = load i32, i32* %4
%136 = call i32 @toggleshutter(i32 %135, i32* %11)
br label %137
137: ; preds = %134, %131
%138 = load i32, i32* %4
%139 = load i32, i32* @B9600
%140 = call i32 @changebaud(i32 %138, i32 9600, i32 %139)
%141 = call i32 @closestdin(i32* %5, %struct.termios* %8)
%142 = call i32 @closecpu(i32* %4, %struct.termios* %6)
store i32 0, i32* %1
br label %143
143: ; preds = %137, %38, %19
%144 = load i32, i32* %1
ret i32 %144
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str.1 = [27 x i8] c"Trying head_offset of %d:\0A\00"
@.str.4 = [24 x i8] c"Set head offset to %d.\0A\00"
@.str.5 = [27 x i8] c"\0AWrote pixel array to %s.\0A\00"
@.str.6 = [10 x i8] c"image.dat\00"
@B115200 = global i32 0
@.str.8 = [20 x i8] c"Baud rate now %ld.\0A\00"
@B9600 = global i32 0
@str = [34 x i8] c"NOT within range. Shutting down.\00"
@str.12 = [52 x i8] c"That's fine. It should be between 1000 and 10,000.\00"
@str.13 = [19 x i8] c"Dark image failed.\00"
@str.14 = [29 x i8] c"Stored dark image in buffer.\00"
@str.15 = [25 x i8] c"Higher baud rate failed.\00"
@str.16 = [17 x i8] c"\0ANo image taken.\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
%5 = alloca %struct.termios
%6 = alloca %struct.termios
%7 = alloca %struct.termios
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%11 = bitcast i32* %2 to i8*
%12 = bitcast i32* %3 to i8*
%13 = bitcast %struct.termios* %4 to i8*
%14 = bitcast %struct.termios* %5 to i8*
%15 = bitcast %struct.termios* %6 to i8*
%16 = bitcast %struct.termios* %7 to i8*
%17 = bitcast i32* %8 to i8*
store i32 1, i32* %8
%18 = call i32 @opencpu(i32* %2, %struct.termios* %4, %struct.termios* %5)
%19 = call i32 @openstdin(i32* %3, %struct.termios* %6, %struct.termios* %7)
%20 = load i32, i32* %2
%21 = call i32 @checkrom(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %0
%24 = call i32 @closestdin(i32* %3, %struct.termios* %6)
%25 = call i32 @closecpu(i32* %2, %struct.termios* %4)
br label %108
26: ; preds = %0
%27 = load i32, i32* %2
%28 = call i32 @getcpuinfo(i32 %27)
%29 = call i32 @putchar(i32 10)
%30 = load i32, i32* %2
%31 = call i32 @toggleshutter(i32 %30, i32* %8)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 163)
%33 = load i32, i32* %2
%34 = call i32 @checkhoffset(i32 %33, i32 163)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %48
36: ; preds = %26
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.12, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = call i32 @toggleshutter(i32 %38, i32* %8)
%40 = call i32 @putchar(i32 10)
%41 = load i32, i32* %2
%42 = call i32 @sethoffset(i32 %41, i32 163)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 163)
%44 = bitcast i32* %9 to i8*
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
%47 = call i32 @FD_ZERO(i32* %9)
br label %52
48: ; preds = %26
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%50 = call i32 @closestdin(i32* %3, %struct.termios* %6)
%51 = call i32 @closecpu(i32* %2, %struct.termios* %4)
br label %108
52: ; preds = %60, %36
%53 = call i32 (...) @printinstructions()
%54 = load i32, i32* %3
%55 = call i32 @FD_SET(i32 %54, i32* %9)
%56 = call i32 @select(i32 %46, i32* %9, i32* null, i32* null, i32* null)
%57 = load i32, i32* %3
%58 = call i64 @FD_ISSET(i32 %57, i32* %9)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %52, %61, %65, %67, %74, %77, %84, %86, %92, %94
br label %52
61: ; preds = %52
%62 = load i32, i32* %3
%63 = call i32 @read(i32 %62, i8* %10, i32 1)
%64 = icmp sgt i32 %63, 0
br i1 %64, label %65, label %60
65: ; preds = %61
%66 = load i8, i8* %10
switch i8 %66, label %60 [
i8 115, label %67
i8 105, label %70
i8 98, label %79
i8 100, label %88
i8 120, label %96
]
67: ; preds = %65
%68 = load i32, i32* %2
%69 = call i32 @toggleshutter(i32 %68, i32* %8)
br label %60
70: ; preds = %65
%71 = load i32, i32* %2
%72 = call i32 @takeimage(i32 %71)
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%76 = call i32 (...) @plotimage()
br label %60
77: ; preds = %70
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.16, i64 0, i64 0))
br label %60
79: ; preds = %65
%80 = load i32, i32* %2
%81 = load i32, i32* @B115200
%82 = call i32 @changebaud(i32 %80, i32 115200, i32 %81)
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %86
84: ; preds = %79
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i64 115200)
br label %60
86: ; preds = %79
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.15, i64 0, i64 0))
br label %60
88: ; preds = %65
%89 = load i32, i32* %2
%90 = call i32 @takedarkimage(i32 %89)
%91 = icmp eq i32 %90, 1
br i1 %91, label %92, label %94
92: ; preds = %88
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.14, i64 0, i64 0))
br label %60
94: ; preds = %88
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.13, i64 0, i64 0))
br label %60
96: ; preds = %65
%97 = load i32, i32* %8
%98 = icmp eq i32 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %96
%100 = load i32, i32* %2
%101 = call i32 @toggleshutter(i32 %100, i32* %8)
br label %102
102: ; preds = %99, %96
%103 = load i32, i32* %2
%104 = load i32, i32* @B9600
%105 = call i32 @changebaud(i32 %103, i32 9600, i32 %104)
%106 = call i32 @closestdin(i32* %3, %struct.termios* %6)
%107 = call i32 @closecpu(i32* %2, %struct.termios* %4)
br label %108
108: ; preds = %102, %48, %23
%109 = phi i32 [ 0, %102 ], [ -1, %48 ], [ -1, %23 ]
ret i32 %109
}