#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  FILE *fp = fopen("022_sorted.txt", "r");
  char c;
  int n = 0, names = 1, t = 0;
  while ((c = getc(fp)) != EOF) {
    if (c == ',') {
      t += names * n;
      names++;
      n = 0;
    }
    if ('A' <= c && c <= 'Z')
      n += c - '@';
  }
  t += names * n;
  printf("%d\n", t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e67(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11e6 <main+0xb6>
movsbl -0x11(%rbp),%eax
cmp    $0x2c,%eax
jne    11b6 <main+0x86>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
movsbl -0x11(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     11e1 <main+0xb1>
movsbl -0x11(%rbp),%eax
cmp    $0x5a,%eax
jg     11e1 <main+0xb1>
movsbl -0x11(%rbp),%eax
sub    $0x40,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    116b <main+0x3b>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <getc@plt>
mov    0x2e88(%rip),%r14
xor    %r13d,%r13d
cmp    (%r14),%al
je     11c4 <main+0x94>
mov    $0x1,%ebx
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%ecx
mov    %ebx,%edx
imul   %ebp,%edx
mov    %ebp,%esi
movsbl %al,%eax
xor    %ebx,%ebx
cmp    $0x2c,%al
sete   %bl
cmove  %r12d,%esi
cmovne %r12d,%edx
add    %ecx,%ebx
add    %edx,%r13d
lea    -0x41(%rax),%ecx
add    $0xffffffc0,%eax
cmp    $0x1a,%cl
cmovae %r12d,%eax
mov    %eax,%ebp
add    %esi,%ebp
mov    %r15,%rdi
call   1050 <getc@plt>
cmp    (%r14),%al
jne    1180 <main+0x50>
imul   %ebp,%ebx
add    %ebx,%r13d
lea    0xe46(%rip),%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"022_sorted.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
store i32 0, i32* %4
store i32 1, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %41, %0
%9 = load i32*, i32** %2
%10 = call signext i8 @getc(i32* %9)
store i8 %10, i8* %3
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %42
15: ; preds = %8
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 44
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32, i32* %5
%21 = load i32, i32* %4
%22 = mul nsw i32 %20, %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, %22
store i32 %24, i32* %6
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
store i32 0, i32* %4
br label %27
27: ; preds = %19, %15
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp sle i32 65, %29
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = icmp sle i32 %33, 90
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 64
%39 = load i32, i32* %4
%40 = add nsw i32 %39, %38
store i32 %40, i32* %4
br label %41
41: ; preds = %35, %31, %27
br label %8
42: ; preds = %8
%43 = load i32, i32* %5
%44 = load i32, i32* %4
%45 = mul nsw i32 %43, %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, %45
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"022_sorted.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call signext i8 @getc(i32* %1)
%3 = load i8, i8* @EOF
%4 = icmp eq i8 %2, %3
br i1 %4, label %29, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %23, %5 ], [ %2, %0 ]
%7 = phi i32 [ %17, %5 ], [ 0, %0 ]
%8 = phi i32 [ %15, %5 ], [ 1, %0 ]
%9 = phi i32 [ %22, %5 ], [ 0, %0 ]
%10 = sext i8 %6 to i32
%11 = icmp eq i8 %6, 44
%12 = mul nsw i32 %8, %9
%13 = select i1 %11, i32 0, i32 %9
%14 = zext i1 %11 to i32
%15 = add nuw nsw i32 %8, %14
%16 = select i1 %11, i32 %12, i32 0
%17 = add nsw i32 %16, %7
%18 = add i8 %6, -65
%19 = icmp ult i8 %18, 26
%20 = add nsw i32 %10, -64
%21 = select i1 %19, i32 %20, i32 0
%22 = add nsw i32 %21, %13
%23 = tail call signext i8 @getc(i32* %1)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %26, label %5
26: ; preds = %5
%27 = mul nsw i32 %15, %22
%28 = add nsw i32 %17, %27
br label %29
29: ; preds = %26, %0
%30 = phi i32 [ %28, %26 ], [ 0, %0 ]
%31 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
ret i32 0
}