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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
int /*<<< orphan*/ fwrite(unsigned char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned int);
scalar_t__ njDecode(unsigned char *, unsigned int);
int /*<<< orphan*/ njDone();
int njGetHeight();
unsigned char *njGetImage();
int /*<<< orphan*/ njGetImageSize();
int njGetWidth();
int /*<<< orphan*/ njInit();
scalar_t__ njIsColor();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readImage(int, unsigned char *, unsigned int, unsigned int);
int /*<<< orphan*/ readImageDetails(int, unsigned int *, unsigned int *);
int /*<<< orphan*/ sendShot(int, int);
int /*<<< orphan*/ serialClose(int);
int serialOpen(char *, int);
int main() {
  unsigned char buffer[1024] = {0};
  unsigned int picSize = 0;
  unsigned int packNum = 0;
  unsigned int packSize;
  unsigned short int checksum;
  unsigned int width, height;
  unsigned int i, j;
  unsigned char bytes[2];
  unsigned char image[160][120];
  int fd = serialOpen("/dev/ttyUSB1", 115200);
  FILE *filefd = fopen("./image.ppm", "w");
  unsigned char *bufptr;
  sendShot(fd, 0x31);
  readImageDetails(fd, &picSize, &packNum);
  printf("size: %d\npackets count: %d\n", picSize, packNum);
  unsigned char *imgBuffer =
      (unsigned char *)malloc((picSize + 1) * sizeof(unsigned char));
  readImage(fd, imgBuffer, picSize, packNum);
  serialClose(fd);
  njInit();
  if (njDecode(imgBuffer, picSize)) {
    printf("Error decoding the input file.\n");
    return 1;
  }
  printf("size:\n%d %d\n", njGetWidth(), njGetHeight());
  fprintf(filefd, "P%d\n%d %d\n255\n", njIsColor() ? 6 : 5, njGetWidth(),
          njGetHeight());
  width = njGetWidth();
  height = njGetHeight();
  fwrite(njGetImage(), 1, njGetImageSize(), filefd);
  bufptr = njGetImage();
  for (i = 0; i < width; i++) {
    for (j = 0; j < height; j++) {
      image[i][j] = (char)((0.21 * (double)bufptr[(i + j * width) * 3]) +
                           0.72 * (double)bufptr[(i + j * width) * 3 + 1] +
                           0.07 * (double)bufptr[(i + j * width) * 3 + 2]);
    }
  }
  for (j = 0; j < height; j++) {
    for (i = 0; i < width; i++) {
      if (image[i][j] < 63)
        printf("@");
      else if (image[i][j] < 128)
        printf("*");
      else if (image[i][j] < 191)
        printf("+");
      else
        printf("-");
    }
    printf("\n");
  }
  fclose(filefd);
  njDone();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4f80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
movl   $0x0,-0x414(%rbp)
movl   $0x0,-0x418(%rbp)
lea    0xd98(%rip),%rdi
mov    $0x1c200,%esi
call   1030 <serialOpen@plt>
mov    %eax,-0x4f44(%rbp)
lea    0xd8e(%rip),%rdi
lea    0xd93(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x4f50(%rbp)
mov    -0x4f44(%rbp),%edi
mov    $0x31,%esi
call   1100 <sendShot@plt>
mov    -0x4f44(%rbp),%edi
lea    -0x414(%rbp),%rsi
lea    -0x418(%rbp),%rdx
call   1110 <readImageDetails@plt>
mov    -0x414(%rbp),%esi
mov    -0x418(%rbp),%edx
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x4f60(%rbp)
mov    -0x4f44(%rbp),%edi
mov    -0x4f60(%rbp),%rsi
mov    -0x414(%rbp),%edx
mov    -0x418(%rbp),%ecx
call   1070 <readImage@plt>
mov    -0x4f44(%rbp),%edi
call   1040 <serialClose@plt>
mov    $0x0,%al
call   1090 <njInit@plt>
mov    -0x4f60(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   10c0 <njDecode@plt>
cmp    $0x0,%rax
je     1370 <main+0x130>
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16a5 <main+0x465>
mov    $0x0,%al
call   1160 <njGetWidth@plt>
mov    %eax,-0x4f7c(%rbp)
mov    $0x0,%al
call   1060 <njGetHeight@plt>
mov    -0x4f7c(%rbp),%esi
mov    %eax,%edx
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x4f50(%rbp),%rax
mov    %rax,-0x4f78(%rbp)
mov    $0x0,%al
call   1150 <njIsColor@plt>
mov    %rax,%rdx
mov    $0x5,%eax
mov    $0x6,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4f70(%rbp)
mov    $0x0,%al
call   1160 <njGetWidth@plt>
mov    %eax,-0x4f6c(%rbp)
mov    $0x0,%al
call   1060 <njGetHeight@plt>
mov    -0x4f78(%rbp),%rdi
mov    -0x4f70(%rbp),%edx
mov    -0x4f6c(%rbp),%ecx
mov    %eax,%r8d
lea    0xc82(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x0,%al
call   1160 <njGetWidth@plt>
mov    %eax,-0x424(%rbp)
mov    $0x0,%al
call   1060 <njGetHeight@plt>
mov    %eax,-0x428(%rbp)
mov    $0x0,%al
call   1050 <njGetImage@plt>
mov    %rax,-0x4f68(%rbp)
mov    $0x0,%al
call   10f0 <njGetImageSize@plt>
mov    -0x4f68(%rbp),%rdi
mov    %eax,%edx
mov    -0x4f50(%rbp),%rcx
mov    $0x1,%esi
call   1140 <fwrite@plt>
mov    $0x0,%al
call   1050 <njGetImage@plt>
mov    %rax,-0x4f58(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x424(%rbp),%eax
jae    154f <main+0x30f>
movl   $0x0,-0x430(%rbp)
mov    -0x430(%rbp),%eax
cmp    -0x428(%rbp),%eax
jae    1536 <main+0x2f6>
mov    -0x4f58(%rbp),%rax
mov    -0x42c(%rbp),%edx
mov    -0x430(%rbp),%ecx
mov    -0x424(%rbp),%esi
imul   %esi,%ecx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%edx
movzbl (%rax,%rdx,1),%edx
cvtsi2sd %edx,%xmm1
lea    0x1(%rcx,%rcx,2),%edx
movzbl (%rax,%rdx,1),%edx
cvtsi2sd %edx,%xmm0
movsd  0xb33(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xb2f(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
lea    0x2(%rcx,%rcx,2),%ecx
movzbl (%rax,%rcx,1),%eax
cvtsi2sd %eax,%xmm0
movsd  0xb1b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%dl
mov    -0x42c(%rbp),%eax
mov    %eax,%ecx
lea    -0x4f40(%rbp),%rax
imul   $0x78,%rcx,%rcx
add    %rcx,%rax
mov    -0x430(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    147c <main+0x23c>
jmp    153b <main+0x2fb>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1460 <main+0x220>
movl   $0x0,-0x430(%rbp)
mov    -0x430(%rbp),%eax
cmp    -0x428(%rbp),%eax
jae    1692 <main+0x452>
movl   $0x0,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x424(%rbp),%eax
jae    1670 <main+0x430>
mov    -0x42c(%rbp),%eax
mov    %eax,%ecx
lea    -0x4f40(%rbp),%rax
imul   $0x78,%rcx,%rcx
add    %rcx,%rax
mov    -0x430(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x3f,%eax
jge    15c3 <main+0x383>
lea    0xad4(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1657 <main+0x417>
mov    -0x42c(%rbp),%eax
mov    %eax,%ecx
lea    -0x4f40(%rbp),%rax
imul   $0x78,%rcx,%rcx
add    %rcx,%rax
mov    -0x430(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x80,%eax
jge    1601 <main+0x3c1>
lea    0xa98(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1652 <main+0x412>
mov    -0x42c(%rbp),%eax
mov    %eax,%ecx
lea    -0x4f40(%rbp),%rax
imul   $0x78,%rcx,%rcx
add    %rcx,%rax
mov    -0x430(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0xbf,%eax
jge    163f <main+0x3ff>
lea    0xa5c(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    164d <main+0x40d>
lea    0xa4b(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1652 <main+0x412>
jmp    1657 <main+0x417>
jmp    165c <main+0x41c>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1575 <main+0x335>
lea    0x9f6(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    1559 <main+0x319>
mov    -0x4f50(%rbp),%rdi
call   1080 <fclose@plt>
mov    $0x0,%al
call   1130 <njDone@plt>
mov    -0x4(%rbp),%eax
add    $0x4f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4b18,%rsp
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xda1(%rip),%rdi
mov    $0x1c200,%esi
call   1040 <serialOpen@plt>
mov    %eax,%ebx
lea    0xd9b(%rip),%rdi
lea    0xda0(%rip),%rsi
call   1130 <fopen@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    $0x31,%esi
call   1110 <sendShot@plt>
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1120 <readImageDetails@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xd71(%rip),%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    (%rsp),%edi
add    $0x1,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbp
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
mov    %rax,%rsi
call   1090 <readImage@plt>
mov    %ebx,%edi
call   1050 <serialClose@plt>
xor    %eax,%eax
call   10b0 <njInit@plt>
mov    (%rsp),%esi
mov    %rbp,%rdi
call   10d0 <njDecode@plt>
test   %rax,%rax
je     131c <main+0xcc>
lea    0xd5e(%rip),%rdi
call   1070 <puts@plt>
mov    $0x1,%ebx
jmp    14f7 <main+0x2a7>
xor    %eax,%eax
call   1170 <njGetWidth@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <njGetHeight@plt>
lea    0xd1c(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   10c0 <printf@plt>
xor    %eax,%eax
call   1160 <njIsColor@plt>
cmp    $0x1,%rax
mov    $0x6,%ebx
sbb    $0x0,%ebx
xor    %eax,%eax
call   1170 <njGetWidth@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <njGetHeight@plt>
lea    0xcf4(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
call   10e0 <fprintf@plt>
xor    %eax,%eax
call   1170 <njGetWidth@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1080 <njGetHeight@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1060 <njGetImage@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1100 <njGetImageSize@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1150 <fwrite@plt>
xor    %eax,%eax
call   1060 <njGetImage@plt>
mov    %r13d,%r15d
mov    %r12d,%r8d
test   %r12d,%r12d
je     1462 <main+0x212>
lea    (%r12,%r12,2),%edx
lea    0x10(%rsp),%rsi
mov    $0x2,%r9d
xor    %ebp,%ebp
movsd  0xc23(%rip),%xmm0
movsd  0xc23(%rip),%xmm1
movsd  0xc23(%rip),%xmm2
jmp    1401 <main+0x1b1>
nop
add    $0x1,%rbp
add    $0x78,%rsi
add    $0x3,%r9d
cmp    %r8,%rbp
je     1462 <main+0x212>
test   %r13d,%r13d
je     13f0 <main+0x1a0>
mov    %r9d,%ebx
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%edi
movzbl (%rax,%rdi,1),%edi
xorps  %xmm3,%xmm3
cvtsi2sd %edi,%xmm3
lea    -0x1(%rbx),%edi
movzbl (%rax,%rdi,1),%edi
xorps  %xmm4,%xmm4
cvtsi2sd %edi,%xmm4
mulsd  %xmm0,%xmm4
mulsd  %xmm1,%xmm3
addsd  %xmm4,%xmm3
mov    %ebx,%edi
movzbl (%rax,%rdi,1),%edi
xorps  %xmm4,%xmm4
cvtsi2sd %edi,%xmm4
mulsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
cvttsd2si %xmm4,%edi
mov    %dil,(%rsi,%rcx,1)
add    $0x1,%rcx
add    %edx,%ebx
cmp    %rcx,%r15
jne    1410 <main+0x1c0>
jmp    13f0 <main+0x1a0>
mov    %r14,0x8(%rsp)
test   %r13d,%r13d
je     14e4 <main+0x294>
imul   $0x78,%r8,%rbp
lea    0x10(%rsp),%rbx
xor    %r13d,%r13d
jmp    1497 <main+0x247>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13
add    $0x1,%rbx
cmp    %r15,%r13
je     14e4 <main+0x294>
test   %r12d,%r12d
je     1480 <main+0x230>
xor    %r14d,%r14d
jmp    14be <main+0x26e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <putchar@plt>
add    $0x78,%r14
cmp    %r14,%rbp
je     1480 <main+0x230>
movzbl (%rbx,%r14,1),%eax
mov    $0x40,%edi
cmp    $0x3f,%al
jb     14b0 <main+0x260>
mov    $0x2a,%edi
test   %al,%al
jns    14b0 <main+0x260>
xor    %ecx,%ecx
cmp    $0xbf,%al
setae  %cl
lea    (%rcx,%rcx,1),%edi
add    $0x2b,%edi
jmp    14b0 <main+0x260>
mov    0x8(%rsp),%rdi
call   10a0 <fclose@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1140 <njDone@plt>
mov    %ebx,%eax
add    $0x4b18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB1\00"
@.str.1 = [12 x i8] c"./image.ppm\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"size: %d\0Apackets count: %d\0A\00"
@.str.4 = [32 x i8] c"Error decoding the input file.\0A\00"
@.str.5 = [13 x i8] c"size:\0A%d %d\0A\00"
@.str.6 = [15 x i8] c"P%d\0A%d %d\0A255\0A\00"
@.str.7 = [2 x i8] c"@\00"
@.str.8 = [2 x i8] c"*\00"
@.str.9 = [2 x i8] c"+\00"
@.str.10 = [2 x i8] c"-\00"
@.str.11 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2 x i8]
%12 = alloca [160 x [120 x i8]]
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i8*
store i32 0, i32* %1
%17 = bitcast [1024 x i8]* %2 to i8*
store i32 0, i32* %3
store i32 0, i32* %4
%18 = call i32 @serialOpen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 115200)
store i32 %18, i32* %13
%19 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %14
%20 = load i32, i32* %13
%21 = call i32 @sendShot(i32 %20, i32 49)
%22 = load i32, i32* %13
%23 = call i32 @readImageDetails(i32 %22, i32* %3, i32* %4)
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32, i32* %3
%28 = add i32 %27, 1
%29 = zext i32 %28 to i64
%30 = mul i64 %29, 1
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %16
%34 = load i32, i32* %13
%35 = load i8*, i8** %16
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = call i32 @readImage(i32 %34, i8* %35, i32 %36, i32 %37)
%39 = load i32, i32* %13
%40 = call i32 @serialClose(i32 %39)
%41 = call i32 (...) @njInit()
%42 = load i8*, i8** %16
%43 = load i32, i32* %3
%44 = call i64 @njDecode(i8* %42, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %192
48: ; preds = %0
%49 = call i32 (...) @njGetWidth()
%50 = call i32 (...) @njGetHeight()
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50)
%52 = load i32*, i32** %14
%53 = call i64 (...) @njIsColor()
%54 = icmp ne i64 %53, 0
%55 = zext i1 %54 to i64
%56 = select i1 %54, i32 6, i32 5
%57 = call i32 (...) @njGetWidth()
%58 = call i32 (...) @njGetHeight()
%59 = call i32 @fprintf(i32* %52, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %56, i32 %57, i32 %58)
%60 = call i32 (...) @njGetWidth()
store i32 %60, i32* %7
%61 = call i32 (...) @njGetHeight()
store i32 %61, i32* %8
%62 = call i8* (...) @njGetImage()
%63 = call i32 (...) @njGetImageSize()
%64 = load i32*, i32** %14
%65 = call i32 @fwrite(i8* %62, i32 1, i32 %63, i32* %64)
%66 = call i8* (...) @njGetImage()
store i8* %66, i8** %15
store i32 0, i32* %9
br label %67
67: ; preds = %126, %48
%68 = load i32, i32* %9
%69 = load i32, i32* %7
%70 = icmp ult i32 %68, %69
br i1 %70, label %71, label %129
71: ; preds = %67
store i32 0, i32* %10
br label %72
72: ; preds = %122, %71
%73 = load i32, i32* %10
%74 = load i32, i32* %8
%75 = icmp ult i32 %73, %74
br i1 %75, label %76, label %125
76: ; preds = %72
%77 = load i8*, i8** %15
%78 = load i32, i32* %9
%79 = load i32, i32* %10
%80 = load i32, i32* %7
%81 = mul i32 %79, %80
%82 = add i32 %78, %81
%83 = mul i32 %82, 3
%84 = zext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %77, i64 %84
%86 = load i8, i8* %85
%87 = uitofp i8 %86 to double
%88 = load i8*, i8** %15
%89 = load i32, i32* %9
%90 = load i32, i32* %10
%91 = load i32, i32* %7
%92 = mul i32 %90, %91
%93 = add i32 %89, %92
%94 = mul i32 %93, 3
%95 = add i32 %94, 1
%96 = zext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %88, i64 %96
%98 = load i8, i8* %97
%99 = uitofp i8 %98 to double
%100 = fmul double 0x3FE70A3D70A3D70A, %99
%101 = call double @llvm.fmuladd.f64(double 2.100000e-01, double %87, double %100)
%102 = load i8*, i8** %15
%103 = load i32, i32* %9
%104 = load i32, i32* %10
%105 = load i32, i32* %7
%106 = mul i32 %104, %105
%107 = add i32 %103, %106
%108 = mul i32 %107, 3
%109 = add i32 %108, 2
%110 = zext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %102, i64 %110
%112 = load i8, i8* %111
%113 = uitofp i8 %112 to double
%114 = call double @llvm.fmuladd.f64(double 7.000000e-02, double %113, double %101)
%115 = fptosi double %114 to i8
%116 = load i32, i32* %9
%117 = zext i32 %116 to i64
%118 = getelementptr inbounds [160 x [120 x i8]], [160 x [120 x i8]]* %12, i64 0, i64 %117
%119 = load i32, i32* %10
%120 = zext i32 %119 to i64
%121 = getelementptr inbounds [120 x i8], [120 x i8]* %118, i64 0, i64 %120
store i8 %115, i8* %121
br label %122
122: ; preds = %76
%123 = load i32, i32* %10
%124 = add i32 %123, 1
store i32 %124, i32* %10
br label %72
125: ; preds = %72
br label %126
126: ; preds = %125
%127 = load i32, i32* %9
%128 = add i32 %127, 1
store i32 %128, i32* %9
br label %67
129: ; preds = %67
store i32 0, i32* %10
br label %130
130: ; preds = %185, %129
%131 = load i32, i32* %10
%132 = load i32, i32* %8
%133 = icmp ult i32 %131, %132
br i1 %133, label %134, label %188
134: ; preds = %130
store i32 0, i32* %9
br label %135
135: ; preds = %180, %134
%136 = load i32, i32* %9
%137 = load i32, i32* %7
%138 = icmp ult i32 %136, %137
br i1 %138, label %139, label %183
139: ; preds = %135
%140 = load i32, i32* %9
%141 = zext i32 %140 to i64
%142 = getelementptr inbounds [160 x [120 x i8]], [160 x [120 x i8]]* %12, i64 0, i64 %141
%143 = load i32, i32* %10
%144 = zext i32 %143 to i64
%145 = getelementptr inbounds [120 x i8], [120 x i8]* %142, i64 0, i64 %144
%146 = load i8, i8* %145
%147 = zext i8 %146 to i32
%148 = icmp slt i32 %147, 63
br i1 %148, label %149, label %151
149: ; preds = %139
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %179
151: ; preds = %139
%152 = load i32, i32* %9
%153 = zext i32 %152 to i64
%154 = getelementptr inbounds [160 x [120 x i8]], [160 x [120 x i8]]* %12, i64 0, i64 %153
%155 = load i32, i32* %10
%156 = zext i32 %155 to i64
%157 = getelementptr inbounds [120 x i8], [120 x i8]* %154, i64 0, i64 %156
%158 = load i8, i8* %157
%159 = zext i8 %158 to i32
%160 = icmp slt i32 %159, 128
br i1 %160, label %161, label %163
161: ; preds = %151
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %178
163: ; preds = %151
%164 = load i32, i32* %9
%165 = zext i32 %164 to i64
%166 = getelementptr inbounds [160 x [120 x i8]], [160 x [120 x i8]]* %12, i64 0, i64 %165
%167 = load i32, i32* %10
%168 = zext i32 %167 to i64
%169 = getelementptr inbounds [120 x i8], [120 x i8]* %166, i64 0, i64 %168
%170 = load i8, i8* %169
%171 = zext i8 %170 to i32
%172 = icmp slt i32 %171, 191
br i1 %172, label %173, label %175
173: ; preds = %163
%174 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %177
175: ; preds = %163
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %177
177: ; preds = %175, %173
br label %178
178: ; preds = %177, %161
br label %179
179: ; preds = %178, %149
br label %180
180: ; preds = %179
%181 = load i32, i32* %9
%182 = add i32 %181, 1
store i32 %182, i32* %9
br label %135
183: ; preds = %135
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %185
185: ; preds = %183
%186 = load i32, i32* %10
%187 = add i32 %186, 1
store i32 %187, i32* %10
br label %130
188: ; preds = %130
%189 = load i32*, i32** %14
%190 = call i32 @fclose(i32* %189)
%191 = call i32 (...) @njDone()
br label %192
192: ; preds = %188, %46
%193 = load i32, i32* %1
ret i32 %193
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB1\00"
@.str.1 = [12 x i8] c"./image.ppm\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"size: %d\0Apackets count: %d\0A\00"
@.str.5 = [13 x i8] c"size:\0A%d %d\0A\00"
@.str.6 = [15 x i8] c"P%d\0A%d %d\0A255\0A\00"
@str = [31 x i8] c"Error decoding the input file.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [160 x [120 x i8]]
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = getelementptr inbounds [160 x [120 x i8]], [160 x [120 x i8]]* %3, i64 0, i64 0, i64 0
%7 = tail call i32 @serialOpen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 115200)
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @sendShot(i32 %7, i32 49)
%10 = call i32 @readImageDetails(i32 %7, i32* %1, i32* %2)
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %1
%15 = add i32 %14, 1
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = call i32 @readImage(i32 %7, i8* %17, i32 %18, i32 %19)
%21 = call i32 @serialClose(i32 %7)
%22 = call i32 (...) @njInit()
%23 = load i32, i32* %1
%24 = call i64 @njDecode(i8* %17, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %0
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %112
28: ; preds = %0
%29 = call i32 (...) @njGetWidth()
%30 = call i32 (...) @njGetHeight()
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %29, i32 %30)
%32 = call i64 (...) @njIsColor()
%33 = icmp eq i64 %32, 0
%34 = select i1 %33, i32 5, i32 6
%35 = call i32 (...) @njGetWidth()
%36 = call i32 (...) @njGetHeight()
%37 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
%38 = call i32 (...) @njGetWidth()
%39 = call i32 (...) @njGetHeight()
%40 = call i8* (...) @njGetImage()
%41 = call i32 (...) @njGetImageSize()
%42 = call i32 @fwrite(i8* %40, i32 1, i32 %41, i32* %8)
%43 = call i8* (...) @njGetImage()
%44 = icmp eq i32 %38, 0
br i1 %44, label %53, label %45
45: ; preds = %28
%46 = icmp eq i32 %39, 0
%47 = zext i32 %38 to i64
%48 = zext i32 %39 to i64
br label %49
49: ; preds = %45, %85
%50 = phi i64 [ 0, %45 ], [ %86, %85 ]
br i1 %46, label %85, label %51
51: ; preds = %49
%52 = trunc i64 %50 to i32
br label %58
53: ; preds = %85, %28
%54 = icmp eq i32 %39, 0
br i1 %54, label %109, label %55
55: ; preds = %53
%56 = zext i32 %39 to i64
%57 = zext i32 %38 to i64
br label %88
58: ; preds = %51, %58
%59 = phi i64 [ 0, %51 ], [ %83, %58 ]
%60 = trunc i64 %59 to i32
%61 = mul i32 %38, %60
%62 = add i32 %61, %52
%63 = mul i32 %62, 3
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %43, i64 %64
%66 = load i8, i8* %65
%67 = uitofp i8 %66 to double
%68 = add i32 %63, 1
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %43, i64 %69
%71 = load i8, i8* %70
%72 = uitofp i8 %71 to double
%73 = fmul double %72, 0x3FE70A3D70A3D70A
%74 = call double @llvm.fmuladd.f64(double %67, double 2.100000e-01, double %73)
%75 = add i32 %63, 2
%76 = zext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %43, i64 %76
%78 = load i8, i8* %77
%79 = uitofp i8 %78 to double
%80 = call double @llvm.fmuladd.f64(double %79, double 7.000000e-02, double %74)
%81 = fptosi double %80 to i8
%82 = getelementptr inbounds [160 x [120 x i8]], [160 x [120 x i8]]* %3, i64 0, i64 %50, i64 %59
store i8 %81, i8* %82
%83 = add nuw nsw i64 %59, 1
%84 = icmp eq i64 %83, %48
br i1 %84, label %85, label %58
85: ; preds = %58, %49
%86 = add nuw nsw i64 %50, 1
%87 = icmp eq i64 %86, %47
br i1 %87, label %53, label %49
88: ; preds = %55, %105
%89 = phi i64 [ 0, %55 ], [ %107, %105 ]
br i1 %44, label %105, label %90
90: ; preds = %88, %100
%91 = phi i64 [ %103, %100 ], [ 0, %88 ]
%92 = getelementptr inbounds [160 x [120 x i8]], [160 x [120 x i8]]* %3, i64 0, i64 %91, i64 %89
%93 = load i8, i8* %92
%94 = icmp ult i8 %93, 63
br i1 %94, label %100, label %95
95: ; preds = %90
%96 = icmp sgt i8 %93, -1
br i1 %96, label %100, label %97
97: ; preds = %95
%98 = icmp ult i8 %93, -65
%99 = select i1 %98, i32 43, i32 45
br label %100
100: ; preds = %97, %95, %90
%101 = phi i32 [ 64, %90 ], [ 42, %95 ], [ %99, %97 ]
%102 = call i32 @putchar(i32 %101)
%103 = add nuw nsw i64 %91, 1
%104 = icmp eq i64 %103, %57
br i1 %104, label %105, label %90
105: ; preds = %100, %88
%106 = call i32 @putchar(i32 10)
%107 = add nuw nsw i64 %89, 1
%108 = icmp eq i64 %107, %56
br i1 %108, label %109, label %88
109: ; preds = %105, %53
%110 = call i32 @fclose(i32* %8)
%111 = call i32 (...) @njDone()
br label %112
112: ; preds = %109, %26
%113 = phi i32 [ 1, %26 ], [ 0, %109 ]
ret i32 %113
}