#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 */
int readbytefrommem(unsigned char **);
int readRLEbyte(unsigned char **memptr, int *bytebuff) {
  int rleprefix = -1;
  for (;;) {
    *bytebuff = readbytefrommem(memptr);
    if (*bytebuff < 0)
      return (-1);
    if ((*bytebuff >= '0') && (*bytebuff <= '9')) {
      if (rleprefix > 0) {
        rleprefix *= 10;
      } else {
        rleprefix = 0;
      }
      rleprefix += (*bytebuff - '0');
    } else {
      break;
    }
  }
  if (rleprefix < 0)
    rleprefix = 1;
  return (rleprefix);
}


x86 assembly (clang, -O0):
<readRLEbyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <readbytefrommem@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1151 <readRLEbyte+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <readRLEbyte+0xad>
mov    -0x18(%rbp),%rax
cmpl   $0x30,(%rax)
jl     119c <readRLEbyte+0x8c>
mov    -0x18(%rbp),%rax
cmpl   $0x39,(%rax)
jg     119c <readRLEbyte+0x8c>
cmpl   $0x0,-0x1c(%rbp)
jle    1181 <readRLEbyte+0x71>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <readRLEbyte+0x78>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x30,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11a1 <readRLEbyte+0x91>
jmp    11a6 <readRLEbyte+0x96>
jmp    1127 <readRLEbyte+0x17>
cmpl   $0x0,-0x1c(%rbp)
jge    11b7 <readRLEbyte+0xa7>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readRLEbyte>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <readbytefrommem@plt>
mov    %eax,(%r14)
test   %eax,%eax
js     1156 <readRLEbyte+0x46>
mov    $0xffffffff,%ebx
xor    %ebp,%ebp
add    $0xffffffd0,%eax
cmp    $0x9,%eax
ja     115d <readRLEbyte+0x4d>
lea    (%rbx,%rbx,1),%ecx
test   %ebx,%ebx
lea    (%rcx,%rcx,4),%ecx
cmovle %ebp,%ecx
mov    %eax,%ebx
add    %ecx,%ebx
mov    %r15,%rdi
call   1030 <readbytefrommem@plt>
mov    %eax,(%r14)
test   %eax,%eax
jns    1130 <readRLEbyte+0x20>
mov    $0xffffffff,%eax
jmp    1167 <readRLEbyte+0x57>
test   %ebx,%ebx
mov    $0x1,%eax
cmovns %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readRLEbyte(i8** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 -1, i32* %6
br label %7
7: ; preds = %37, %2
%8 = load i8**, i8*** %4
%9 = call i32 @readbytefrommem(i8** %8)
%10 = load i32*, i32** %5
store i32 %9, i32* %10
%11 = load i32*, i32** %5
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %7
store i32 -1, i32* %3
br label %44
15: ; preds = %7
%16 = load i32*, i32** %5
%17 = load i32, i32* %16
%18 = icmp sge i32 %17, 48
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = icmp sle i32 %21, 57
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %6
%28 = mul nsw i32 %27, 10
store i32 %28, i32* %6
br label %30
29: ; preds = %23
store i32 0, i32* %6
br label %30
30: ; preds = %29, %26
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = sub nsw i32 %32, 48
%34 = load i32, i32* %6
%35 = add nsw i32 %34, %33
store i32 %35, i32* %6
br label %37
36: ; preds = %19, %15
br label %38
37: ; preds = %30
br label %7
38: ; preds = %36
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 1, i32* %6
br label %42
42: ; preds = %41, %38
%43 = load i32, i32* %6
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %14
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @readRLEbyte(i8** %0, i32* nocapture %1) {
%3 = tail call i32 @readbytefrommem(i8** %0)
store i32 %3, i32* %1
%4 = icmp slt i32 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %10
%6 = phi i32 [ %15, %10 ], [ %3, %2 ]
%7 = phi i32 [ %14, %10 ], [ -1, %2 ]
%8 = add nsw i32 %6, -48
%9 = icmp ult i32 %8, 10
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = icmp sgt i32 %7, 0
%12 = mul nsw i32 %7, 10
%13 = select i1 %11, i32 %12, i32 0
%14 = add nsw i32 %8, %13
%15 = tail call i32 @readbytefrommem(i8** %0)
store i32 %15, i32* %1
%16 = icmp slt i32 %15, 0
br i1 %16, label %20, label %5
17: ; preds = %5
%18 = icmp slt i32 %7, 0
%19 = select i1 %18, i32 1, i32 %7
br label %20
20: ; preds = %10, %2, %17
%21 = phi i32 [ %19, %17 ], [ -1, %2 ], [ -1, %10 ]
ret i32 %21
}