#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 */
float average(float *, int);
float convert(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, float);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc == 1) {
    fprintf(stderr, "usage: %s grade\n", argv[0]);
    exit(1);
  }
  float entry[100];
  int i = 0;
  float a;
  for (i = 0; i < argc - 1; i++) {
    entry[i] = convert(argv[argc - 1 - i]);
  }
  a = average(entry, i);
  printf("the average is : %f.\n", a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1199 <main+0x49>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x1a4(%rbp)
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1201 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x1a4(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <convert@plt>
movslq -0x1a4(%rbp),%rax
movss  %xmm0,-0x1a0(%rbp,%rax,4)
ff ff
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    11ad <main+0x5d>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
call   1060 <average@plt>
movss  %xmm0,-0x1a8(%rbp)
ff
movss  -0x1a8(%rbp),%xmm0
ff
lea    0xde7(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x198,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
je     11be <main+0x6e>
mov    %edi,%r14d
xor    %esi,%esi
cmp    $0x2,%edi
jl     119a <main+0x4a>
add    $0xffffffff,%r14d
mov    %r14d,%ebp
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    (%r15,%rbp,8),%rdi
call   1030 <convert@plt>
movss  %xmm0,(%rbx)
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1180 <main+0x30>
mov    %r14d,%esi
mov    %rsp,%rdi
call   1060 <average@plt>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe2f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s grade\0A\00"
@.str.1 = [22 x i8] c"the average is : %f.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x float]
%7 = alloca i32
%8 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i32 0, i32* %7
store i32 0, i32* %7
br label %19
19: ; preds = %37, %18
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %40
24: ; preds = %19
%25 = load i8**, i8*** %5
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = load i32, i32* %7
%29 = sub nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %25, i64 %30
%32 = load i8*, i8** %31
%33 = call float @convert(i8* %32)
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x float], [100 x float]* %6, i64 0, i64 %35
store float %33, float* %36
br label %37
37: ; preds = %24
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %19
40: ; preds = %19
%41 = getelementptr inbounds [100 x float], [100 x float]* %6, i64 0, i64 0
%42 = load i32, i32* %7
%43 = call float @average(float* %41, i32 %42)
store float %43, float* %8
%44 = load float, float* %8
%45 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), float %44)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s grade\0A\00"
@.str.1 = [22 x i8] c"the average is : %f.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x float]
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast [100 x float]* %3 to i8*
%12 = add i32 %0, -1
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = zext i32 %12 to i64
%16 = zext i32 %12 to i64
br label %17
17: ; preds = %14, %17
%18 = phi i64 [ 0, %14 ], [ %24, %17 ]
%19 = sub nsw i64 %15, %18
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call float @convert(i8* %21)
%23 = getelementptr inbounds [100 x float], [100 x float]* %3, i64 0, i64 %18
store float %22, float* %23
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %16
br i1 %25, label %26, label %17
26: ; preds = %17, %10
%27 = phi i32 [ 0, %10 ], [ %12, %17 ]
%28 = getelementptr inbounds [100 x float], [100 x float]* %3, i64 0, i64 0
%29 = call float @average(float* %28, i32 %27)
%30 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), float %29)
ret i32 0
}