#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*/ isdigit(char const);
int form_field_validate_phone(const char *str, int *pos, void *arg) {
  const char *s;
  for (s = str; *s; *s++)
    if (!isdigit(*s) && *s != 'X' && *s != 'x' &&
        (s - str) < sizeof("NPANXXNMBRxEXTN5")) {
      *pos = s - str;
      return -1;
    }
  return 0;
}


x86 assembly (clang, -O0):
<form_field_validate_phone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b8 <form_field_validate_phone+0xa8>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11a2 <form_field_validate_phone+0x92>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x58,%eax
je     11a2 <form_field_validate_phone+0x92>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
je     11a2 <form_field_validate_phone+0x92>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x11,%rax
jae    11a2 <form_field_validate_phone+0x92>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <form_field_validate_phone+0xaf>
jmp    11a7 <form_field_validate_phone+0x97>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <form_field_validate_phone+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<form_field_validate_phone>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1165 <form_field_validate_phone+0x55>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    113e <form_field_validate_phone+0x2e>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
je     1165 <form_field_validate_phone+0x55>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    1130 <form_field_validate_phone+0x20>
movzbl (%r15,%rbx,1),%eax
or     $0x20,%al
cmp    $0x78,%al
je     1130 <form_field_validate_phone+0x20>
cmp    $0x10,%rbx
ja     1130 <form_field_validate_phone+0x20>
mov    %ebx,(%r14)
mov    $0xffffffff,%eax
jmp    1167 <form_field_validate_phone+0x57>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @form_field_validate_phone(i8* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
store i8* %9, i8** %8
br label %10
10: ; preds = %45, %3
%11 = load i8*, i8** %8
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %49
14: ; preds = %10
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = call i32 @isdigit(i8 signext %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %44, label %19
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 88
br i1 %23, label %24, label %44
24: ; preds = %19
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 120
br i1 %28, label %29, label %44
29: ; preds = %24
%30 = load i8*, i8** %8
%31 = load i8*, i8** %5
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = icmp ult i64 %34, 17
br i1 %35, label %36, label %44
36: ; preds = %29
%37 = load i8*, i8** %8
%38 = load i8*, i8** %5
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = trunc i64 %41 to i32
%43 = load i32*, i32** %6
store i32 %42, i32* %43
store i32 -1, i32* %4
br label %50
44: ; preds = %29, %24, %19, %14
br label %45
45: ; preds = %44
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %8
%48 = load i8, i8* %46
br label %10
49: ; preds = %10
store i32 0, i32* %4
br label %50
50: ; preds = %49, %36
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
define i32 @form_field_validate_phone(i8* %0, i32* nocapture writeonly %1, i8* nocapture readnone %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = ptrtoint i8* %0 to i64
br label %8
8: ; preds = %6, %21
%9 = phi i8 [ %4, %6 ], [ %23, %21 ]
%10 = phi i8* [ %0, %6 ], [ %22, %21 ]
%11 = tail call i32 @isdigit(i8 signext %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = load i8, i8* %10
switch i8 %14, label %15 [
i8 88, label %21
i8 120, label %21
]
15: ; preds = %13
%16 = ptrtoint i8* %10 to i64
%17 = sub i64 %16, %7
%18 = icmp ult i64 %17, 17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = trunc i64 %17 to i32
store i32 %20, i32* %1
br label %25
21: ; preds = %13, %13, %8, %15
%22 = getelementptr inbounds i8, i8* %10, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %8
25: ; preds = %21, %3, %19
%26 = phi i32 [ -1, %19 ], [ 0, %3 ], [ 0, %21 ]
ret i32 %26
}