#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*/ strcpy(char *, char *);
int strlen(char *);
char *standardizePhoneNumber(char *phone) {
  static char phoneCharMap[] = "2223334445556667077888999";
  char *result = phone;
  char copy[256];
  int i, j;
  strcpy(copy, phone);
  i = 0;
  j = 0;
  for (i = 0; i < strlen(copy); ++i) {
    if (copy[i] == '-') {
      continue;
    } else if (copy[i] < 'A') {
      result[j++] = copy[i];
    } else {
      result[j++] = phoneCharMap[copy[i] - 'A'];
    }
    if (j == 3) {
      result[j++] = '-';
    }
  }
  result[j] = 0;
  return result;
}


x86 assembly (clang, -O0):
<standardizePhoneNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x114(%rbp)
movl   $0x0,-0x118(%rbp)
movl   $0x0,-0x114(%rbp)
mov    -0x114(%rbp),%eax
mov    %eax,-0x11c(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x11c(%rbp),%eax
cmp    %ecx,%eax
jge    1271 <standardizePhoneNumber+0x151>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2d,%eax
jne    11aa <standardizePhoneNumber+0x8a>
jmp    125d <standardizePhoneNumber+0x13d>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x41,%eax
jge    11f0 <standardizePhoneNumber+0xd0>
movslq -0x114(%rbp),%rax
mov    -0x110(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x118(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x118(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    122a <standardizePhoneNumber+0x10a>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
sub    $0x41,%eax
movslq %eax,%rcx
lea    0x2e34(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x118(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x118(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    122f <standardizePhoneNumber+0x10f>
cmpl   $0x3,-0x118(%rbp)
jne    1258 <standardizePhoneNumber+0x138>
mov    -0x10(%rbp),%rax
mov    -0x118(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x118(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    125d <standardizePhoneNumber+0x13d>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    1165 <standardizePhoneNumber+0x45>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<standardizePhoneNumber>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r15
mov    %rsp,%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11aa <standardizePhoneNumber+0x8a>
xor    %ebx,%ebx
mov    %rsp,%r14
lea    0xea7(%rip),%r13
xor    %r12d,%r12d
jmp    1184 <standardizePhoneNumber+0x64>
xchg   %ax,%ax
movslq %r12d,%r12
mov    %al,(%r15,%r12,1)
add    $0x1,%r12d
cmp    $0x3,%r12d
je     119d <standardizePhoneNumber+0x7d>
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11ad <standardizePhoneNumber+0x8d>
movsbq (%rsp,%rbx,1),%rax
cmp    $0x2d,%rax
je     1171 <standardizePhoneNumber+0x51>
cmp    $0x41,%al
jl     1160 <standardizePhoneNumber+0x40>
add    $0xffffffbf,%eax
movzbl (%rax,%r13,1),%eax
jmp    1160 <standardizePhoneNumber+0x40>
movb   $0x2d,0x3(%r15)
mov    $0x4,%r12d
jmp    1171 <standardizePhoneNumber+0x51>
xor    %r12d,%r12d
movslq %r12d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@standardizePhoneNumber.phoneCharMap = internal global [26 x i8] c"2223334445556667077888999\00"
define i8* @standardizePhoneNumber(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %3
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %2
%10 = call i32 @strcpy(i8* %8, i8* %9)
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %67, %1
%12 = load i32, i32* %5
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %70
16: ; preds = %11
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 45
br i1 %22, label %23, label %24
23: ; preds = %16
br label %67
24: ; preds = %16
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp slt i32 %29, 65
br i1 %30, label %31, label %41
31: ; preds = %24
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = load i8*, i8** %3
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 %35, i8* %40
br label %56
41: ; preds = %24
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = sub nsw i32 %46, 65
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [26 x i8], [26 x i8]* @standardizePhoneNumber.phoneCharMap, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = load i8*, i8** %3
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8 %50, i8* %55
br label %56
56: ; preds = %41, %31
br label %57
57: ; preds = %56
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, 3
br i1 %59, label %60, label %66
60: ; preds = %57
%61 = load i8*, i8** %3
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
%64 = sext i32 %62 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
store i8 45, i8* %65
br label %66
66: ; preds = %60, %57
br label %67
67: ; preds = %66, %23
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
br label %11
70: ; preds = %11
%71 = load i8*, i8** %3
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
store i8 0, i8* %74
%75 = load i8*, i8** %3
ret i8* %75
}

LLVM IR (-O2):
@standardizePhoneNumber.phoneCharMap = internal unnamed_addr constant [26 x i8] c"2223334445556667077888999\00"
define i8* @standardizePhoneNumber(i8* returned %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i32 @strlen(i8* %3)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %36
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 3
br label %9
9: ; preds = %7, %30
%10 = phi i64 [ 0, %7 ], [ %32, %30 ]
%11 = phi i32 [ 0, %7 ], [ %31, %30 ]
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %10
%13 = load i8, i8* %12
%14 = sext i8 %13 to i64
%15 = icmp eq i8 %13, 45
br i1 %15, label %30, label %16
16: ; preds = %9
%17 = icmp slt i8 %13, 65
br i1 %17, label %23, label %18
18: ; preds = %16
%19 = add nsw i64 %14, 4294967231
%20 = and i64 %19, 4294967295
%21 = getelementptr inbounds [26 x i8], [26 x i8]* @standardizePhoneNumber.phoneCharMap, i64 0, i64 %20
%22 = load i8, i8* %21
br label %23
23: ; preds = %16, %18
%24 = phi i8 [ %22, %18 ], [ %13, %16 ]
%25 = sext i32 %11 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %24, i8* %26
%27 = add nsw i32 %11, 1
%28 = icmp eq i32 %27, 3
br i1 %28, label %29, label %30
29: ; preds = %23
store i8 45, i8* %8
br label %30
30: ; preds = %23, %29, %9
%31 = phi i32 [ %11, %9 ], [ 4, %29 ], [ %27, %23 ]
%32 = add nuw nsw i64 %10, 1
%33 = call i32 @strlen(i8* %3)
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %9, label %36
36: ; preds = %30, %1
%37 = phi i32 [ 0, %1 ], [ %31, %30 ]
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %0, i64 %38
store i8 0, i8* %39
ret i8* %0
}