#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 name_score(char *);
long name_scores_total(char **name_list, int length) {
  long total = 0;
  for (int idx = 0; idx < length; idx++) {
    int score = name_score(name_list[idx]);
    total += (score * (idx + 1));
  }
  return total;
}


x86 assembly (clang, -O0):
<name_scores_total>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1172 <name_scores_total+0x62>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <name_score@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
cltq
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <name_scores_total+0x1e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<name_scores_total>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    114f <name_scores_total+0x3f>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1030 <name_score@plt>
add    $0x1,%rbx
mov    %ebx,%ecx
imul   %eax,%ecx
movslq %ecx,%rax
add    %rax,%r12
cmp    %rbx,%r15
jne    1130 <name_scores_total+0x20>
jmp    1152 <name_scores_total+0x42>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @name_scores_total(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %8
8: ; preds = %26, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load i8**, i8*** %3
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @name_score(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
%22 = mul nsw i32 %19, %21
%23 = sext i32 %22 to i64
%24 = load i64, i64* %5
%25 = add nsw i64 %24, %23
store i64 %25, i64* %5
br label %26
26: ; preds = %12
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %8
29: ; preds = %8
%30 = load i64, i64* %5
ret i64 %30
}

LLVM IR (-O2):
define i64 @name_scores_total(i8** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %8, %2
%7 = phi i64 [ 0, %2 ], [ %18, %8 ]
ret i64 %7
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %14, %8 ]
%10 = phi i64 [ 0, %4 ], [ %18, %8 ]
%11 = getelementptr inbounds i8*, i8** %0, i64 %9
%12 = load i8*, i8** %11
%13 = tail call i32 @name_score(i8* %12)
%14 = add nuw nsw i64 %9, 1
%15 = trunc i64 %14 to i32
%16 = mul nsw i32 %13, %15
%17 = sext i32 %16 to i64
%18 = add nsw i64 %10, %17
%19 = icmp eq i64 %14, %5
br i1 %19, label %6, label %8
}