#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__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int tolower(char const);
char *soundex(const char *in) {
  int index_in = 1, index_out = 1;
  char prev_dig, *out = (char *)malloc(5), cur_char;
  memset(out, '0', 4);
  out[0] = tolower(in[0]);
  prev_dig = out[0];
  while (in[index_in] && index_out < 4) {
    switch (tolower(in[index_in++])) {
    case 'b':
      cur_char = '1';
      break;
    case 'p':
      cur_char = '1';
      break;
    case 'f':
      cur_char = '1';
      break;
    case 'v':
      cur_char = '1';
      break;
    case 'c':
      cur_char = '2';
      break;
    case 's':
      cur_char = '2';
      break;
    case 'k':
      cur_char = '2';
      break;
    case 'g':
      cur_char = '2';
      break;
    case 'j':
      cur_char = '2';
      break;
    case 'q':
      cur_char = '2';
      break;
    case 'x':
      cur_char = '2';
      break;
    case 'z':
      cur_char = '2';
      break;
    case 'd':
      cur_char = '3';
      break;
    case 't':
      cur_char = '3';
      break;
    case 'l':
      cur_char = '4';
      break;
    case 'm':
      cur_char = '5';
      break;
    case 'n':
      cur_char = '5';
      break;
    case 'r':
      cur_char = '6';
      break;
    default:
      cur_char = '*';
    }
    if (cur_char != prev_dig && cur_char != '*')
      out[index_out++] = prev_dig = cur_char;
  }
  out[4] = 0x00;
  return out;
}


x86 assembly (clang, -O0):
<soundex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x5,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x30,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x22(%rbp)
je     11ac <soundex+0x7c>
cmpl   $0x4,-0x10(%rbp)
setl   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11bc <soundex+0x8c>
jmp    12de <soundex+0x1ae>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x18,%eax
ja     129d <soundex+0x16d>
mov    -0x30(%rbp),%rax
lea    0xe0e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x31,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x31,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x31,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x31,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x32,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x33,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x33,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x34,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x35,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x35,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x36,-0x21(%rbp)
jmp    12a1 <soundex+0x171>
movb   $0x2a,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     12d9 <soundex+0x1a9>
movsbl -0x21(%rbp),%eax
cmp    $0x2a,%eax
je     12d9 <soundex+0x1a9>
mov    -0x21(%rbp),%dl
mov    %dl,-0x11(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1188 <soundex+0x58>
mov    -0x20(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<soundex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x5,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x30,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
mov    %eax,%r15d
mov    %r15b,(%r14)
mov    0x1(%rbx),%al
test   %al,%al
je     11e0 <soundex+0xb0>
add    $0x2,%rbx
mov    $0x1,%ebp
mov    $0x157df37,%r12d
lea    0xe78(%rip),%r13
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <tolower@plt>
add    $0xffffff9e,%eax
cmp    $0x18,%eax
ja     11d0 <soundex+0xa0>
bt     %eax,%r12d
jae    11d0 <soundex+0xa0>
cltq
movzbl (%rax,%r13,1),%eax
movsbl %r15b,%ecx
cmp    %ecx,%eax
je     11d0 <soundex+0xa0>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%r14,%rcx,1)
mov    %eax,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%eax
test   %al,%al
je     11e0 <soundex+0xb0>
add    $0x1,%rbx
cmp    $0x4,%ebp
jl     1190 <soundex+0x60>
movb   $0x0,0x4(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @soundex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %2
store i32 1, i32* %3
store i32 1, i32* %4
%8 = call i64 @malloc(i32 5)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @memset(i8* %10, i32 48, i32 4)
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = call i32 @tolower(i8 signext %14)
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 %16, i8* %18
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
store i8 %21, i8* %5
br label %22
22: ; preds = %79, %1
%23 = load i8*, i8** %2
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 4
br label %33
33: ; preds = %30, %22
%34 = phi i1 [ false, %22 ], [ %32, %30 ]
br i1 %34, label %35, label %80
35: ; preds = %33
%36 = load i8*, i8** %2
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @tolower(i8 signext %41)
switch i32 %42, label %61 [
i32 98, label %43
i32 112, label %44
i32 102, label %45
i32 118, label %46
i32 99, label %47
i32 115, label %48
i32 107, label %49
i32 103, label %50
i32 106, label %51
i32 113, label %52
i32 120, label %53
i32 122, label %54
i32 100, label %55
i32 116, label %56
i32 108, label %57
i32 109, label %58
i32 110, label %59
i32 114, label %60
]
43: ; preds = %35
store i8 49, i8* %7
br label %62
44: ; preds = %35
store i8 49, i8* %7
br label %62
45: ; preds = %35
store i8 49, i8* %7
br label %62
46: ; preds = %35
store i8 49, i8* %7
br label %62
47: ; preds = %35
store i8 50, i8* %7
br label %62
48: ; preds = %35
store i8 50, i8* %7
br label %62
49: ; preds = %35
store i8 50, i8* %7
br label %62
50: ; preds = %35
store i8 50, i8* %7
br label %62
51: ; preds = %35
store i8 50, i8* %7
br label %62
52: ; preds = %35
store i8 50, i8* %7
br label %62
53: ; preds = %35
store i8 50, i8* %7
br label %62
54: ; preds = %35
store i8 50, i8* %7
br label %62
55: ; preds = %35
store i8 51, i8* %7
br label %62
56: ; preds = %35
store i8 51, i8* %7
br label %62
57: ; preds = %35
store i8 52, i8* %7
br label %62
58: ; preds = %35
store i8 53, i8* %7
br label %62
59: ; preds = %35
store i8 53, i8* %7
br label %62
60: ; preds = %35
store i8 54, i8* %7
br label %62
61: ; preds = %35
store i8 42, i8* %7
br label %62
62: ; preds = %61, %60, %59, %58, %57, %56, %55, %54, %53, %52, %51, %50, %49, %48, %47, %46, %45, %44, %43
%63 = load i8, i8* %7
%64 = sext i8 %63 to i32
%65 = load i8, i8* %5
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %64, %66
br i1 %67, label %68, label %79
68: ; preds = %62
%69 = load i8, i8* %7
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 42
br i1 %71, label %72, label %79
72: ; preds = %68
%73 = load i8, i8* %7
store i8 %73, i8* %5
%74 = load i8*, i8** %6
%75 = load i32, i32* %4
%76 = add nsw i32 %75, 1
store i32 %76, i32* %4
%77 = sext i32 %75 to i64
%78 = getelementptr inbounds i8, i8* %74, i64 %77
store i8 %73, i8* %78
br label %79
79: ; preds = %72, %68, %62
br label %22
80: ; preds = %33
%81 = load i8*, i8** %6
%82 = getelementptr inbounds i8, i8* %81, i64 4
store i8 0, i8* %82
%83 = load i8*, i8** %6
ret i8* %83
}

LLVM IR (-O2):
@switch.table.soundex = [25 x i8] c"1231121122455112623111212"
define i8* @soundex(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 5)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @memset(i8* %3, i32 48, i32 4)
%5 = load i8, i8* %0
%6 = tail call i32 @tolower(i8 signext %5)
%7 = trunc i32 %6 to i8
store i8 %7, i8* %3
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %43, label %11
11: ; preds = %1, %35
%12 = phi i64 [ %16, %35 ], [ 1, %1 ]
%13 = phi i8 [ %39, %35 ], [ %9, %1 ]
%14 = phi i8 [ %37, %35 ], [ %7, %1 ]
%15 = phi i32 [ %36, %35 ], [ 1, %1 ]
%16 = add nuw i64 %12, 1
%17 = tail call i32 @tolower(i8 signext %13)
%18 = add i32 %17, -98
%19 = icmp ult i32 %18, 25
br i1 %19, label %20, label %35
20: ; preds = %11
%21 = lshr i32 22535991, %18
%22 = and i32 %21, 1
%23 = icmp eq i32 %22, 0
br i1 %23, label %35, label %24
24: ; preds = %20
%25 = sext i32 %18 to i64
%26 = getelementptr inbounds [25 x i8], [25 x i8]* @switch.table.soundex, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = sext i8 %14 to i32
%30 = icmp eq i32 %28, %29
br i1 %30, label %35, label %31
31: ; preds = %24
%32 = add nsw i32 %15, 1
%33 = sext i32 %15 to i64
%34 = getelementptr inbounds i8, i8* %3, i64 %33
store i8 %27, i8* %34
br label %35
35: ; preds = %20, %11, %31, %24
%36 = phi i32 [ %32, %31 ], [ %15, %24 ], [ %15, %11 ], [ %15, %20 ]
%37 = phi i8 [ %27, %31 ], [ %14, %24 ], [ %14, %11 ], [ %14, %20 ]
%38 = getelementptr inbounds i8, i8* %0, i64 %16
%39 = load i8, i8* %38
%40 = icmp ne i8 %39, 0
%41 = icmp slt i32 %36, 4
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %11, label %43
43: ; preds = %35, %1
%44 = getelementptr inbounds i8, i8* %3, i64 4
store i8 0, i8* %44
ret i8* %3
}