#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(char const);
int metaphone(char const *, char *, int);
int address_metaphone(const char *input, char *output, int max_phones) {
  const char *n = input;
  int i = 0;
  if (isdigit(*n)) {
    while (i < max_phones && isdigit(n[i]) && n[i] != '\0')
      *output++ = n[i++];
    *output = '\0';
    return 1;
  } else {
    return metaphone(input, output, max_phones);
  }
}


x86 assembly (clang, -O0):
<address_metaphone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11f4 <address_metaphone+0xd4>
jmp    115d <address_metaphone+0x3d>
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jge    11a6 <address_metaphone+0x86>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2d(%rbp)
je     11a6 <address_metaphone+0x86>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11b6 <address_metaphone+0x96>
jmp    11e1 <address_metaphone+0xc1>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    115d <address_metaphone+0x3d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1207 <address_metaphone+0xe7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <metaphone@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<address_metaphone>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r12
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     117e <address_metaphone+0x5e>
test   %ebp,%ebp
jle    1196 <address_metaphone+0x76>
mov    %ebp,%r15d
xor    %ebp,%ebp
mov    %r14,%rbx
nopl   0x0(%rax)
movsbl (%r12,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1193 <address_metaphone+0x73>
movzbl (%r12,%rbp,1),%eax
test   %al,%al
je     1179 <address_metaphone+0x59>
add    $0x1,%rbx
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <address_metaphone+0x30>
add    %rbp,%r14
jmp    1196 <address_metaphone+0x76>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <metaphone@plt>
mov    %rbx,%r14
movb   $0x0,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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