#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__ isalpha(char const);
int /*<<< orphan*/ strcpy(char *, char *);
int toupper(char const);
const char *txt_soundex(const char *string) {
  static char result[5];
  char *pt = result;
  int upper_case;
  static char map[] = "01230120022455012623010202";
  char previous = 0;
  char transform;
  int i;
  strcpy(result, "Z000");
  for (i = 0; *string && i < 4; ++string) {
    if (isalpha(*string)) {
      upper_case = toupper(*string);
      transform = map[upper_case - 'A'];
      if (!i) {
        *pt++ = upper_case;
        ++i;
      } else {
        if (transform != '0' && transform != previous) {
          *pt++ = transform;
          ++i;
        }
      }
      previous = transform;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<txt_soundex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f19(%rip),%rax
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x15(%rbp)
lea    0x2f0a(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1184 <txt_soundex+0x54>
cmpl   $0x4,-0x1c(%rbp)
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1194 <txt_soundex+0x64>
jmp    1258 <txt_soundex+0x128>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     1242 <txt_soundex+0x112>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x41,%eax
movslq %eax,%rcx
lea    0x2e77(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x16(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11fd <txt_soundex+0xcd>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <txt_soundex+0x10c>
movsbl -0x16(%rbp),%eax
cmp    $0x30,%eax
je     1237 <txt_soundex+0x107>
movsbl -0x16(%rbp),%eax
movsbl -0x15(%rbp),%ecx
cmp    %ecx,%eax
je     1237 <txt_soundex+0x107>
mov    -0x16(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <txt_soundex+0x10c>
mov    -0x16(%rbp),%al
mov    %al,-0x15(%rbp)
jmp    1247 <txt_soundex+0x117>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1165 <txt_soundex+0x35>
lea    0x2dfd(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txt_soundex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x2ef4(%rip),%r14
lea    0xecf(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    (%rbx),%al
test   %al,%al
je     11cf <txt_soundex+0x9f>
add    $0x1,%rbx
xor    %ebp,%ebp
lea    0xe99(%rip),%r15
mov    $0x1504191,%r12d
xor    %r13d,%r13d
movsbl %al,%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     11bf <txt_soundex+0x8f>
movsbl -0x1(%rbx),%edi
call   1040 <toupper@plt>
movslq %eax,%rdx
movzbl -0x41(%rdx,%r15,1),%ecx
test   %ebp,%ebp
je     11b0 <txt_soundex+0x80>
add    $0xffffffffffffffbf,%rdx
bt     %rdx,%r12
jb     11bc <txt_soundex+0x8c>
cmp    %r13b,%cl
je     11bc <txt_soundex+0x8c>
mov    %cl,(%r14)
add    $0x1,%r14
add    $0x1,%ebp
jmp    11bc <txt_soundex+0x8c>
xchg   %ax,%ax
mov    %al,(%r14)
add    $0x1,%r14
mov    $0x1,%ebp
mov    %ecx,%r13d
movzbl (%rbx),%eax
test   %al,%al
je     11cf <txt_soundex+0x9f>
add    $0x1,%rbx
cmp    $0x4,%ebp
jl     1170 <txt_soundex+0x40>
lea    0x2e63(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@txt_soundex.result = internal global [5 x i8] zeroinitializer
@txt_soundex.map = internal global [27 x i8] c"01230120022455012623010202\00"
@.str = [5 x i8] c"Z000\00"
define i8* @txt_soundex(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @txt_soundex.result, i64 0, i64 0), i8** %3
store i8 0, i8* %5
%8 = call i32 @strcpy(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @txt_soundex.result, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %9
9: ; preds = %62, %1
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 4
br label %17
17: ; preds = %14, %9
%18 = phi i1 [ false, %9 ], [ %16, %14 ]
br i1 %18, label %19, label %65
19: ; preds = %17
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = call i64 @isalpha(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %61
24: ; preds = %19
%25 = load i8*, i8** %2
%26 = load i8, i8* %25
%27 = call i32 @toupper(i8 signext %26)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 65
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [27 x i8], [27 x i8]* @txt_soundex.map, i64 0, i64 %30
%32 = load i8, i8* %31
store i8 %32, i8* %6
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %24
%36 = load i32, i32* %4
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %3
store i8 %37, i8* %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %59
42: ; preds = %24
%43 = load i8, i8* %6
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 48
br i1 %45, label %46, label %58
46: ; preds = %42
%47 = load i8, i8* %6
%48 = sext i8 %47 to i32
%49 = load i8, i8* %5
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %48, %50
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = load i8, i8* %6
%54 = load i8*, i8** %3
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %3
store i8 %53, i8* %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %58
58: ; preds = %52, %46, %42
br label %59
59: ; preds = %58, %35
%60 = load i8, i8* %6
store i8 %60, i8* %5
br label %61
61: ; preds = %59, %19
br label %62
62: ; preds = %61
%63 = load i8*, i8** %2
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %2
br label %9
65: ; preds = %17
ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @txt_soundex.result, i64 0, i64 0)
}

LLVM IR (-O2):
@txt_soundex.result = internal global [5 x i8] zeroinitializer
@txt_soundex.map = internal unnamed_addr constant [27 x i8] c"01230120022455012623010202\00"
@.str = [5 x i8] c"Z000\00"
define i8* @txt_soundex(i8* nocapture %0) {
%2 = tail call i32 @strcpy(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @txt_soundex.result, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %42, label %5
5: ; preds = %1, %33
%6 = phi i8 [ %38, %33 ], [ %3, %1 ]
%7 = phi i32 [ %36, %33 ], [ 0, %1 ]
%8 = phi i8* [ %37, %33 ], [ %0, %1 ]
%9 = phi i8 [ %35, %33 ], [ 0, %1 ]
%10 = phi i8* [ %34, %33 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @txt_soundex.result, i64 0, i64 0), %1 ]
%11 = tail call i64 @isalpha(i8 signext %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %33, label %13
13: ; preds = %5
%14 = load i8, i8* %8
%15 = tail call i32 @toupper(i8 signext %14)
%16 = add nsw i32 %15, -65
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [27 x i8], [27 x i8]* @txt_soundex.map, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i32 %7, 0
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = trunc i32 %15 to i8
%23 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %22, i8* %10
br label %33
24: ; preds = %13
%25 = lshr i64 22036881, %17
%26 = and i64 %25, 1
%27 = icmp ne i64 %26, 0
%28 = icmp eq i8 %19, %9
%29 = select i1 %27, i1 true, i1 %28
br i1 %29, label %33, label %30
30: ; preds = %24
%31 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %19, i8* %10
%32 = add nsw i32 %7, 1
br label %33
33: ; preds = %21, %30, %24, %5
%34 = phi i8* [ %10, %5 ], [ %31, %30 ], [ %10, %24 ], [ %23, %21 ]
%35 = phi i8 [ %9, %5 ], [ %19, %30 ], [ %19, %24 ], [ %19, %21 ]
%36 = phi i32 [ %7, %5 ], [ %32, %30 ], [ %7, %24 ], [ 1, %21 ]
%37 = getelementptr inbounds i8, i8* %8, i64 1
%38 = load i8, i8* %37
%39 = icmp ne i8 %38, 0
%40 = icmp slt i32 %36, 4
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %5, label %42
42: ; preds = %33, %1
ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @txt_soundex.result, i64 0, i64 0)
}