#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 */
scalar_t__ EOF;
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
long name_value(char *);
int /*<<< orphan*/ printf(char *, long);
int main(void) {
  FILE *fd = fopen("../res/022.data", "r");
  char str[30];
  long name_sum = 0;
  size_t position = 1;
  while (fscanf(fd, "%30s", str) != EOF)
    name_sum += position++ * name_value(str);
  printf("%ld\n", name_sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x1,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
je     11cb <main+0x8b>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <name_value@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
imul   %rcx,%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1176 <main+0x36>
mov    -0x38(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xeab(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xea7(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e6b(%rip),%r12
cmp    (%r12),%rax
jne    1187 <main+0x47>
xor    %ebx,%ebx
jmp    11ce <main+0x8e>
mov    $0x1,%ebp
xor    %ebx,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbp),%r13
mov    %r15,%rdi
call   1050 <name_value@plt>
imul   %rbp,%rax
add    %rax,%rbx
mov    %r14,%rdi
lea    0xe55(%rip),%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
mov    %r13,%rbp
cmp    (%r12),%rax
jne    11a0 <main+0x60>
lea    0xe42(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"../res/022.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%30s\00"
@EOF = global i64 0
@.str.3 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [30 x i8]
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
store i64 0, i64* %4
store i64 1, i64* %5
br label %7
7: ; preds = %13, %0
%8 = load i32*, i32** %2
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%10 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i64, i64* @EOF
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = load i64, i64* %5
%15 = add i64 %14, 1
store i64 %15, i64* %5
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%17 = call i64 @name_value(i8* %16)
%18 = mul i64 %14, %17
%19 = load i64, i64* %4
%20 = add i64 %19, %18
store i64 %20, i64* %4
br label %7
21: ; preds = %7
%22 = load i64, i64* %4
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"../res/022.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%30s\00"
@EOF = global i64 0
@.str.3 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %17, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %10, %7 ], [ 1, %0 ]
%9 = phi i64 [ %13, %7 ], [ 0, %0 ]
%10 = add i64 %8, 1
%11 = call i64 @name_value(i8* %3)
%12 = mul i64 %11, %8
%13 = add i64 %12, %9
%14 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %7
17: ; preds = %7, %0
%18 = phi i64 [ 0, %0 ], [ %13, %7 ]
%19 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %18)
ret i32 0
}