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

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read_serial_port_timeout(unsigned char *, int, int /*<<< orphan*/ *,
                             double);
scalar_t__ strchr(char *, char);
int /*<<< orphan*/ write_serial_port(unsigned char *, int);
int xmodem_crc(unsigned char *, int);
int xmodem_transmit(const unsigned char *data, int len) {
  char c;
  int r, retry = 0, crc;
  int packet_num, total_packets;
  unsigned char packet[136], buf[16];
  do {
    r = read_serial_port_timeout(buf, sizeof(buf), NULL, 0.1);
    printf("r=%d, c=%d\n", r, c);
    if (r > 0 && strchr((char *)buf, 'C'))
      break;
  } while (++retry < 10);
  if (retry >= 10) {
    return -1;
  }
  printf("Got 'C', starting Xmodem transfer\n");
  total_packets = (len + 127) / 128;
  for (packet_num = 0; packet_num < total_packets; packet_num++) {
    retry = 0;
    packet[0] = 1;
    packet[1] = (packet_num + 1) & 255;
    packet[2] = 255 - packet[1];
    if ((packet_num + 1) * 128 <= len) {
      memcpy(packet + 3, data + packet_num * 128, 128);
    } else {
      memset(packet + 3, 0, 128);
      memcpy(packet + 3, data + packet_num * 128, len - packet_num * 128);
    }
    crc = xmodem_crc(packet + 3, 128);
    packet[131] = (crc >> 8) & 255;
    packet[132] = crc & 255;
    do {
      printf("sending packet #%d\n", packet_num + 1);
      write_serial_port(packet, 133);
      r = read_serial_port_timeout((unsigned char *)&c, 1, NULL, 0.2);
      printf("r=%d, c=%d\n", r, c);
      if (r != 1)
        return -3;
      if (c == 0x06)
        break;
      if (c != 0x15)
        return -4;
    } while (++retry < 10);
    if (retry >= 10) {
      return -2;
    }
  }
  c = 0x04;
  write_serial_port((unsigned char *)&c, 1);
  r = read_serial_port_timeout((unsigned char *)&c, 1, NULL, 0.2);
  return 0;
}


x86 assembly (clang, -O0):
<xmodem_transmit>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0xd0(%rbp),%rdi
mov    $0x10,%esi
xor    %eax,%eax
mov    %eax,%edx
movsd  0xe5f(%rip),%xmm0
call   1070 <read_serial_port_timeout@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
movsbl -0x15(%rbp),%edx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    11e8 <xmodem_transmit+0x78>
lea    -0xd0(%rbp),%rdi
mov    $0x43,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11e8 <xmodem_transmit+0x78>
jmp    11ff <xmodem_transmit+0x8f>
jmp    11ed <xmodem_transmit+0x7d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    $0xa,%eax
jl     1189 <xmodem_transmit+0x19>
cmpl   $0xa,-0x20(%rbp)
jl     1215 <xmodem_transmit+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1435 <xmodem_transmit+0x2c5>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x7f,%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    13ff <xmodem_transmit+0x28f>
movl   $0x0,-0x20(%rbp)
movb   $0x1,-0xc0(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
and    $0xff,%eax
mov    %al,-0xbf(%rbp)
movzbl -0xbf(%rbp),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0xbe(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
shl    $0x7,%eax
cmp    -0x14(%rbp),%eax
jg     12b5 <xmodem_transmit+0x145>
lea    -0xc0(%rbp),%rdi
add    $0x3,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%eax
shl    $0x7,%eax
cltq
add    %rax,%rsi
mov    $0x80,%edx
call   1080 <memcpy@plt>
jmp    12f6 <xmodem_transmit+0x186>
lea    -0xc0(%rbp),%rdi
add    $0x3,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0xc0(%rbp),%rdi
add    $0x3,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%eax
shl    $0x7,%eax
cltq
add    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%eax
shl    $0x7,%eax
sub    %eax,%edx
call   1080 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
add    $0x3,%rdi
mov    $0x80,%esi
call   1090 <xmodem_crc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x3d(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x3c(%rbp)
mov    -0x28(%rbp),%esi
add    $0x1,%esi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x85,%esi
call   1030 <write_serial_port@plt>
lea    -0x15(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
movsd  0xca7(%rip),%xmm0
call   1070 <read_serial_port_timeout@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
movsbl -0x15(%rbp),%edx
lea    0xc99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x1c(%rbp)
je     1394 <xmodem_transmit+0x224>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1435 <xmodem_transmit+0x2c5>
movsbl -0x15(%rbp),%eax
cmp    $0x6,%eax
jne    13a6 <xmodem_transmit+0x236>
jmp    13d6 <xmodem_transmit+0x266>
movsbl -0x15(%rbp),%eax
cmp    $0x15,%eax
je     13bf <xmodem_transmit+0x24f>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1435 <xmodem_transmit+0x2c5>
jmp    13c4 <xmodem_transmit+0x254>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    $0xa,%eax
jl     1327 <xmodem_transmit+0x1b7>
cmpl   $0xa,-0x20(%rbp)
jl     13ec <xmodem_transmit+0x27c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1435 <xmodem_transmit+0x2c5>
jmp    13f1 <xmodem_transmit+0x281>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    123b <xmodem_transmit+0xcb>
movb   $0x4,-0x15(%rbp)
lea    -0x15(%rbp),%rdi
mov    $0x1,%esi
call   1030 <write_serial_port@plt>
lea    -0x15(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
movsd  0xbe2(%rip),%xmm0
call   1070 <read_serial_port_timeout@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmodem_transmit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %esi,%r12d
mov    %rdi,%r13
mov    $0xa,%ebx
lea    0x30(%rsp),%r15
lea    0xe68(%rip),%r14
jmp    11b9 <xmodem_transmit+0x39>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
je     1376 <xmodem_transmit+0x1f6>
mov    %r15,%rdi
mov    $0x10,%esi
xor    %edx,%edx
movsd  0xe35(%rip),%xmm0
call   1080 <read_serial_port_timeout@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
jle    11b0 <xmodem_transmit+0x30>
mov    %r15,%rdi
mov    $0x43,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b0 <xmodem_transmit+0x30>
mov    %r13,0x10(%rsp)
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
lea    0x7f(%r12),%eax
mov    %r12,0x28(%rsp)
lea    0xfe(%r12),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x7,%ecx
xor    %eax,%eax
test   %ecx,%ecx
cmovle %eax,%ecx
lea    0xded(%rip),%r12
xor    %r14d,%r14d
mov    %rcx,0x20(%rsp)
cmp    %rcx,%r14
je     13a1 <xmodem_transmit+0x221>
movb   $0x1,0x40(%rsp)
lea    0x1(%r14),%rdx
mov    %dl,0x41(%rsp)
mov    $0xfe,%al
sub    %r14b,%al
mov    %al,0x42(%rsp)
mov    %rdx,0x18(%rsp)
mov    %edx,%eax
shl    $0x7,%eax
mov    0x28(%rsp),%r15
cmp    %r15d,%eax
jle    12a0 <xmodem_transmit+0x120>
lea    0x43(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
shl    $0x7,%r14
mov    0x10(%rsp),%rax
lea    (%rax,%r14,1),%rsi
mov    %r15d,%edx
sub    %r14d,%edx
mov    %rbx,%rdi
jmp    12b9 <xmodem_transmit+0x139>
cs nopw 0x0(%rax,%rax,1)
shl    $0x7,%r14
add    0x10(%rsp),%r14
lea    0x43(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x80,%edx
call   1090 <memcpy@plt>
lea    0x40(%rsp),%r14
lea    0xf(%rsp),%rbp
mov    %rbx,%rdi
mov    $0x80,%esi
call   10a0 <xmodem_crc@plt>
rol    $0x8,%ax
mov    %ax,0xc3(%rsp)
xor    %r15d,%r15d
lea    0xd25(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    0x18(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x85,%esi
call   1040 <write_serial_port@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %edx,%edx
movsd  0xcea(%rip),%xmm0
call   1080 <read_serial_port_timeout@plt>
mov    %eax,%ebx
movsbl 0xf(%rsp),%edx
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x1,%ebx
jne    1391 <xmodem_transmit+0x211>
movzbl 0xf(%rsp),%eax
cmp    $0x15,%al
jne    1350 <xmodem_transmit+0x1d0>
add    $0x1,%r15d
cmp    $0xa,%r15d
jne    12f0 <xmodem_transmit+0x170>
jmp    1399 <xmodem_transmit+0x219>
mov    $0xfffffffc,%r13d
cmp    $0x6,%al
mov    0x20(%rsp),%rcx
jne    137c <xmodem_transmit+0x1fc>
mov    $0xfffffffe,%r13d
mov    0x18(%rsp),%r14
cmp    $0x9,%r15d
jbe    1237 <xmodem_transmit+0xb7>
jmp    137c <xmodem_transmit+0x1fc>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xfffffffd,%r13d
jmp    137c <xmodem_transmit+0x1fc>
mov    $0xfffffffe,%r13d
jmp    137c <xmodem_transmit+0x1fc>
movb   $0x4,0xf(%rsp)
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <write_serial_port@plt>
xor    %r13d,%r13d
movsd  0xc45(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <read_serial_port_timeout@plt>
jmp    137c <xmodem_transmit+0x1fc>

LLVM IR (-O0):
@.str = [12 x i8] c"r=%d, c=%d\0A\00"
@.str.1 = [35 x i8] c"Got 'C', starting Xmodem transfer\0A\00"
@.str.2 = [20 x i8] c"sending packet #%d\0A\00"
define i32 @xmodem_transmit(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [136 x i8]
%13 = alloca [16 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %8
br label %14
14: ; preds = %29, %2
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%16 = call i32 @read_serial_port_timeout(i8* %15, i32 16, i32* null, double 1.000000e-01)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19)
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %14
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%25 = call i64 @strchr(i8* %24, i8 signext 67)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
br label %33
28: ; preds = %23, %14
br label %29
29: ; preds = %28
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
%32 = icmp slt i32 %31, 10
br i1 %32, label %14, label %33
33: ; preds = %29, %27
%34 = load i32, i32* %8
%35 = icmp sge i32 %34, 10
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 -1, i32* %3
br label %142
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 127
%41 = sdiv i32 %40, 128
store i32 %41, i32* %11
store i32 0, i32* %10
br label %42
42: ; preds = %136, %37
%43 = load i32, i32* %10
%44 = load i32, i32* %11
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %139
46: ; preds = %42
store i32 0, i32* %8
%47 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 0
store i8 1, i8* %47
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
%50 = and i32 %49, 255
%51 = trunc i32 %50 to i8
%52 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 1
store i8 %51, i8* %52
%53 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 1
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = sub nsw i32 255, %55
%57 = trunc i32 %56 to i8
%58 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 2
store i8 %57, i8* %58
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
%61 = mul nsw i32 %60, 128
%62 = load i32, i32* %5
%63 = icmp sle i32 %61, %62
br i1 %63, label %64, label %73
64: ; preds = %46
%65 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 0
%66 = getelementptr inbounds i8, i8* %65, i64 3
%67 = load i8*, i8** %4
%68 = load i32, i32* %10
%69 = mul nsw i32 %68, 128
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %67, i64 %70
%72 = call i32 @memcpy(i8* %66, i8* %71, i32 128)
br label %89
73: ; preds = %46
%74 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 0
%75 = getelementptr inbounds i8, i8* %74, i64 3
%76 = call i32 @memset(i8* %75, i32 0, i32 128)
%77 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 0
%78 = getelementptr inbounds i8, i8* %77, i64 3
%79 = load i8*, i8** %4
%80 = load i32, i32* %10
%81 = mul nsw i32 %80, 128
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %79, i64 %82
%84 = load i32, i32* %5
%85 = load i32, i32* %10
%86 = mul nsw i32 %85, 128
%87 = sub nsw i32 %84, %86
%88 = call i32 @memcpy(i8* %78, i8* %83, i32 %87)
br label %89
89: ; preds = %73, %64
%90 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 0
%91 = getelementptr inbounds i8, i8* %90, i64 3
%92 = call i32 @xmodem_crc(i8* %91, i32 128)
store i32 %92, i32* %9
%93 = load i32, i32* %9
%94 = ashr i32 %93, 8
%95 = and i32 %94, 255
%96 = trunc i32 %95 to i8
%97 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 131
store i8 %96, i8* %97
%98 = load i32, i32* %9
%99 = and i32 %98, 255
%100 = trunc i32 %99 to i8
%101 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 132
store i8 %100, i8* %101
br label %102
102: ; preds = %127, %89
%103 = load i32, i32* %10
%104 = add nsw i32 %103, 1
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %104)
%106 = getelementptr inbounds [136 x i8], [136 x i8]* %12, i64 0, i64 0
%107 = call i32 @write_serial_port(i8* %106, i32 133)
%108 = call i32 @read_serial_port_timeout(i8* %6, i32 1, i32* null, double 2.000000e-01)
store i32 %108, i32* %7
%109 = load i32, i32* %7
%110 = load i8, i8* %6
%111 = sext i8 %110 to i32
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %109, i32 %111)
%113 = load i32, i32* %7
%114 = icmp ne i32 %113, 1
br i1 %114, label %115, label %116
115: ; preds = %102
store i32 -3, i32* %3
br label %142
116: ; preds = %102
%117 = load i8, i8* %6
%118 = sext i8 %117 to i32
%119 = icmp eq i32 %118, 6
br i1 %119, label %120, label %121
120: ; preds = %116
br label %131
121: ; preds = %116
%122 = load i8, i8* %6
%123 = sext i8 %122 to i32
%124 = icmp ne i32 %123, 21
br i1 %124, label %125, label %126
125: ; preds = %121
store i32 -4, i32* %3
br label %142
126: ; preds = %121
br label %127
127: ; preds = %126
%128 = load i32, i32* %8
%129 = add nsw i32 %128, 1
store i32 %129, i32* %8
%130 = icmp slt i32 %129, 10
br i1 %130, label %102, label %131
131: ; preds = %127, %120
%132 = load i32, i32* %8
%133 = icmp sge i32 %132, 10
br i1 %133, label %134, label %135
134: ; preds = %131
store i32 -2, i32* %3
br label %142
135: ; preds = %131
br label %136
136: ; preds = %135
%137 = load i32, i32* %10
%138 = add nsw i32 %137, 1
store i32 %138, i32* %10
br label %42
139: ; preds = %42
store i8 4, i8* %6
%140 = call i32 @write_serial_port(i8* %6, i32 1)
%141 = call i32 @read_serial_port_timeout(i8* %6, i32 1, i32* null, double 2.000000e-01)
store i32 %141, i32* %7
store i32 0, i32* %3
br label %142
142: ; preds = %139, %134, %125, %115, %36
%143 = load i32, i32* %3
ret i32 %143
}

LLVM IR (-O2):
@.str = [12 x i8] c"r=%d, c=%d\0A\00"
@.str.2 = [20 x i8] c"sending packet #%d\0A\00"
@str = [34 x i8] c"Got 'C', starting Xmodem transfer\00"
define i32 @xmodem_transmit(i8* %0, i32 %1) {
%3 = alloca i8
%4 = alloca [136 x i8]
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [136 x i8], [136 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
br label %8
8: ; preds = %16, %2
%9 = phi i32 [ 0, %2 ], [ %17, %16 ]
%10 = call i32 @read_serial_port_timeout(i8* %7, i32 16, i32* null, double 1.000000e-01)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10, i32 0)
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i64 @strchr(i8* %7, i8 signext 67)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8, %13
%17 = add nuw nsw i32 %9, 1
%18 = icmp eq i32 %17, 10
br i1 %18, label %77, label %8
19: ; preds = %13
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%21 = add nsw i32 %1, 127
%22 = sdiv i32 %21, 128
%23 = getelementptr inbounds [136 x i8], [136 x i8]* %4, i64 0, i64 1
%24 = getelementptr inbounds [136 x i8], [136 x i8]* %4, i64 0, i64 2
%25 = getelementptr inbounds [136 x i8], [136 x i8]* %4, i64 0, i64 3
%26 = getelementptr inbounds [136 x i8], [136 x i8]* %4, i64 0, i64 131
%27 = getelementptr inbounds [136 x i8], [136 x i8]* %4, i64 0, i64 132
%28 = call i32 @llvm.smax.i32(i32 %22, i32 0)
%29 = zext i32 %28 to i64
br label %30
30: ; preds = %72, %19
%31 = phi i64 [ %34, %72 ], [ 0, %19 ]
%32 = icmp eq i64 %31, %29
br i1 %32, label %74, label %33
33: ; preds = %30
store i8 1, i8* %6
%34 = add nuw nsw i64 %31, 1
%35 = trunc i64 %34 to i32
%36 = trunc i64 %34 to i8
store i8 %36, i8* %23
%37 = trunc i64 %31 to i8
%38 = sub i8 -2, %37
store i8 %38, i8* %24
%39 = trunc i64 %34 to i32
%40 = shl i32 %39, 7
%41 = icmp sgt i32 %40, %1
br i1 %41, label %46, label %42
42: ; preds = %33
%43 = shl nsw i64 %31, 7
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = call i32 @memcpy(i8* %25, i8* %44, i32 128)
br label %53
46: ; preds = %33
%47 = call i32 @memset(i8* %25, i32 0, i32 128)
%48 = shl nsw i64 %31, 7
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = trunc i64 %48 to i32
%51 = sub i32 %1, %50
%52 = call i32 @memcpy(i8* %25, i8* %49, i32 %51)
br label %53
53: ; preds = %46, %42
%54 = call i32 @xmodem_crc(i8* %25, i32 128)
%55 = lshr i32 %54, 8
%56 = trunc i32 %55 to i8
store i8 %56, i8* %26
%57 = trunc i32 %54 to i8
store i8 %57, i8* %27
br label %58
58: ; preds = %69, %53
%59 = phi i32 [ 0, %53 ], [ %70, %69 ]
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%61 = call i32 @write_serial_port(i8* %6, i32 133)
%62 = call i32 @read_serial_port_timeout(i8* %3, i32 1, i32* null, double 2.000000e-01)
%63 = load i8, i8* %3
%64 = sext i8 %63 to i32
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %62, i32 %64)
%66 = icmp eq i32 %62, 1
br i1 %66, label %67, label %77
67: ; preds = %58
%68 = load i8, i8* %3
switch i8 %68, label %77 [
i8 6, label %72
i8 21, label %69
]
69: ; preds = %67
%70 = add nuw nsw i32 %59, 1
%71 = icmp eq i32 %70, 10
br i1 %71, label %77, label %58
72: ; preds = %67
%73 = icmp ugt i32 %59, 9
br i1 %73, label %77, label %30
74: ; preds = %30
store i8 4, i8* %3
%75 = call i32 @write_serial_port(i8* %3, i32 1)
%76 = call i32 @read_serial_port_timeout(i8* %3, i32 1, i32* null, double 2.000000e-01)
br label %77
77: ; preds = %16, %72, %69, %67, %58, %74
%78 = phi i32 [ 0, %74 ], [ -2, %69 ], [ -4, %67 ], [ -3, %58 ], [ -2, %72 ], [ -1, %16 ]
ret i32 %78
}