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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS7;
int CSIZE;
int CSTOPB;
int ECHO;
int /*<<< orphan*/ FNDELAY;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int ISIG;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int open_port();
int read(int, char **, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int mainfd = 0;
  int num, n;
  char chout[16];
  char serialBuffer[16];
  char preBuffer[16];
  char scannerInput[12];
  char scaleInput[9];
  char scaleBuffer[9] = "000000000";
  struct termios options;
  char serialInput;
  mainfd = open_port();
  fcntl(mainfd, F_SETFL, FNDELAY);
  tcgetattr(mainfd, &options);
  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 | ISIG);
  tcsetattr(mainfd, TCSANOW, &options);
  FILE *fp_scanner;
  FILE *fp_scale;
  int in_buffer = 0;
  int i;
  n = 0;
  num = 0;
  write(mainfd, "S11\r", 5);
  write(mainfd, "S14\r", 5);
  while (1) {
    in_buffer = read(mainfd, &chout, 1);
    if (in_buffer != -1) {
      if (chout[0] == 'S') {
        num = 0;
      }
      serialBuffer[num] = chout[0];
      num++;
      if (chout[0] == '\n' && num > 2) {
        serialBuffer[num] = '\0';
        if (serialBuffer[1] == '0') {
          for (i = 0; i < 17; i++) {
            scannerInput[i] = serialBuffer[i + 4];
          }
          fp_scanner = fopen("scanner", "w");
          fprintf(fp_scanner, "%s\n", scannerInput);
          fclose(fp_scanner);
        }
        if (serialBuffer[1] == '1') {
          if (serialBuffer[2] == '1') {
            write(mainfd, "S14\r", 5);
          } else if (serialBuffer[2] == '4' && serialBuffer[3] == '3') {
            write(mainfd, "S11\r", 5);
            if (strcmp(scaleBuffer, serialBuffer) != 0) {
              fp_scale = fopen("scale", "w");
              fprintf(fp_scale, "%s\n", serialBuffer);
              fclose(fp_scale);
            }
          } else if (serialBuffer[2] == '4') {
            write(mainfd, "S14\r", 5);
            if (strcmp(scaleBuffer, serialBuffer) != 0) {
              fp_scale = fopen("scale", "w");
              fprintf(fp_scale, "%s\n", serialBuffer);
              fclose(fp_scale);
            }
          }
          for (i = 0; i < 10; i++) {
            scaleBuffer[i] = serialBuffer[i];
          }
        }
      }
    }
    in_buffer = -1;
  }
  close(mainfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0xe20(%rip),%rax
mov    %rax,-0x5e(%rbp)
mov    0xe1e(%rip),%al
mov    %al,-0x56(%rbp)
mov    $0x0,%al
call   10e0 <open_port@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x8(%rbp),%edi
lea    -0x68(%rbp),%rsi
call   10a0 <tcgetattr@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   10d0 <cfsetispeed@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   1060 <cfsetospeed@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    0x2d67(%rip),%rcx
or     (%rcx),%eax
or     -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
or     -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
or     -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
or     -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
or     -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
mov    0x2d0f(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf6(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x64(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   10b0 <tcsetattr@plt>
movl   $0x0,-0x84(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    0xcf5(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xce6(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
je     15a0 <main+0x3e0>
movsbl -0x20(%rbp),%eax
cmp    $0x53,%eax
jne    136a <main+0x1aa>
movl   $0x0,-0xc(%rbp)
mov    -0x20(%rbp),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsbl -0x20(%rbp),%eax
cmp    $0xa,%eax
jne    159b <main+0x3db>
cmpl   $0x2,-0xc(%rbp)
jle    159b <main+0x3db>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
movsbl -0x2f(%rbp),%eax
cmp    $0x30,%eax
jne    1424 <main+0x264>
movl   $0x0,-0x88(%rbp)
cmpl   $0x11,-0x88(%rbp)
jge    13f0 <main+0x230>
mov    -0x88(%rbp),%eax
add    $0x4,%eax
cltq
mov    -0x30(%rbp,%rax,1),%cl
movslq -0x88(%rbp),%rax
mov    %cl,-0x4c(%rbp,%rax,1)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    13b5 <main+0x1f5>
lea    0xc1c(%rip),%rdi
lea    0xc1d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
lea    -0x4c(%rbp),%rdx
lea    0xc07(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x78(%rbp),%rdi
call   1050 <fclose@plt>
movsbl -0x2f(%rbp),%eax
cmp    $0x31,%eax
jne    1596 <main+0x3d6>
movsbl -0x2e(%rbp),%eax
cmp    $0x31,%eax
jne    1457 <main+0x297>
mov    -0x8(%rbp),%edi
lea    0xbc6(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
jmp    1550 <main+0x390>
movsbl -0x2e(%rbp),%eax
cmp    $0x34,%eax
jne    14d5 <main+0x315>
movsbl -0x2d(%rbp),%eax
cmp    $0x33,%eax
jne    14d5 <main+0x315>
mov    -0x8(%rbp),%edi
lea    0xb8e(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
lea    -0x5e(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     14d0 <main+0x310>
lea    0xb7e(%rip),%rdi
lea    0xb71(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xb5b(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x80(%rbp),%rdi
call   1050 <fclose@plt>
jmp    154b <main+0x38b>
movsbl -0x2e(%rbp),%eax
cmp    $0x34,%eax
jne    1546 <main+0x386>
mov    -0x8(%rbp),%edi
lea    0xb22(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
lea    -0x5e(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1541 <main+0x381>
lea    0xb0d(%rip),%rdi
lea    0xb00(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xaea(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x80(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1546 <main+0x386>
jmp    154b <main+0x38b>
jmp    1550 <main+0x390>
movl   $0x0,-0x88(%rbp)
cmpl   $0xa,-0x88(%rbp)
jge    1591 <main+0x3d1>
movslq -0x88(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%cl
movslq -0x88(%rbp),%rax
mov    %cl,-0x5e(%rbp,%rax,1)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    155a <main+0x39a>
jmp    1596 <main+0x3d6>
jmp    159b <main+0x3db>
jmp    15a0 <main+0x3e0>
movl   $0xffffffff,-0x84(%rbp)
ff ff ff
jmp    1332 <main+0x172>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movabs $0x3030303030303030,%rax
30 30 30
mov    %rax,0x18(%rsp)
movb   $0x30,0x20(%rsp)
xor    %r15d,%r15d
xor    %eax,%eax
call   10e0 <open_port@plt>
mov    %eax,%ebx
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
lea    0x28(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   10a0 <tcgetattr@plt>
mov    0x2da3(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   10d0 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1060 <cfsetospeed@plt>
mov    0x2d2e(%rip),%rax
mov    0x2d77(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x28(%rsp),%ecx
mov    0x2d98(%rip),%rax
or     (%rax),%ecx
mov    0x2d77(%rip),%rax
or     (%rax),%ecx
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    0x2d45(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2cf8(%rip),%rcx
or     (%rcx),%eax
mov    0x2cff(%rip),%rcx
or     (%rcx),%eax
mov    0x2d06(%rip),%rcx
mov    0x2d47(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,0x28(%rsp)
mov    0x2d28(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x2c(%rsp)
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   10b0 <tcsetattr@plt>
lea    0xd3e(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0xd30(%rip),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0x40(%rsp),%r12
xor    %r14d,%r14d
jmp    1310 <main+0x150>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1040 <write@plt>
movzwl 0x8(%rsp),%eax
mov    %ax,0x20(%rsp)
mov    (%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1310 <main+0x150>
movzbl 0x40(%rsp),%ecx
cmp    $0x53,%cl
mov    %r14d,%eax
cmove  %r15d,%eax
movslq %eax,%r14
mov    %cl,(%rsp,%r14,1)
add    $0x1,%r14d
cmp    $0xa,%cl
jne    1310 <main+0x150>
cmp    $0x2,%eax
jl     1310 <main+0x150>
mov    %r14d,%eax
movb   $0x0,(%rsp,%rax,1)
movzbl 0x1(%rsp),%eax
cmp    $0x30,%al
jne    13a4 <main+0x1e4>
lea    0x4(%rsp),%rcx
movzbl 0x10(%rcx),%eax
mov    %al,0x40(%rsp)
movups (%rcx),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0xc96(%rip),%rdi
lea    0xc97(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
lea    0xc87(%rip),%rsi
lea    0x30(%rsp),%rdx
call   1090 <fprintf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
movzbl 0x1(%rsp),%eax
cmp    $0x31,%al
jne    1310 <main+0x150>
movzbl 0x2(%rsp),%eax
cmp    $0x31,%al
je     12ee <main+0x12e>
cmp    $0x34,%al
jne    13cf <main+0x20f>
cmpb   $0x33,0x3(%rsp)
jne    13cf <main+0x20f>
mov    %ebx,%edi
lea    0xc33(%rip),%rsi
jmp    13dc <main+0x21c>
cmp    $0x34,%al
jne    12fd <main+0x13d>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0x18(%rsp),%rdi
mov    %rsp,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12fd <main+0x13d>
lea    0xc15(%rip),%rdi
lea    0xc08(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xbf8(%rip),%rsi
mov    %rsp,%rdx
call   1090 <fprintf@plt>
mov    %rbp,%rdi
lea    0xbd7(%rip),%rbp
call   1050 <fclose@plt>
jmp    12fd <main+0x13d>

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@__const.main.scaleBuffer = [9 x i8] c"000000000"
@F_SETFL = global i32 0
@FNDELAY = 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
@ISIG = global i32 0
@TCSANOW = global i32 0
@.str = [5 x i8] c"S11\0D\00"
@.str.1 = [5 x i8] c"S14\0D\00"
@.str.2 = [8 x i8] c"scanner\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [6 x i8] c"scale\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca [12 x i8]
%9 = alloca [9 x i8]
%10 = alloca [9 x i8]
%11 = alloca %struct.termios
%12 = alloca i8
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%17 = bitcast [9 x i8]* %10 to i8*
%18 = call i32 (...) @open_port()
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* @FNDELAY
%22 = call i32 @fcntl(i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @tcgetattr(i32 %23, %struct.termios* %11)
%25 = load i32, i32* @B9600
%26 = call i32 @cfsetispeed(%struct.termios* %11, i32 %25)
%27 = load i32, i32* @B9600
%28 = call i32 @cfsetospeed(%struct.termios* %11, i32 %27)
%29 = load i32, i32* @CLOCAL
%30 = load i32, i32* @CREAD
%31 = or i32 %29, %30
%32 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%33 = load i32, i32* %32
%34 = or i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @PARENB
%36 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%37 = load i32, i32* %36
%38 = or i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @PARODD
%40 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%41 = load i32, i32* %40
%42 = or i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @CSTOPB
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @CSIZE
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @CS7
%54 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%55 = load i32, i32* %54
%56 = or i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @CRTSCTS
%58 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%59 = load i32, i32* %58
%60 = or i32 %59, %57
store i32 %60, i32* %58
%61 = load i32, i32* @ICANON
%62 = load i32, i32* @ECHO
%63 = or i32 %61, %62
%64 = load i32, i32* @ISIG
%65 = or i32 %63, %64
%66 = xor i32 %65, -1
%67 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 1
%68 = load i32, i32* %67
%69 = and i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* %2
%71 = load i32, i32* @TCSANOW
%72 = call i32 @tcsetattr(i32 %70, i32 %71, %struct.termios* %11)
store i32 0, i32* %15
store i32 0, i32* %4
store i32 0, i32* %3
%73 = load i32, i32* %2
%74 = call i32 @write(i32 %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 5)
%75 = load i32, i32* %2
%76 = call i32 @write(i32 %75, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
br label %77
77: ; preds = %0, %213
%78 = load i32, i32* %2
%79 = bitcast [16 x i8]* %5 to i8**
%80 = call i32 @read(i32 %78, i8** %79, i32 1)
store i32 %80, i32* %15
%81 = load i32, i32* %15
%82 = icmp ne i32 %81, -1
br i1 %82, label %83, label %213
83: ; preds = %77
%84 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 83
br i1 %87, label %88, label %89
88: ; preds = %83
store i32 0, i32* %3
br label %89
89: ; preds = %88, %83
%90 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%91 = load i8, i8* %90
%92 = load i32, i32* %3
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %93
store i8 %91, i8* %94
%95 = load i32, i32* %3
%96 = add nsw i32 %95, 1
store i32 %96, i32* %3
%97 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = icmp eq i32 %99, 10
br i1 %100, label %101, label %212
101: ; preds = %89
%102 = load i32, i32* %3
%103 = icmp sgt i32 %102, 2
br i1 %103, label %104, label %212
104: ; preds = %101
%105 = load i32, i32* %3
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %106
store i8 0, i8* %107
%108 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 1
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = icmp eq i32 %110, 48
br i1 %111, label %112, label %135
112: ; preds = %104
store i32 0, i32* %16
br label %113
113: ; preds = %125, %112
%114 = load i32, i32* %16
%115 = icmp slt i32 %114, 17
br i1 %115, label %116, label %128
116: ; preds = %113
%117 = load i32, i32* %16
%118 = add nsw i32 %117, 4
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %119
%121 = load i8, i8* %120
%122 = load i32, i32* %16
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 %123
store i8 %121, i8* %124
br label %125
125: ; preds = %116
%126 = load i32, i32* %16
%127 = add nsw i32 %126, 1
store i32 %127, i32* %16
br label %113
128: ; preds = %113
%129 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %129, i32** %13
%130 = load i32*, i32** %13
%131 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%132 = call i32 @fprintf(i32* %130, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %131)
%133 = load i32*, i32** %13
%134 = call i32 @fclose(i32* %133)
br label %135
135: ; preds = %128, %104
%136 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 1
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = icmp eq i32 %138, 49
br i1 %139, label %140, label %211
140: ; preds = %135
%141 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 2
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = icmp eq i32 %143, 49
br i1 %144, label %145, label %148
145: ; preds = %140
%146 = load i32, i32* %2
%147 = call i32 @write(i32 %146, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
br label %195
148: ; preds = %140
%149 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 2
%150 = load i8, i8* %149
%151 = sext i8 %150 to i32
%152 = icmp eq i32 %151, 52
br i1 %152, label %153, label %173
153: ; preds = %148
%154 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 3
%155 = load i8, i8* %154
%156 = sext i8 %155 to i32
%157 = icmp eq i32 %156, 51
br i1 %157, label %158, label %173
158: ; preds = %153
%159 = load i32, i32* %2
%160 = call i32 @write(i32 %159, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 5)
%161 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%162 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%163 = call i64 @strcmp(i8* %161, i8* %162)
%164 = icmp ne i64 %163, 0
br i1 %164, label %165, label %172
165: ; preds = %158
%166 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %166, i32** %14
%167 = load i32*, i32** %14
%168 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%169 = call i32 @fprintf(i32* %167, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %168)
%170 = load i32*, i32** %14
%171 = call i32 @fclose(i32* %170)
br label %172
172: ; preds = %165, %158
br label %194
173: ; preds = %153, %148
%174 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 2
%175 = load i8, i8* %174
%176 = sext i8 %175 to i32
%177 = icmp eq i32 %176, 52
br i1 %177, label %178, label %193
178: ; preds = %173
%179 = load i32, i32* %2
%180 = call i32 @write(i32 %179, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%181 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%182 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%183 = call i64 @strcmp(i8* %181, i8* %182)
%184 = icmp ne i64 %183, 0
br i1 %184, label %185, label %192
185: ; preds = %178
%186 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %186, i32** %14
%187 = load i32*, i32** %14
%188 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%189 = call i32 @fprintf(i32* %187, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %188)
%190 = load i32*, i32** %14
%191 = call i32 @fclose(i32* %190)
br label %192
192: ; preds = %185, %178
br label %193
193: ; preds = %192, %173
br label %194
194: ; preds = %193, %172
br label %195
195: ; preds = %194, %145
store i32 0, i32* %16
br label %196
196: ; preds = %207, %195
%197 = load i32, i32* %16
%198 = icmp slt i32 %197, 10
br i1 %198, label %199, label %210
199: ; preds = %196
%200 = load i32, i32* %16
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %201
%203 = load i8, i8* %202
%204 = load i32, i32* %16
%205 = sext i32 %204 to i64
%206 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 %205
store i8 %203, i8* %206
br label %207
207: ; preds = %199
%208 = load i32, i32* %16
%209 = add nsw i32 %208, 1
store i32 %209, i32* %16
br label %196
210: ; preds = %196
br label %211
211: ; preds = %210, %135
br label %212
212: ; preds = %211, %101, %89
br label %213
213: ; preds = %212, %77
store i32 -1, i32* %15
br label %77
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@F_SETFL = global i32 0
@FNDELAY = 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
@ISIG = global i32 0
@TCSANOW = global i32 0
@.str = [5 x i8] c"S11\0D\00"
@.str.1 = [5 x i8] c"S14\0D\00"
@.str.2 = [8 x i8] c"scanner\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [6 x i8] c"scale\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = alloca [12 x i8]
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%6 = alloca [9 x i8]
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%8 = alloca %struct.termios
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%13 = bitcast %struct.termios* %8 to i8*
%14 = tail call i32 (...) @open_port()
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* @FNDELAY
%17 = tail call i32 @fcntl(i32 %14, i32 %15, i32 %16)
%18 = call i32 @tcgetattr(i32 %14, %struct.termios* %8)
%19 = load i32, i32* @B9600
%20 = call i32 @cfsetispeed(%struct.termios* %8, i32 %19)
%21 = load i32, i32* @B9600
%22 = call i32 @cfsetospeed(%struct.termios* %8, i32 %21)
%23 = load i32, i32* @CLOCAL
%24 = load i32, i32* @CREAD
%25 = or i32 %24, %23
%26 = getelementptr inbounds %struct.termios, %struct.termios* %8, 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 = or i32 %31, %30
%33 = load i32, i32* @CSTOPB
%34 = load i32, i32* @CSIZE
%35 = or i32 %33, %34
%36 = xor i32 %35, -1
%37 = and i32 %32, %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* @ISIG
%46 = or i32 %44, %45
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 1
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @TCSANOW
%52 = call i32 @tcsetattr(i32 %14, i32 %51, %struct.termios* %8)
%53 = call i32 @write(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 5)
%54 = call i32 @write(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%55 = bitcast [16 x i8]* %1 to i8**
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 1
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 2
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 3
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 4
br label %60
60: ; preds = %88, %0
%61 = phi i32 [ 0, %0 ], [ %71, %88 ]
br label %62
62: ; preds = %60, %62
%63 = call i32 @read(i32 %14, i8** %55, i32 1)
%64 = icmp eq i32 %63, -1
br i1 %64, label %62, label %65
65: ; preds = %62
%66 = load i8, i8* %9
%67 = icmp eq i8 %66, 83
%68 = select i1 %67, i32 0, i32 %61
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %69
store i8 %66, i8* %70
%71 = add nsw i32 %68, 1
%72 = icmp eq i8 %66, 10
%73 = icmp sgt i32 %68, 1
%74 = select i1 %72, i1 %73, i1 false
br i1 %74, label %75, label %88
75: ; preds = %65
%76 = zext i32 %71 to i64
%77 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %76
store i8 0, i8* %77
%78 = load i8, i8* %56
%79 = icmp eq i8 %78, 48
br i1 %79, label %80, label %85
80: ; preds = %75
%81 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%82 = call i32 @fprintf(i32* %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%83 = call i32 @fclose(i32* %81)
%84 = load i8, i8* %56
br label %85
85: ; preds = %80, %75
%86 = phi i8 [ %84, %80 ], [ %78, %75 ]
%87 = icmp eq i8 %86, 49
br i1 %87, label %89, label %88
88: ; preds = %85, %65, %116
br label %60
89: ; preds = %85
%90 = load i8, i8* %57
%91 = icmp eq i8 %90, 49
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 @write(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
br label %116
94: ; preds = %89
%95 = icmp eq i8 %90, 52
%96 = load i8, i8* %58
%97 = icmp eq i8 %96, 51
%98 = select i1 %95, i1 %97, i1 false
br i1 %98, label %99, label %107
99: ; preds = %94
%100 = call i32 @write(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 5)
%101 = call i64 @strcmp(i8* %12, i8* %10)
%102 = icmp eq i64 %101, 0
br i1 %102, label %116, label %103
103: ; preds = %99
%104 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%105 = call i32 @fprintf(i32* %104, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%106 = call i32 @fclose(i32* %104)
br label %116
107: ; preds = %94
br i1 %95, label %108, label %116
108: ; preds = %107
%109 = call i32 @write(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%110 = call i64 @strcmp(i8* %12, i8* %10)
%111 = icmp eq i64 %110, 0
br i1 %111, label %116, label %112
112: ; preds = %108
%113 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%114 = call i32 @fprintf(i32* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%115 = call i32 @fclose(i32* %113)
br label %116
116: ; preds = %103, %99, %108, %112, %107, %92
br label %88
}