#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*/ CharPhoneMatch(char, char);
scalar_t__ StringIn(char, char *);
StringPhoneMatch(char *ptn, char *s, char *digits, char **nextp) {
  while (*ptn) {
    if (!CharPhoneMatch(*ptn, *s))
      return (0);
    if (StringIn(*s, "0123456789"))
      *digits++ = *s;
    ptn++;
    s++;
  }
  *digits = '\0';
  *nextp = s;
  return (1);
}


x86 assembly (clang, -O0):
<StringPhoneMatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c0 <StringPhoneMatch+0xa0>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
movsbl %cl,%edi
movsbl (%rax),%esi
call   1030 <CharPhoneMatch@plt>
cmp    $0x0,%eax
jne    116f <StringPhoneMatch+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <StringPhoneMatch+0xb9>
mov    -0x18(%rbp),%rax
lea    0xe86(%rip),%rsi
movsbl (%rax),%edi
call   1040 <StringIn@plt>
cmp    $0x0,%rax
je     11a3 <StringPhoneMatch+0x83>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <StringPhoneMatch+0x18>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StringPhoneMatch>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    (%rdi),%al
test   %al,%al
je     118c <StringPhoneMatch+0x6c>
mov    %rdi,%r12
add    $0x1,%r12
lea    0xeba(%rip),%r13
jmp    1161 <StringPhoneMatch+0x41>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%r12),%eax
add    $0x1,%r12
test   %al,%al
je     118c <StringPhoneMatch+0x6c>
movsbl (%rbx),%esi
movsbl %al,%edi
call   1030 <CharPhoneMatch@plt>
test   %eax,%eax
je     119a <StringPhoneMatch+0x7a>
movsbl (%rbx),%edi
mov    %r13,%rsi
call   1040 <StringIn@plt>
test   %rax,%rax
je     1150 <StringPhoneMatch+0x30>
movzbl (%rbx),%eax
mov    %al,(%r15)
add    $0x1,%r15
jmp    1150 <StringPhoneMatch+0x30>
movb   $0x0,(%r15)
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    119c <StringPhoneMatch+0x7c>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define i32 @StringPhoneMatch(i8* %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
br label %10
10: ; preds = %32, %4
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = call i32 @CharPhoneMatch(i8 signext %16, i8 signext %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %14
store i32 0, i32* %5
br label %41
22: ; preds = %14
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = call i64 @StringIn(i8 signext %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %8
store i8 %29, i8* %30
br label %32
32: ; preds = %27, %22
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %6
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
br label %10
37: ; preds = %10
%38 = load i8*, i8** %8
store i8 0, i8* %38
%39 = load i8*, i8** %7
%40 = load i8**, i8*** %9
store i8* %39, i8** %40
store i32 1, i32* %5
br label %41
41: ; preds = %37, %21
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define i32 @StringPhoneMatch(i8* nocapture %0, i8* %1, i8* nocapture writeonly %2, i8** nocapture writeonly %3) {
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %4, %22
%8 = phi i8 [ %26, %22 ], [ %5, %4 ]
%9 = phi i8* [ %23, %22 ], [ %2, %4 ]
%10 = phi i8* [ %25, %22 ], [ %1, %4 ]
%11 = phi i8* [ %24, %22 ], [ %0, %4 ]
%12 = load i8, i8* %10
%13 = tail call i32 @CharPhoneMatch(i8 signext %8, i8 signext %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %31, label %15
15: ; preds = %7
%16 = load i8, i8* %10
%17 = tail call i64 @StringIn(i8 signext %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i8, i8* %10
%21 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %20, i8* %9
br label %22
22: ; preds = %19, %15
%23 = phi i8* [ %21, %19 ], [ %9, %15 ]
%24 = getelementptr inbounds i8, i8* %11, i64 1
%25 = getelementptr inbounds i8, i8* %10, i64 1
%26 = load i8, i8* %24
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %7
28: ; preds = %22, %4
%29 = phi i8* [ %1, %4 ], [ %25, %22 ]
%30 = phi i8* [ %2, %4 ], [ %23, %22 ]
store i8 0, i8* %30
store i8* %29, i8** %3
br label %31
31: ; preds = %7, %28
%32 = phi i32 [ 1, %28 ], [ 0, %7 ]
ret i32 %32
}