#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*/ sscanf(char const *, char *, char *, float *);
float avg(const char *a[]) {
  float sum = 0, vel = 0;
  int i;
  char direction[10];
  for (i = 0; a[i]; i++) {
    sscanf(a[i], "%s%d", direction, &vel);
    sum += vel;
  }
  return sum / i;
}


x86 assembly (clang, -O0):
<avg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1183 <avg+0x73>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x1e(%rbp),%rdx
lea    0xea3(%rip),%rsi
lea    -0x10(%rbp),%rcx
call   1030 <sscanf@plt>
movss  -0x10(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <avg+0x23>
movss  -0xc(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avg>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r13
movl   $0x0,0xc(%rsp)
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1188 <avg+0x78>
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
lea    0xec8(%rip),%r14
lea    0x16(%rsp),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
movss  %xmm0,0x10(%rsp)
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <sscanf@plt>
movss  0x10(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
mov    0x8(%r13,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1150 <avg+0x40>
cvtsi2ss %ebx,%xmm1
divss  %xmm1,%xmm0
jmp    1190 <avg+0x80>
movss  0xe70(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%d\00"
define float @avg(i8** %0) {
%2 = alloca i8**
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca [10 x i8]
store i8** %0, i8*** %2
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %4
store i32 0, i32* %5
br label %7
7: ; preds = %25, %1
%8 = load i8**, i8*** %2
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %28
14: ; preds = %7
%15 = load i8**, i8*** %2
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %20, float* %4)
%22 = load float, float* %4
%23 = load float, float* %3
%24 = fadd float %23, %22
store float %24, float* %3
br label %25
25: ; preds = %14
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %7
28: ; preds = %7
%29 = load float, float* %3
%30 = load i32, i32* %5
%31 = sitofp i32 %30 to float
%32 = fdiv float %29, %31
ret float %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%d\00"
define float @avg(i8** nocapture %0) {
%2 = alloca float
%3 = alloca [10 x i8]
%4 = bitcast float* %2 to i8*
store float 0.000000e+00, float* %2
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %23, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %15, %8 ], [ 0, %1 ]
%10 = phi i8* [ %17, %8 ], [ %6, %1 ]
%11 = phi float [ %14, %8 ], [ 0.000000e+00, %1 ]
%12 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5, float* %2)
%13 = load float, float* %2
%14 = fadd float %11, %13
%15 = add nuw i64 %9, 1
%16 = getelementptr inbounds i8*, i8** %0, i64 %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %8
19: ; preds = %8
%20 = trunc i64 %15 to i32
%21 = sitofp i32 %20 to float
%22 = fdiv float %14, %21
br label %23
23: ; preds = %19, %1
%24 = phi float [ %22, %19 ], [ 0x7FF8000000000000, %1 ]
ret float %24
}