#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 /*<<< orphan*/ printf(char *);
int getweight(char *p, int *alphap, int len) {
  int i, weight = 0;
  int index;
  for (i = 0; i < len; i++) {
    index = ((int)(*p) - 65);
    if (index < (26)) {
      weight += alphap[index];
    } else {
      printf("wrong index\n");
    }
    p++;
  }
  return weight;
}


x86 assembly (clang, -O0):
<getweight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1190 <getweight+0x80>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x41,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1a,-0x20(%rbp)
jge    116a <getweight+0x5a>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <getweight+0x66>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <getweight+0x21>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getweight>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1166 <getweight+0x56>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r13d
xor    %ebx,%ebx
lea    0xecf(%rip),%r15
xor    %ebp,%ebp
jmp    1151 <getweight+0x41>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1030 <puts@plt>
add    $0x1,%rbx
cmp    %ebx,%r13d
je     1168 <getweight+0x58>
movsbq (%r12,%rbx,1),%rax
cmp    $0x5a,%rax
jg     1140 <getweight+0x30>
add    -0x104(%r14,%rax,4),%ebp
ff
jmp    1148 <getweight+0x38>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"wrong index\0A\00"
define i32 @getweight(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %10
10: ; preds = %34, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = sub nsw i32 %17, 65
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 26
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = load i32*, i32** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %8
%28 = add nsw i32 %27, %26
store i32 %28, i32* %8
br label %31
29: ; preds = %14
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %21
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
br label %34
34: ; preds = %31
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %10
37: ; preds = %10
%38 = load i32, i32* %8
ret i32 %38
}

LLVM IR (-O2):
@str = [12 x i8] c"wrong index\00"
define i32 @getweight(i8* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %24
5: ; preds = %3, %19
%6 = phi i8* [ %21, %19 ], [ %0, %3 ]
%7 = phi i32 [ %20, %19 ], [ 0, %3 ]
%8 = phi i32 [ %22, %19 ], [ 0, %3 ]
%9 = load i8, i8* %6
%10 = icmp slt i8 %9, 91
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = sext i8 %9 to i64
%13 = add nsw i64 %12, -65
%14 = getelementptr inbounds i32, i32* %1, i64 %13
%15 = load i32, i32* %14
%16 = add nsw i32 %15, %7
br label %19
17: ; preds = %5
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
%20 = phi i32 [ %16, %11 ], [ %7, %17 ]
%21 = getelementptr inbounds i8, i8* %6, i64 1
%22 = add nuw nsw i32 %8, 1
%23 = icmp eq i32 %22, %2
br i1 %23, label %24, label %5
24: ; preds = %19, %3
%25 = phi i32 [ 0, %3 ], [ %20, %19 ]
ret i32 %25
}