#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*/ assert(int);
unsigned computeIndex(const char text[]) {
  unsigned result = 0;
  unsigned i = 0;
  while (text[i] != 0) {
    result = 127 * result + text[i];
    ++i;
  }
  assert(i < 31);
  return result;
}


x86 assembly (clang, -O0):
<computeIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1160 <computeIndex+0x50>
imul   $0x7f,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <computeIndex+0x1a>
cmpl   $0x1f,-0x10(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeIndex>:
push   %rbx
mov    (%rdi),%cl
test   %cl,%cl
je     1144 <computeIndex+0x34>
xor    %eax,%eax
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl %cl,%ecx
mov    %ebx,%edx
shl    $0x7,%edx
sub    %ebx,%edx
mov    %edx,%ebx
add    %ecx,%ebx
add    $0x1,%eax
movzbl (%rdi,%rax,1),%ecx
test   %cl,%cl
jne    1120 <computeIndex+0x10>
xor    %edi,%edi
cmp    $0x1f,%eax
setb   %dil
jmp    114b <computeIndex+0x3b>
mov    $0x1,%edi
xor    %ebx,%ebx
call   1030 <assert@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

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