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

/* Variables and functions */
scalar_t__ srec_is_head(unsigned char);
scalar_t__ srec_load(unsigned char *);
int xmodem_srec_seqload(unsigned char c) {
  static unsigned char buf[(1 + 1 + 2 + 8 + 64 + 2 + 2 + 1)];
  static int index = 0;
  if ((srec_is_head(c) || c == (0x1a)) &&
      (buf[index - 1] == '\r' || buf[index - 1] == '\n')) {
    if (srec_load(buf) < 0) {
      return -1;
    }
    index = 0;
  }
  buf[index++] = c;
  return 0;
}


x86 assembly (clang, -O0):
<xmodem_srec_seqload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%edi
call   1030 <srec_is_head@plt>
cmp    $0x0,%rax
jne    114e <xmodem_srec_seqload+0x2e>
movzbl -0x5(%rbp),%eax
cmp    $0x1a,%eax
jne    11ba <xmodem_srec_seqload+0x9a>
mov    0x2f40(%rip),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2edf(%rip),%rax
movzbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     118e <xmodem_srec_seqload+0x6e>
mov    0x2f20(%rip),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ebf(%rip),%rax
movzbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ba <xmodem_srec_seqload+0x9a>
lea    0x2eab(%rip),%rdi
call   1040 <srec_load@plt>
cmp    $0x0,%rax
jge    11b0 <xmodem_srec_seqload+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <xmodem_srec_seqload+0xc2>
movl   $0x0,0x2eda(%rip)
mov    -0x5(%rbp),%dl
mov    0x2ed1(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2ec6(%rip)
movslq %eax,%rcx
lea    0x2e68(%rip),%rax
mov    %dl,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmodem_srec_seqload>:
push   %rbx
mov    %edi,%ebx
call   1030 <srec_is_head@plt>
mov    0x2f66(%rip),%ecx
cmp    $0x1a,%bl
je     1138 <xmodem_srec_seqload+0x18>
test   %rax,%rax
je     1161 <xmodem_srec_seqload+0x41>
movslq %ecx,%rax
lea    0x2efe(%rip),%rdx
mov    -0x1(%rax,%rdx,1),%al
cmp    $0xd,%al
je     114e <xmodem_srec_seqload+0x2e>
cmp    $0xa,%al
jne    1161 <xmodem_srec_seqload+0x41>
lea    0x2eeb(%rip),%rdi
call   1040 <srec_load@plt>
xor    %ecx,%ecx
test   %rax,%rax
js     117b <xmodem_srec_seqload+0x5b>
lea    0x1(%rcx),%eax
mov    %eax,0x2f2a(%rip)
movslq %ecx,%rax
lea    0x2ecc(%rip),%rcx
mov    %bl,(%rax,%rcx,1)
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@xmodem_srec_seqload.buf = internal global [81 x i8] zeroinitializer
@xmodem_srec_seqload.index = internal global i32 0
define i32 @xmodem_srec_seqload(i8 zeroext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = call i64 @srec_is_head(i8 zeroext %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i8, i8* %3
%9 = zext i8 %8 to i32
%10 = icmp eq i32 %9, 26
br i1 %10, label %11, label %32
11: ; preds = %7, %1
%12 = load i32, i32* @xmodem_srec_seqload.index
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [81 x i8], [81 x i8]* @xmodem_srec_seqload.buf, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp eq i32 %17, 13
br i1 %18, label %27, label %19
19: ; preds = %11
%20 = load i32, i32* @xmodem_srec_seqload.index
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [81 x i8], [81 x i8]* @xmodem_srec_seqload.buf, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %32
27: ; preds = %19, %11
%28 = call i64 @srec_load(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @xmodem_srec_seqload.buf, i64 0, i64 0))
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 -1, i32* %2
br label %38
31: ; preds = %27
store i32 0, i32* @xmodem_srec_seqload.index
br label %32
32: ; preds = %31, %19, %7
%33 = load i8, i8* %3
%34 = load i32, i32* @xmodem_srec_seqload.index
%35 = add nsw i32 %34, 1
store i32 %35, i32* @xmodem_srec_seqload.index
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds [81 x i8], [81 x i8]* @xmodem_srec_seqload.buf, i64 0, i64 %36
store i8 %33, i8* %37
store i32 0, i32* %2
br label %38
38: ; preds = %32, %30
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@xmodem_srec_seqload.buf = internal global [81 x i8] zeroinitializer
@xmodem_srec_seqload.index = internal unnamed_addr global i32 0
define i32 @xmodem_srec_seqload(i8 zeroext %0) {
%2 = tail call i64 @srec_is_head(i8 zeroext %0)
%3 = icmp ne i64 %2, 0
%4 = icmp eq i8 %0, 26
%5 = or i1 %4, %3
%6 = load i32, i32* @xmodem_srec_seqload.index
br i1 %5, label %7, label %15
7: ; preds = %1
%8 = add nsw i32 %6, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [81 x i8], [81 x i8]* @xmodem_srec_seqload.buf, i64 0, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %15 [
i8 13, label %12
i8 10, label %12
]
12: ; preds = %7, %7
%13 = tail call i64 @srec_load(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @xmodem_srec_seqload.buf, i64 0, i64 0))
%14 = icmp slt i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12, %1, %7
%16 = phi i32 [ %6, %7 ], [ %6, %1 ], [ 0, %12 ]
%17 = add nsw i32 %16, 1
store i32 %17, i32* @xmodem_srec_seqload.index
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds [81 x i8], [81 x i8]* @xmodem_srec_seqload.buf, i64 0, i64 %18
store i8 %0, i8* %19
br label %20
20: ; preds = %12, %15
%21 = phi i32 [ 0, %15 ], [ -1, %12 ]
ret i32 %21
}