#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ isdigit(char const);
int /*<<< orphan*/ strlcpy(char *, char *, int);
char tolower(char const);
const char *form_field_getstr_phone(const char *raw, void *arg) {
  static char str[sizeof("(NPA) NXX-NMBR xEXTN5")];
  const char *r;
  int len;
  if (raw == NULL || *raw == '\0') {
    strlcpy(str, "(___) ___-____", sizeof(str));
    return str;
  }
  r = raw;
  len = 0;
  bzero(str, sizeof(str));
  do {
    switch (len) {
    case 0:
      str[len++] = '(';
      break;
    case 4:
      str[len++] = ')';
    case 5:
      str[len++] = ' ';
      break;
    case 9:
      str[len++] = '-';
      break;
    case 14:
      if (*r != '\0')
        str[len++] = ' ';
    case 15:
      if (*r != '\0')
        str[len++] = 'x';
      break;
    }
    if (isdigit(*r))
      str[len++] = *r++;
    else if (tolower(*r) == 'x') {
      if (len < 14)
        str[len++] = '_';
      else
        *r++;
    } else if (*r == '\0' && len < 14)
      str[len++] = '_';
    else
      len++;
  } while (len < (sizeof("(NPA) NXX-NMBR xEXTN5") - 1));
  return str;
}


x86 assembly (clang, -O0):
<form_field_getstr_phone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <form_field_getstr_phone+0x2b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1193 <form_field_getstr_phone+0x53>
lea    0x2ede(%rip),%rdi
lea    0xec7(%rip),%rsi
mov    $0x16,%edx
call   1050 <strlcpy@plt>
lea    0x2ec6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13a5 <form_field_getstr_phone+0x265>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0x2ea7(%rip),%rdi
mov    $0x16,%esi
call   1060 <bzero@plt>
mov    -0x24(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0xf,%rax
ja     12a7 <form_field_getstr_phone+0x167>
mov    -0x30(%rbp),%rax
lea    0xe31(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2e63(%rip),%rax
movb   $0x28,(%rax,%rcx,1)
jmp    12a7 <form_field_getstr_phone+0x167>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2e45(%rip),%rax
movb   $0x29,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2e2c(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
jmp    12a7 <form_field_getstr_phone+0x167>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2e0e(%rip),%rax
movb   $0x2d,(%rax,%rcx,1)
jmp    12a7 <form_field_getstr_phone+0x167>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1274 <form_field_getstr_phone+0x134>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2de0(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
jmp    1279 <form_field_getstr_phone+0x139>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a2 <form_field_getstr_phone+0x162>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2db2(%rip),%rax
movb   $0x78,(%rax,%rcx,1)
jmp    12a7 <form_field_getstr_phone+0x167>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12eb <form_field_getstr_phone+0x1ab>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%dl
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2d6d(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    1387 <form_field_getstr_phone+0x247>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x78,%eax
jne    133c <form_field_getstr_phone+0x1fc>
cmpl   $0xe,-0x24(%rbp)
jge    132b <form_field_getstr_phone+0x1eb>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2d2e(%rip),%rax
movb   $0x5f,(%rax,%rcx,1)
jmp    1337 <form_field_getstr_phone+0x1f7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1382 <form_field_getstr_phone+0x242>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1374 <form_field_getstr_phone+0x234>
cmpl   $0xe,-0x24(%rbp)
jge    1374 <form_field_getstr_phone+0x234>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %eax,%rcx
lea    0x2ce5(%rip),%rax
movb   $0x5f,(%rax,%rcx,1)
jmp    137d <form_field_getstr_phone+0x23d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1382 <form_field_getstr_phone+0x242>
jmp    1387 <form_field_getstr_phone+0x247>
jmp    138c <form_field_getstr_phone+0x24c>
movslq -0x24(%rbp),%rax
cmp    $0x15,%rax
jb     11b3 <form_field_getstr_phone+0x73>
lea    0x2caf(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<form_field_getstr_phone>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     126d <form_field_getstr_phone+0x12d>
mov    %rdi,%r12
cmpb   $0x0,(%rdi)
je     126d <form_field_getstr_phone+0x12d>
lea    0x2eec(%rip),%r14
mov    %r14,%rdi
mov    $0x16,%esi
call   1060 <bzero@plt>
xor    %ebx,%ebx
lea    0xe86(%rip),%r15
jmp    119b <form_field_getstr_phone+0x5b>
nopl   0x0(%rax)
movzbl (%r12),%eax
add    $0x1,%r12
mov    %ebx,%ecx
add    $0x1,%ebx
mov    %al,(%rcx,%r14,1)
cmp    $0x15,%ebx
jae    1285 <form_field_getstr_phone+0x145>
cmp    $0xf,%ebx
ja     1210 <form_field_getstr_phone+0xd0>
mov    %ebx,%eax
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
movb   $0x28,0x2e9e(%rip)
mov    $0x1,%ebx
jmp    1210 <form_field_getstr_phone+0xd0>
movb   $0x29,0x2e94(%rip)
movb   $0x20,0x2e8e(%rip)
mov    $0x6,%ebx
jmp    1210 <form_field_getstr_phone+0xd0>
movb   $0x2d,0x2e84(%rip)
mov    $0xa,%ebx
jmp    1210 <form_field_getstr_phone+0xd0>
cmpb   $0x0,(%r12)
je     1206 <form_field_getstr_phone+0xc6>
movb   $0x20,0x2e74(%rip)
cmpb   $0x0,(%r12)
je     11ff <form_field_getstr_phone+0xbf>
movb   $0x78,0x2e67(%rip)
mov    $0x10,%ebx
jmp    1210 <form_field_getstr_phone+0xd0>
mov    $0xf,%ebx
jmp    1210 <form_field_getstr_phone+0xd0>
mov    $0xe,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r12),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1180 <form_field_getstr_phone+0x40>
movsbl (%r12),%edi
call   1040 <tolower@plt>
cmp    $0x78,%al
jne    1246 <form_field_getstr_phone+0x106>
cmp    $0xd,%ebx
jg     1264 <form_field_getstr_phone+0x124>
movslq %ebx,%rax
add    $0x1,%ebx
movb   $0x5f,(%rax,%r14,1)
jmp    1192 <form_field_getstr_phone+0x52>
lea    0x1(%rbx),%eax
cmpb   $0x0,(%r12)
jne    125d <form_field_getstr_phone+0x11d>
cmp    $0xd,%ebx
jg     125d <form_field_getstr_phone+0x11d>
movslq %ebx,%rcx
movb   $0x5f,(%rcx,%r14,1)
mov    %eax,%ebx
jmp    1192 <form_field_getstr_phone+0x52>
add    $0x1,%r12
jmp    1192 <form_field_getstr_phone+0x52>
lea    0x2ddc(%rip),%rdi
lea    0xdc5(%rip),%rsi
mov    $0x16,%edx
call   1050 <strlcpy@plt>
lea    0x2dc4(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@form_field_getstr_phone.str = internal global [22 x i8] zeroinitializer
@.str = [15 x i8] c"(___) ___-____\00"
define i8* @form_field_getstr_phone(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10, %2
%16 = call i32 @strlcpy(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 22)
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0), i8** %3
br label %120
17: ; preds = %10
%18 = load i8*, i8** %4
store i8* %18, i8** %6
store i32 0, i32* %7
%19 = call i32 @bzero(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0), i32 22)
br label %20
20: ; preds = %115, %17
%21 = load i32, i32* %7
switch i32 %21, label %64 [
i32 0, label %22
i32 4, label %27
i32 5, label %32
i32 9, label %37
i32 14, label %42
i32 15, label %53
]
22: ; preds = %20
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %25
store i8 40, i8* %26
br label %64
27: ; preds = %20
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %30
store i8 41, i8* %31
br label %32
32: ; preds = %20, %27
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %35
store i8 32, i8* %36
br label %64
37: ; preds = %20
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %40
store i8 45, i8* %41
br label %64
42: ; preds = %20
%43 = load i8*, i8** %6
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %50
store i8 32, i8* %51
br label %52
52: ; preds = %47, %42
br label %53
53: ; preds = %20, %52
%54 = load i8*, i8** %6
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %53
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %61
store i8 120, i8* %62
br label %63
63: ; preds = %58, %53
br label %64
64: ; preds = %20, %63, %37, %32, %22
%65 = load i8*, i8** %6
%66 = load i8, i8* %65
%67 = call i64 @isdigit(i8 signext %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %77
69: ; preds = %64
%70 = load i8*, i8** %6
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %6
%72 = load i8, i8* %70
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
%75 = sext i32 %73 to i64
%76 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %75
store i8 %72, i8* %76
br label %114
77: ; preds = %64
%78 = load i8*, i8** %6
%79 = load i8, i8* %78
%80 = call signext i8 @tolower(i8 signext %79)
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 120
br i1 %82, label %83, label %96
83: ; preds = %77
%84 = load i32, i32* %7
%85 = icmp slt i32 %84, 14
br i1 %85, label %86, label %91
86: ; preds = %83
%87 = load i32, i32* %7
%88 = add nsw i32 %87, 1
store i32 %88, i32* %7
%89 = sext i32 %87 to i64
%90 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %89
store i8 95, i8* %90
br label %95
91: ; preds = %83
%92 = load i8*, i8** %6
%93 = getelementptr inbounds i8, i8* %92, i32 1
store i8* %93, i8** %6
%94 = load i8, i8* %92
br label %95
95: ; preds = %91, %86
br label %113
96: ; preds = %77
%97 = load i8*, i8** %6
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = icmp eq i32 %99, 0
br i1 %100, label %101, label %109
101: ; preds = %96
%102 = load i32, i32* %7
%103 = icmp slt i32 %102, 14
br i1 %103, label %104, label %109
104: ; preds = %101
%105 = load i32, i32* %7
%106 = add nsw i32 %105, 1
store i32 %106, i32* %7
%107 = sext i32 %105 to i64
%108 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %107
store i8 95, i8* %108
br label %112
109: ; preds = %101, %96
%110 = load i32, i32* %7
%111 = add nsw i32 %110, 1
store i32 %111, i32* %7
br label %112
112: ; preds = %109, %104
br label %113
113: ; preds = %112, %95
br label %114
114: ; preds = %113, %69
br label %115
115: ; preds = %114
%116 = load i32, i32* %7
%117 = sext i32 %116 to i64
%118 = icmp ult i64 %117, 21
br i1 %118, label %20, label %119
119: ; preds = %115
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0), i8** %3
br label %120
120: ; preds = %119, %15
%121 = load i8*, i8** %3
ret i8* %121
}

LLVM IR (-O2):
@form_field_getstr_phone.str = internal global [22 x i8] zeroinitializer
@.str = [15 x i8] c"(___) ___-____\00"
define i8* @form_field_getstr_phone(i8* %0, i8* nocapture readnone %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4, %2
%8 = tail call i32 @strlcpy(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 22)
br label %62
9: ; preds = %4
%10 = tail call i32 @bzero(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0), i32 22)
br label %11
11: ; preds = %58, %9
%12 = phi i8* [ %0, %9 ], [ %59, %58 ]
%13 = phi i32 [ 0, %9 ], [ %60, %58 ]
switch i32 %13, label %26 [
i32 0, label %14
i32 4, label %15
i32 5, label %16
i32 9, label %17
i32 14, label %18
i32 15, label %22
]
14: ; preds = %11
store i8 40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0)
br label %26
15: ; preds = %11
store i8 41, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 4)
br label %16
16: ; preds = %11, %15
store i8 32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 5)
br label %26
17: ; preds = %11
store i8 45, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 9)
br label %26
18: ; preds = %11
%19 = load i8, i8* %12
%20 = icmp eq i8 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %18
store i8 32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 14)
br label %22
22: ; preds = %21, %11
%23 = load i8, i8* %12
%24 = icmp eq i8 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22
store i8 120, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 15)
br label %26
26: ; preds = %18, %22, %25, %11, %17, %16, %14
%27 = phi i32 [ %13, %11 ], [ 16, %25 ], [ 15, %22 ], [ 10, %17 ], [ 6, %16 ], [ 1, %14 ], [ 14, %18 ]
%28 = load i8, i8* %12
%29 = tail call i64 @isdigit(i8 signext %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %26
%32 = getelementptr inbounds i8, i8* %12, i64 1
%33 = load i8, i8* %12
%34 = add nsw i32 %27, 1
%35 = zext i32 %27 to i64
%36 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %35
store i8 %33, i8* %36
br label %58
37: ; preds = %26
%38 = load i8, i8* %12
%39 = tail call signext i8 @tolower(i8 signext %38)
%40 = icmp eq i8 %39, 120
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = icmp slt i32 %27, 14
br i1 %42, label %43, label %47
43: ; preds = %41
%44 = add nsw i32 %27, 1
%45 = sext i32 %27 to i64
%46 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %45
store i8 95, i8* %46
br label %58
47: ; preds = %41
%48 = getelementptr inbounds i8, i8* %12, i64 1
br label %58
49: ; preds = %37
%50 = load i8, i8* %12
%51 = icmp eq i8 %50, 0
%52 = icmp slt i32 %27, 14
%53 = select i1 %51, i1 %52, i1 false
%54 = add nsw i32 %27, 1
br i1 %53, label %55, label %58
55: ; preds = %49
%56 = sext i32 %27 to i64
%57 = getelementptr inbounds [22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 %56
store i8 95, i8* %57
br label %58
58: ; preds = %49, %31, %55, %43, %47
%59 = phi i8* [ %32, %31 ], [ %12, %43 ], [ %48, %47 ], [ %12, %55 ], [ %12, %49 ]
%60 = phi i32 [ %34, %31 ], [ %44, %43 ], [ %27, %47 ], [ %54, %55 ], [ %54, %49 ]
%61 = icmp ult i32 %60, 21
br i1 %61, label %11, label %62
62: ; preds = %58, %7
ret i8* getelementptr inbounds ([22 x i8], [22 x i8]* @form_field_getstr_phone.str, i64 0, i64 0)
}