#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__ isdigit(unsigned char);
int header_extract_number(const char *header, void *closure) {
  const char *p = header;
  long result;
  for (result = 0; isdigit((unsigned char)(*p)); p++)
    result = 10 * result + (*p - '0');
  if (*p)
    return 0;
  *(long *)closure = result;
  return 1;
}


x86 assembly (clang, -O0):
<header_extract_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1170 <header_extract_number+0x60>
imul   $0xa,-0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <header_extract_number+0x20>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1189 <header_extract_number+0x79>
movl   $0x0,-0x4(%rbp)
jmp    119b <header_extract_number+0x8b>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header_extract_number>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movzbl (%rdi),%edi
call   1030 <isdigit@plt>
xor    %r15d,%r15d
xor    %r12d,%r12d
test   %rax,%rax
je     1162 <header_extract_number+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r12,%r12,4),%rax
movsbq (%rbx),%rcx
lea    (%rcx,%rax,2),%r12
add    $0xffffffffffffffd0,%r12
movzbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1140 <header_extract_number+0x30>
cmpb   $0x0,(%rbx)
jne    1170 <header_extract_number+0x60>
mov    %r12,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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