#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(int);
long dprintf_DollarString(char *input, char **end) {
  int number = 0;
  while ((isdigit((int)((unsigned char)*input)))) {
    number *= 10;
    number += *input - '0';
    input++;
  }
  if (number && ('$' == *input++)) {
    *end = input;
    return number;
  }
  return 0;
}


x86 assembly (clang, -O0):
<dprintf_DollarString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1165 <dprintf_DollarString+0x55>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1127 <dprintf_DollarString+0x17>
cmpl   $0x0,-0x1c(%rbp)
je     11a6 <dprintf_DollarString+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%ecx
mov    $0x24,%eax
cmp    %ecx,%eax
jne    11a6 <dprintf_DollarString+0x96>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <dprintf_DollarString+0x9e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dprintf_DollarString>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movzbl (%rdi),%edi
call   1030 <isdigit@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1167 <dprintf_DollarString+0x57>
add    $0x1,%rbx
nop
lea    (%r15,%r15,4),%eax
movsbl -0x1(%rbx),%ecx
lea    (%rcx,%rax,2),%r15d
add    $0xffffffd0,%r15d
movzbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <dprintf_DollarString+0x20>
test   %r15d,%r15d
je     1164 <dprintf_DollarString+0x54>
cmpb   $0x24,-0x1(%rbx)
jne    1164 <dprintf_DollarString+0x54>
mov    %rbx,(%r14)
movslq %r15d,%r15
jmp    1167 <dprintf_DollarString+0x57>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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