#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 atoi(char const *);
int calculateGradeAverage(int *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ version();
int main(int argc, char const *argv[]) {
  int i;
  int *studentsGrade;
  if (argc == 1) {
    usage();
  } else if (argc == 2) {
    if (strcmp(argv[1], "-v") == 0) {
      version();
    } else if (strcmp(argv[1], "-d") == 0) {
      printf("Not supported yet.\n");
      usage();
    } else {
      usage();
    }
  } else {
    if (strcmp(argv[1], "-s") != 0) {
      usage();
    } else {
      studentsGrade = (int *)calloc((argc - 2), sizeof(int));
      for (i = 0; i < argc - 2; ++i) {
        studentsGrade[i] = atoi(argv[i + 2]);
      }
    }
  }
  printf("Students grade average is %d.\n",
         calculateGradeAverage(studentsGrade, argc - 2));
  free(studentsGrade);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ac <main+0x2c>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    12bf <main+0x13f>
cmpl   $0x2,-0x8(%rbp)
jne    1229 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e0 <main+0x60>
mov    $0x0,%al
call   1070 <version@plt>
jmp    1224 <main+0xa4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1218 <main+0x98>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    121f <main+0x9f>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    1224 <main+0xa4>
jmp    12ba <main+0x13a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde2(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1253 <main+0xd3>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    12b5 <main+0x135>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    12b0 <main+0x130>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    126e <main+0xee>
jmp    12b5 <main+0x135>
jmp    12ba <main+0x13a>
jmp    12bf <main+0x13f>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x2,%esi
call   10a0 <calculateGradeAverage@plt>
mov    %eax,%esi
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%r14d
cmp    $0x2,%edi
je     11f8 <main+0x68>
cmp    $0x1,%r14d
je     122e <main+0x9e>
mov    0x8(%r15),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    122e <main+0x9e>
lea    -0x2(%r14),%ebp
mov    %ebp,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
cmp    $0x3,%r14d
jl     1235 <main+0xa5>
mov    %ebp,%r12d
xor    %ebp,%ebp
mov    0x10(%r15,%rbp,8),%rdi
call   10a0 <atoi@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    11e0 <main+0x50>
jmp    1235 <main+0xa5>
mov    0x8(%r15),%rdi
lea    0xdfd(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1267 <main+0xd7>
mov    0x8(%r15),%rdi
lea    0xdeb(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    122e <main+0x9e>
lea    0xdff(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <usage@plt>
add    $0xfffffffe,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   10b0 <calculateGradeAverage@plt>
lea    0xdbe(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1080 <version@plt>
jmp    1235 <main+0xa5>

LLVM IR (-O0):
@.str = [3 x i8] c"-v\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [20 x i8] c"Not supported yet.\0A\00"
@.str.3 = [3 x i8] c"-s\00"
@.str.4 = [31 x i8] c"Students grade average is %d.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @usage()
br label %72
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (...) @version()
br label %35
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 (...) @usage()
br label %34
32: ; preds = %23
%33 = call i32 (...) @usage()
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34, %21
br label %71
36: ; preds = %12
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 (...) @usage()
br label %70
44: ; preds = %36
%45 = load i32, i32* %4
%46 = sub nsw i32 %45, 2
%47 = call i64 @calloc(i32 %46, i32 4)
%48 = inttoptr i64 %47 to i32*
store i32* %48, i32** %7
store i32 0, i32* %6
br label %49
49: ; preds = %66, %44
%50 = load i32, i32* %6
%51 = load i32, i32* %4
%52 = sub nsw i32 %51, 2
%53 = icmp slt i32 %50, %52
br i1 %53, label %54, label %69
54: ; preds = %49
%55 = load i8**, i8*** %5
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %55, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @atoi(i8* %60)
%62 = load i32*, i32** %7
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
store i32 %61, i32* %65
br label %66
66: ; preds = %54
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %49
69: ; preds = %49
br label %70
70: ; preds = %69, %42
br label %71
71: ; preds = %70, %35
br label %72
72: ; preds = %71, %10
%73 = load i32*, i32** %7
%74 = load i32, i32* %4
%75 = sub nsw i32 %74, 2
%76 = call i32 @calculateGradeAverage(i32* %73, i32 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %76)
%78 = load i32*, i32** %7
%79 = call i32 @free(i32* %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-v\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.3 = [3 x i8] c"-s\00"
@.str.4 = [31 x i8] c"Students grade average is %d.\0A\00"
@str = [19 x i8] c"Not supported yet.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %21 [
i32 1, label %3
i32 2, label %5
]
3: ; preds = %2
%4 = tail call i32 (...) @usage()
br label %44
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 (...) @version()
br label %44
12: ; preds = %5
%13 = load i8*, i8** %6
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 (...) @usage()
br label %44
19: ; preds = %12
%20 = tail call i32 (...) @usage()
br label %44
21: ; preds = %2
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = tail call i32 (...) @usage()
br label %44
28: ; preds = %21
%29 = add nsw i32 %0, -2
%30 = tail call i64 @calloc(i32 %29, i32 4)
%31 = inttoptr i64 %30 to i32*
%32 = icmp sgt i32 %0, 2
br i1 %32, label %33, label %44
33: ; preds = %28
%34 = zext i32 %29 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %42, %35 ]
%37 = add nuw nsw i64 %36, 2
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = tail call i32 @atoi(i8* %39)
%41 = getelementptr inbounds i32, i32* %31, i64 %36
store i32 %40, i32* %41
%42 = add nuw nsw i64 %36, 1
%43 = icmp eq i64 %42, %34
br i1 %43, label %44, label %35
44: ; preds = %35, %28, %16, %19, %10, %26, %3
%45 = phi i32* [ undef, %3 ], [ undef, %10 ], [ undef, %16 ], [ undef, %19 ], [ undef, %26 ], [ %31, %28 ], [ %31, %35 ]
%46 = add nsw i32 %0, -2
%47 = tail call i32 @calculateGradeAverage(i32* %45, i32 %46)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = tail call i32 @free(i32* %45)
ret i32 0
}