#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 /*<<< orphan*/ assert(int);
scalar_t__ isdigit(char const);
const char *__read_string_len(const char *sp, int *slen) {
  *slen = 0;
  if (!isdigit(*sp))
    return NULL;
  do {
    *slen *= 10;
    *slen += *sp - '0';
    sp++;
  } while (isdigit(*sp));
  assert(*sp == ':');
  assert(0 <= *slen);
  return sp + 1;
}


x86 assembly (clang, -O0):
<__read_string_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    115d <__read_string_len+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <__read_string_len+0xb7>
jmp    1162 <__read_string_len+0x42>
mov    -0x18(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    1162 <__read_string_len+0x42>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__read_string_len>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rsi)
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1196 <__read_string_len+0x76>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %eax,(%r14)
movsbl -0x1(%rbx),%ecx
add    %ecx,%eax
add    $0xffffffd0,%eax
mov    %eax,(%r14)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <__read_string_len+0x30>
xor    %edi,%edi
cmpb   $0x3a,-0x1(%rbx)
sete   %dil
call   1040 <assert@plt>
mov    (%r14),%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
jmp    1198 <__read_string_len+0x78>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @__read_string_len(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i32*, i32** %5
store i32 0, i32* %6
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = call i64 @isdigit(i8 signext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i8* null, i8** %3
br label %45
12: ; preds = %2
br label %13
13: ; preds = %26, %12
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = mul nsw i32 %15, 10
store i32 %16, i32* %14
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 48
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = add nsw i32 %22, %20
store i32 %23, i32* %21
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
br label %26
26: ; preds = %13
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = call i64 @isdigit(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %13, label %31
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 58
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32*, i32** %5
%39 = load i32, i32* %38
%40 = icmp sle i32 0, %39
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8* %44, i8** %3
br label %45
45: ; preds = %31, %11
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
define i8* @__read_string_len(i8* %0, i32* nocapture %1) {
store i32 0, i32* %1
%3 = load i8, i8* %0
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %14, %6 ], [ %0, %2 ]
%8 = load i32, i32* %1
%9 = mul nsw i32 %8, 10
store i32 %9, i32* %1
%10 = load i8, i8* %7
%11 = sext i8 %10 to i32
%12 = add i32 %9, -48
%13 = add i32 %12, %11
store i32 %13, i32* %1
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = load i8, i8* %14
%16 = tail call i64 @isdigit(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = load i8, i8* %14
%20 = icmp eq i8 %19, 58
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = load i32, i32* %1
%24 = xor i32 %23, -1
%25 = lshr i32 %24, 31
%26 = tail call i32 @assert(i32 %25)
%27 = getelementptr inbounds i8, i8* %7, i64 2
br label %28
28: ; preds = %2, %18
%29 = phi i8* [ %27, %18 ], [ null, %2 ]
ret i8* %29
}