#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(char const);
const char *pf_parse_int_a(const char *fmt, int *val) {
  *val = 0;
  while (isdigit(*fmt)) {
    *val *= 10;
    *val += *fmt++ - '0';
  }
  return fmt;
}


x86 assembly (clang, -O0):
<pf_parse_int_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     116b <pf_parse_int_a+0x5b>
mov    -0x10(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%ecx
sub    $0x30,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    112a <pf_parse_int_a+0x1a>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pf_parse_int_a>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rsi)
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     115d <pf_parse_int_a+0x4d>
xchg   %ax,%ax
mov    (%r14),%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %eax,(%r14)
lea    0x1(%rbx),%r15
movsbl (%rbx),%ecx
add    %ecx,%eax
add    $0xffffffd0,%eax
mov    %eax,(%r14)
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
mov    %r15,%rbx
test   %rax,%rax
jne    1130 <pf_parse_int_a+0x20>
jmp    1160 <pf_parse_int_a+0x50>
mov    %rbx,%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @pf_parse_int_a(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 %18, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %10, %6 ], [ %0, %2 ]
%8 = load i32, i32* %1
%9 = mul nsw i32 %8, 10
store i32 %9, i32* %1
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %7
%12 = sext i8 %11 to i32
%13 = add i32 %9, -48
%14 = add i32 %13, %12
store i32 %14, i32* %1
%15 = load i8, i8* %10
%16 = tail call i64 @isdigit(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %6, %2
%19 = phi i8* [ %0, %2 ], [ %10, %6 ]
ret i8* %19
}