#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 sre_toupper(int);
int GCGchecksum(char *seq, int seqlen) {
  int check = 0, count = 0, i;
  for (i = 0; i < seqlen; i++) {
    count++;
    check += count * sre_toupper((int)seq[i]);
    if (count == 57)
      count = 0;
  }
  return (check % 10000);
}


x86 assembly (clang, -O0):
<GCGchecksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <GCGchecksum+0x82>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <sre_toupper@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x39,-0x14(%rbp)
jne    117f <GCGchecksum+0x6f>
movl   $0x0,-0x14(%rbp)
jmp    1184 <GCGchecksum+0x74>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1134 <GCGchecksum+0x24>
mov    -0x10(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GCGchecksum>:
test   %esi,%esi
jle    1181 <GCGchecksum+0x71>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%r12d
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r13d,%r13d
nop
add    $0x1,%ebp
movsbl (%r14,%rbx,1),%edi
call   1030 <sre_toupper@plt>
imul   %ebp,%eax
add    %eax,%r13d
cmp    $0x39,%ebp
cmove  %r15d,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <GCGchecksum+0x20>
movslq %r13d,%rax
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

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

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