#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 letterscore(char);
int strlen(char *);
void assign_score(char *str, int *ctr, int elementnum) {
  if (str) {
    int i;
    for (i = 0; i < strlen(str); i++) {
      *ctr += letterscore(str[i]) * elementnum;
    }
  }
}


x86 assembly (clang, -O0):
<assign_score>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1193 <assign_score+0x73>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    118e <assign_score+0x6e>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <letterscore@plt>
mov    %eax,%ecx
imul   -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <assign_score+0x25>
jmp    1193 <assign_score+0x73>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assign_score>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1164 <assign_score+0x44>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
jle    1164 <assign_score+0x44>
xor    %ebx,%ebx
movsbl 0x0(%rbp,%rbx,1),%edi
call   1040 <letterscore@plt>
imul   %r14d,%eax
add    %eax,(%r15)
add    $0x1,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <assign_score+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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