#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 /*<<< orphan*/);
int /*<<< orphan*/ is_my_file(char const *);
scalar_t__ isdigit(char const);
long number_from_filename(const char *filename) {
  const char *p;
  long num;
  assert(is_my_file(filename));
  p = filename;
  num = 0;
  do {
    num = num * 10 + (*p - '0');
    p++;
  } while (isdigit(*p));
  return num - 1;
}


x86 assembly (clang, -O0):
<number_from_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <is_my_file@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
imul   $0xa,-0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
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    115c <number_from_filename+0x2c>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_from_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <is_my_file@plt>
mov    %eax,%edi
call   1050 <assert@plt>
add    $0x1,%rbx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
lea    (%r14,%r14,4),%rax
movsbq -0x1(%rbx),%rcx
lea    (%rcx,%rax,2),%r14
add    $0xffffffffffffffd0,%r14
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <number_from_filename+0x20>
add    $0xffffffffffffffff,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @number_from_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @is_my_file(i8* %5)
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %2
store i8* %8, i8** %3
store i64 0, i64* %4
br label %9
9: ; preds = %20, %1
%10 = load i64, i64* %4
%11 = mul nsw i64 %10, 10
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = sub nsw i32 %14, 48
%16 = sext i32 %15 to i64
%17 = add nsw i64 %11, %16
store i64 %17, i64* %4
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
br label %20
20: ; preds = %9
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = call i64 @isdigit(i8 signext %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %9, label %25
25: ; preds = %20
%26 = load i64, i64* %4
%27 = sub nsw i64 %26, 1
ret i64 %27
}

LLVM IR (-O2):
define i64 @number_from_filename(i8* %0) {
%2 = tail call i32 @is_my_file(i8* %0)
%3 = tail call i32 @assert(i32 %2)
br label %4
4: ; preds = %4, %1
%5 = phi i8* [ %0, %1 ], [ %12, %4 ]
%6 = phi i64 [ 0, %1 ], [ %11, %4 ]
%7 = mul nsw i64 %6, 10
%8 = load i8, i8* %5
%9 = sext i8 %8 to i64
%10 = add i64 %7, -48
%11 = add i64 %10, %9
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = load i8, i8* %12
%14 = tail call i64 @isdigit(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %4
%17 = add nsw i64 %11, -1
ret i64 %17
}