#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 */
double RAND_MAX;
int /*<<< orphan*/ printf(char *, float, ...);
scalar_t__ rand();
void print_random_array() {
  int index;
  float array[20], sum = 0;
  for (index = 0; index < 20; index++) {
    array[index] = (double)rand() / RAND_MAX;
    printf("The element %d is equal to %f\n", index + 1, array[index]);
    sum += array[index];
  }
  printf("The sum of 20 elemetns is %f\n", sum);
}


x86 assembly (clang, -O0):
<print_random_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,-0x64(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x14,-0x4(%rbp)
jge    11ae <print_random_array+0x8e>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e94(%rip),%rax
divsd  (%rax),%xmm0
cvtsd2ss %xmm0,%xmm0
movslq -0x4(%rbp),%rax
movss  %xmm0,-0x60(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
movslq -0x4(%rbp),%rax
movss  -0x60(%rbp,%rax,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe7b(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movslq -0x4(%rbp),%rax
movss  -0x60(%rbp,%rax,4),%xmm0
addss  -0x64(%rbp),%xmm0
movss  %xmm0,-0x64(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1137 <print_random_array+0x17>
movss  -0x64(%rbp),%xmm0
lea    0xe65(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_random_array>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
mov    $0x1,%ebp
mov    0x2eb1(%rip),%r14
lea    0xec2(%rip),%rbx
xchg   %ax,%ax
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
cvtss2sd %xmm1,%xmm1
mov    %rbx,%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm0
addss  0x8(%rsp),%xmm0
add    $0x1,%ebp
cmp    $0x15,%ebp
jne    1140 <print_random_array+0x20>
lea    0xe88(%rip),%rdi
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
@.str = [31 x i8] c"The element %d is equal to %f\0A\00"
@.str.1 = [30 x i8] c"The sum of 20 elemetns is %f\0A\00"
define void @print_random_array() {
%1 = alloca i32
%2 = alloca [20 x float]
%3 = alloca float
store float 0.000000e+00, float* %3
store i32 0, i32* %1
br label %4
4: ; preds = %31, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 20
br i1 %6, label %7, label %34
7: ; preds = %4
%8 = call i64 (...) @rand()
%9 = sitofp i64 %8 to double
%10 = load double, double* @RAND_MAX
%11 = fdiv double %9, %10
%12 = fptrunc double %11 to float
%13 = load i32, i32* %1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [20 x float], [20 x float]* %2, i64 0, i64 %14
store float %12, float* %15
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
%18 = sitofp i32 %17 to float
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [20 x float], [20 x float]* %2, i64 0, i64 %20
%22 = load float, float* %21
%23 = fpext float %22 to double
%24 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), float %18, double %23)
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [20 x float], [20 x float]* %2, i64 0, i64 %26
%28 = load float, float* %27
%29 = load float, float* %3
%30 = fadd float %29, %28
store float %30, float* %3
br label %31
31: ; preds = %7
%32 = load i32, i32* %1
%33 = add nsw i32 %32, 1
store i32 %33, i32* %1
br label %4
34: ; preds = %4
%35 = load float, float* %3
%36 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), float %35)
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@.str = [31 x i8] c"The element %d is equal to %f\0A\00"
@.str.1 = [30 x i8] c"The sum of 20 elemetns is %f\0A\00"
define void @print_random_array() {
br label %1
1: ; preds = %0, %1
%2 = phi float [ 0.000000e+00, %0 ], [ %13, %1 ]
%3 = phi i32 [ 0, %0 ], [ %9, %1 ]
%4 = tail call i64 (...) @rand()
%5 = sitofp i64 %4 to double
%6 = load double, double* @RAND_MAX
%7 = fdiv double %5, %6
%8 = fptrunc double %7 to float
%9 = add nuw nsw i32 %3, 1
%10 = sitofp i32 %9 to float
%11 = fpext float %8 to double
%12 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), float %10, double %11)
%13 = fadd float %2, %8
%14 = icmp eq i32 %9, 20
br i1 %14, label %15, label %1
15: ; preds = %1
%16 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), float %13)
ret void
}