#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 getAmountArray(int *, int);
double getAverageArray(int *, int);
size_t getMostDifferentFromAverage(int *, int);
int /*<<< orphan*/ getRandomArray(int *, int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a[100];
  int choice = -1;
  while (choice != 0) {
    printf("1. Fill array randomly\n");
    printf("2. Print array\n");
    printf("3. Get amount of array elements\n");
    printf("4. Get average\n");
    printf("5. Get the number of element which the most different from the "
           "average\n");
    printf("0. Exit\n: ");
    scanf("%d", &choice);
    switch (choice) {
    case 1:
      getRandomArray(a, 100);
      break;
    case 2:
      printArray(a, 100);
      break;
    case 3:
      printf("The amount is %d.\n", getAmountArray(a, 100));
      break;
    case 4:
      printf("The average is %.2f.\n", getAverageArray(a, 100));
      break;
    case 5:
      printf("The element a[ %d ] = %d is the most differen from average.\n",
             getMostDifferentFromAverage(a, 100),
             a[getMostDifferentFromAverage(a, 100)]);
      break;
    case 0:
      printf("The end.\n");
      break;
    default:
      printf("Wrong number, try again\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x1a4(%rbp)
ff ff ff
cmpl   $0x0,-0x1a4(%rbp)
je     132e <main+0x1be>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x1b1(%rbp)
call   1040 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x1a4(%rbp),%eax
mov    %rax,-0x1b0(%rbp)
sub    $0x5,%rax
ja     131b <main+0x1ab>
mov    -0x1b0(%rbp),%rax
lea    0xdc1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1050 <getRandomArray@plt>
jmp    1329 <main+0x1b9>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1070 <printArray@plt>
jmp    1329 <main+0x1b9>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1080 <getAmountArray@plt>
mov    %eax,%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1329 <main+0x1b9>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1030 <getAverageArray@plt>
lea    0xe28(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1329 <main+0x1b9>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1090 <getMostDifferentFromAverage@plt>
mov    %rax,-0x1c0(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1090 <getMostDifferentFromAverage@plt>
mov    -0x1c0(%rbp),%rsi
mov    -0x1a0(%rbp,%rax,4),%edx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1329 <main+0x1b9>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1329 <main+0x1b9>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118c <main+0x1c>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xeec(%rip),%rbx
lea    0xefc(%rip),%rbp
lea    0xf04(%rip),%r12
lea    0xf1d(%rip),%r14
lea    0xf25(%rip),%r15
lea    0xe55(%rip),%r13
jmp    11dc <main+0x5c>
lea    0xf65(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
je     1304 <main+0x184>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe0e(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x5,%rax
ja     11c5 <main+0x45>
lea    0xdd0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xee8(%rip),%rdi
jmp    11cc <main+0x4c>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1060 <getRandomArray@plt>
jmp    11d1 <main+0x51>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1080 <printArray@plt>
jmp    11d1 <main+0x51>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1090 <getAmountArray@plt>
lea    0xda6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d1 <main+0x51>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1040 <getAverageArray@plt>
lea    0xd95(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    11d1 <main+0x51>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   10a0 <getMostDifferentFromAverage@plt>
mov    %r15,%r13
mov    %r14,%r15
mov    %r12,%r14
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   10a0 <getMostDifferentFromAverage@plt>
mov    0x10(%rsp,%rax,4),%edx
lea    0xd6a(%rip),%rdi
mov    %r12,%rsi
mov    %r14,%r12
mov    %r15,%r14
mov    %r13,%r15
lea    0xd20(%rip),%r13
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d1 <main+0x51>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"1. Fill array randomly\0A\00"
@.str.1 = [16 x i8] c"2. Print array\0A\00"
@.str.2 = [33 x i8] c"3. Get amount of array elements\0A\00"
@.str.3 = [16 x i8] c"4. Get average\0A\00"
@.str.4 = [72 x i8] c"5. Get the number of element which the most different from the average\0A\00"
@.str.5 = [11 x i8] c"0. Exit\0A: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [19 x i8] c"The amount is %d.\0A\00"
@.str.8 = [22 x i8] c"The average is %.2f.\0A\00"
@.str.9 = [61 x i8] c"The element a[ %d ] = %d is the most differen from average.\0A\00"
@.str.10 = [10 x i8] c"The end.\0A\00"
@.str.11 = [25 x i8] c"Wrong number, try again\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %3
br label %4
4: ; preds = %42, %0
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %43
7: ; preds = %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
switch i32 %15, label %40 [
i32 1, label %16
i32 2, label %19
i32 3, label %22
i32 4, label %26
i32 5, label %30
i32 0, label %38
]
16: ; preds = %7
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%18 = call i32 @getRandomArray(i32* %17, i32 100)
br label %42
19: ; preds = %7
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%21 = call i32 @printArray(i32* %20, i32 100)
br label %42
22: ; preds = %7
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%24 = call i32 @getAmountArray(i32* %23, i32 100)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %24)
br label %42
26: ; preds = %7
%27 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%28 = call double @getAverageArray(i32* %27, i32 100)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), double %28)
br label %42
30: ; preds = %7
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%32 = call i64 @getMostDifferentFromAverage(i32* %31, i32 100)
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%34 = call i64 @getMostDifferentFromAverage(i32* %33, i32 100)
%35 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0), i64 %32, i32 %36)
br label %42
38: ; preds = %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
br label %42
40: ; preds = %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
br label %42
42: ; preds = %40, %38, %30, %26, %22, %19, %16
br label %4
43: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str.5 = [11 x i8] c"0. Exit\0A: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [19 x i8] c"The amount is %d.\0A\00"
@.str.8 = [22 x i8] c"The average is %.2f.\0A\00"
@.str.9 = [61 x i8] c"The element a[ %d ] = %d is the most differen from average.\0A\00"
@str = [23 x i8] c"1. Fill array randomly\00"
@str.12 = [15 x i8] c"2. Print array\00"
@str.13 = [32 x i8] c"3. Get amount of array elements\00"
@str.14 = [15 x i8] c"4. Get average\00"
@str.15 = [71 x i8] c"5. Get the number of element which the most different from the average\00"
@str.16 = [9 x i8] c"The end.\00"
@str.17 = [24 x i8] c"Wrong number, try again\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
br label %6
6: ; preds = %0, %35
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.14, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.15, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
switch i32 %14, label %33 [
i32 1, label %15
i32 2, label %17
i32 3, label %19
i32 4, label %22
i32 5, label %25
i32 0, label %31
]
15: ; preds = %6
%16 = call i32 @getRandomArray(i32* %5, i32 100)
br label %35
17: ; preds = %6
%18 = call i32 @printArray(i32* %5, i32 100)
br label %35
19: ; preds = %6
%20 = call i32 @getAmountArray(i32* %5, i32 100)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %20)
br label %35
22: ; preds = %6
%23 = call double @getAverageArray(i32* %5, i32 100)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), double %23)
br label %35
25: ; preds = %6
%26 = call i64 @getMostDifferentFromAverage(i32* %5, i32 100)
%27 = call i64 @getMostDifferentFromAverage(i32* %5, i32 100)
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0), i64 %26, i32 %29)
br label %35
31: ; preds = %6
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0))
br label %35
33: ; preds = %6
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.17, i64 0, i64 0))
br label %35
35: ; preds = %33, %31, %25, %22, %19, %17, %15
%36 = load i32, i32* %2
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %6
38: ; preds = %35
ret i32 0
}