char **letterCombinations(char *digits, int *returnSize) {
  char map[10][5] = {" ",   "",    "abc",  "def", "ghi",
                     "jkl", "mno", "pqrs", "tuv", "wxyz"};
  char **res, *tmp;
  int num = 1, length = 0, top = 0;
  while (digits[length]) {
    if (digits[length] == '0' || digits[length] == '1')
      continue;
    else if (digits[length] == '7' || digits[length] == '9')
      num *= 4;
    else
      num *= 3;
    length++;
  }
  res = (char **)malloc(sizeof(char *) * num);
  if (length == 0) {
    *returnSize = 0;
    return res;
  }
  tmp = (char *)malloc(sizeof(char) * length);
  getLetterCom(res, digits, tmp, 0, map, &top);
  *returnSize = top;
  return res;
}


x86 assembly (clang, -O0):
<letterCombinations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x32,%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11fd <letterCombinations+0xcd>
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
je     11a6 <letterCombinations+0x76>
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    11ab <letterCombinations+0x7b>
jmp    116a <letterCombinations+0x3a>
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x37,%eax
je     11d5 <letterCombinations+0xa5>
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
jne    11e3 <letterCombinations+0xb3>
mov    -0x64(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x64(%rbp)
jmp    11ea <letterCombinations+0xba>
imul   $0x3,-0x64(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    11ef <letterCombinations+0xbf>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    116a <letterCombinations+0x3a>
movslq -0x64(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpl   $0x0,-0x68(%rbp)
jne    122f <letterCombinations+0xff>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126e <letterCombinations+0x13e>
movslq -0x68(%rbp),%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x60(%rbp),%rdx
lea    -0x50(%rbp),%r8
xor    %ecx,%ecx
lea    -0x6c(%rbp),%r9
mov    $0x0,%al
call   1030 <getLetterCom@plt>
mov    -0x6c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<letterCombinations>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movzwl 0xef8(%rip),%eax
mov    %ax,0x40(%rsp)
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
mov    $0x1,%eax
xor    %ebx,%ebx
jmp    1187 <letterCombinations+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
shl    $0x2,%eax
add    $0x1,%rbx
movzbl (%r15,%rbx,1),%ecx
cmp    $0x37,%cl
je     1180 <letterCombinations+0x60>
cmp    $0x39,%cl
je     1180 <letterCombinations+0x60>
test   %cl,%cl
je     11a3 <letterCombinations+0x83>
lea    (%rax,%rax,2),%eax
add    $0x1,%rbx
jmp    1187 <letterCombinations+0x67>
movslq %eax,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
je     11e0 <letterCombinations+0xc0>
mov    %rbx,%rdi
call   1040 <malloc@plt>
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <getLetterCom@plt>
mov    0xc(%rsp),%eax
jmp    11e2 <letterCombinations+0xc2>
xor    %eax,%eax
mov    %eax,(%r14)
mov    %r12,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.letterCombinations.map = [10 x [5 x i8]] [[5 x i8] c" \00\00\00\00", [5 x i8] zeroinitializer, [5 x i8] c"abc\00\00", [5 x i8] c"def\00\00", [5 x i8] c"ghi\00\00", [5 x i8] c"jkl\00\00", [5 x i8] c"mno\00\00", [5 x i8] c"pqrs\00", [5 x i8] c"tuv\00\00", [5 x i8] c"wxyz\00"]
define i8** @letterCombinations(i8* %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [10 x [5 x i8]]
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%12 = bitcast [10 x [5 x i8]]* %6 to i8*
store i32 1, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %13
13: ; preds = %60, %36, %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %63
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 48
br i1 %27, label %36, label %28
28: ; preds = %20
%29 = load i8*, i8** %4
%30 = load i32, i32* %10
%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 eq i32 %34, 49
br i1 %35, label %36, label %37
36: ; preds = %28, %20
br label %13
37: ; preds = %28
%38 = load i8*, i8** %4
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 55
br i1 %44, label %53, label %45
45: ; preds = %37
%46 = load i8*, i8** %4
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 57
br i1 %52, label %53, label %56
53: ; preds = %45, %37
%54 = load i32, i32* %9
%55 = mul nsw i32 %54, 4
store i32 %55, i32* %9
br label %59
56: ; preds = %45
%57 = load i32, i32* %9
%58 = mul nsw i32 %57, 3
store i32 %58, i32* %9
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
br label %13
63: ; preds = %13
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = mul i64 8, %65
%67 = call i8* @malloc(i64 %66)
%68 = bitcast i8* %67 to i8**
store i8** %68, i8*** %7
%69 = load i32, i32* %10
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %63
%72 = load i32*, i32** %5
store i32 0, i32* %72
%73 = load i8**, i8*** %7
store i8** %73, i8*** %3
br label %87
74: ; preds = %63
%75 = load i32, i32* %10
%76 = sext i32 %75 to i64
%77 = mul i64 1, %76
%78 = call i8* @malloc(i64 %77)
store i8* %78, i8** %8
%79 = load i8**, i8*** %7
%80 = load i8*, i8** %4
%81 = load i8*, i8** %8
%82 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %6, i64 0, i64 0
%83 = call i32 (i8**, i8*, i8*, i32, [5 x i8]*, i32*, ...) bitcast (i32 (...)* @getLetterCom to i32 (i8**, i8*, i8*, i32, [5 x i8]*, i32*, ...)*)(i8** %79, i8* %80, i8* %81, i32 0, [5 x i8]* %82, i32* %11)
%84 = load i32, i32* %11
%85 = load i32*, i32** %5
store i32 %84, i32* %85
%86 = load i8**, i8*** %7
store i8** %86, i8*** %3
br label %87
87: ; preds = %74, %71
%88 = load i8**, i8*** %3
ret i8** %88
}

LLVM IR (-O2):
@__const.letterCombinations.map = [10 x [5 x i8]] [[5 x i8] c" \00\00\00\00", [5 x i8] zeroinitializer, [5 x i8] c"abc\00\00", [5 x i8] c"def\00\00", [5 x i8] c"ghi\00\00", [5 x i8] c"jkl\00\00", [5 x i8] c"mno\00\00", [5 x i8] c"pqrs\00", [5 x i8] c"tuv\00\00", [5 x i8] c"wxyz\00"]
define i8** @letterCombinations(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [10 x [5 x i8]]
%4 = alloca i32
%5 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %3, i64 0, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %16, %2
%8 = phi i64 [ %18, %16 ], [ 0, %2 ]
%9 = phi i32 [ %17, %16 ], [ 1, %2 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
switch i8 %11, label %14 [
i8 0, label %19
i8 55, label %12
i8 57, label %12
]
12: ; preds = %7, %7
%13 = shl nsw i32 %9, 2
br label %16
14: ; preds = %7
%15 = mul nsw i32 %9, 3
br label %16
16: ; preds = %12, %14
%17 = phi i32 [ %13, %12 ], [ %15, %14 ]
%18 = add nuw i64 %8, 1
br label %7
19: ; preds = %7
%20 = trunc i64 %8 to i32
%21 = sext i32 %9 to i64
%22 = shl nsw i64 %21, 3
%23 = tail call i8* @malloc(i64 %22)
%24 = bitcast i8* %23 to i8**
%25 = icmp eq i32 %20, 0
br i1 %25, label %31, label %26
26: ; preds = %19
%27 = tail call i8* @malloc(i64 %8)
%28 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %3, i64 0, i64 0
%29 = call i32 (i8**, i8*, i8*, i32, [5 x i8]*, i32*, ...) bitcast (i32 (...)* @getLetterCom to i32 (i8**, i8*, i8*, i32, [5 x i8]*, i32*, ...)*)(i8** %24, i8* %0, i8* %27, i32 0, [5 x i8]* %28, i32* %4)
%30 = load i32, i32* %4
br label %31
31: ; preds = %19, %26
%32 = phi i32 [ %30, %26 ], [ 0, %19 ]
store i32 %32, i32* %1
ret i8** %24
}