#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int atoi(char *);
scalar_t__ clock();
float *compute_sqrts(float *, int);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Give me a number of FLOPs (100000000 for example)");
  } else {
    int n = atoi(argv[1]), i;
    float *input_array = (float *)malloc(n * sizeof(float));
    for (i = 0; i < n; i++) {
      input_array[i] = i;
    }
    clock_t t;
    t = clock();
    float *output_array = compute_sqrts(input_array, n);
    t = clock() - t;
    free(input_array);
    free(output_array);
    double time_taken = ((double)t) / CLOCKS_PER_SEC;
    printf("The program took %f seconds to execute %d square roots\n",
           time_taken, n);
    printf("MFLOPS (millions of floating point operations per second) = %f\n",
           n / time_taken / 1000000);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1193 <main+0x33>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1275 <main+0x115>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e9 <main+0x89>
cvtsi2ssl -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bd <main+0x5d>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <compute_sqrts@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cvtsi2sdq -0x28(%rbp),%xmm0
mov    0x2db6(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x14(%rbp),%esi
lea    0xdf0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cvtsi2sdl -0x14(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  0xd9d(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe04(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     1185 <main+0x25>
lea    0xedf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1318 <main+0x1b8>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1295 <main+0x135>
mov    %r14d,%eax
cmp    $0x8,%r14d
jae    11ba <main+0x5a>
xor    %ecx,%ecx
jmp    1280 <main+0x120>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     1328 <main+0x1c8>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
movdqa 0xe1a(%rip),%xmm0
xor    %esi,%esi
movdqa 0xe20(%rip),%xmm1
movdqa 0xe28(%rip),%xmm2
movdqa 0xe30(%rip),%xmm3
movdqa 0xe38(%rip),%xmm4
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
paddd  %xmm1,%xmm5
cvtdq2ps %xmm0,%xmm6
cvtdq2ps %xmm5,%xmm5
movups %xmm6,(%rbx,%rsi,4)
movups %xmm5,0x10(%rbx,%rsi,4)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
cvtdq2ps %xmm5,%xmm5
cvtdq2ps %xmm6,%xmm6
movups %xmm5,0x20(%rbx,%rsi,4)
movups %xmm6,0x30(%rbx,%rsi,4)
add    $0x10,%rsi
paddd  %xmm4,%xmm0
add    $0xfffffffffffffffe,%rdi
jne    1210 <main+0xb0>
test   $0x1,%dl
je     1271 <main+0x111>
cvtdq2ps %xmm0,%xmm1
paddd  0xdab(%rip),%xmm0
cvtdq2ps %xmm0,%xmm0
movups %xmm1,(%rbx,%rsi,4)
movups %xmm0,0x10(%rbx,%rsi,4)
cmp    %rax,%rcx
je     1295 <main+0x135>
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
movss  %xmm0,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1280 <main+0x120>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <compute_sqrts@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r13
sub    %r15,%r13
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r13,%xmm0
mov    0x2d0f(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xda0(%rip),%rdi
mov    %r14d,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  0x8(%rsp),%xmm0
divsd  0xd46(%rip),%xmm0
lea    0xdb1(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
movdqa 0xcd0(%rip),%xmm0
xor    %esi,%esi
test   $0x1,%dl
jne    125a <main+0xfa>
jmp    1271 <main+0x111>

LLVM IR (-O0):
@.str = [50 x i8] c"Give me a number of FLOPs (100000000 for example)\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [56 x i8] c"The program took %f seconds to execute %d square roots\0A\00"
@.str.2 = [64 x i8] c"MFLOPS (millions of floating point operations per second) = %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca i64
%10 = alloca float*
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %66
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to float*
store float* %26, float** %8
store i32 0, i32* %7
br label %27
27: ; preds = %38, %16
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = load i32, i32* %7
%33 = sitofp i32 %32 to float
%34 = load float*, float** %8
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds float, float* %34, i64 %36
store float %33, float* %37
br label %38
38: ; preds = %31
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %27
41: ; preds = %27
%42 = call i64 (...) @clock()
store i64 %42, i64* %9
%43 = load float*, float** %8
%44 = load i32, i32* %6
%45 = call float* @compute_sqrts(float* %43, i32 %44)
store float* %45, float** %10
%46 = call i64 (...) @clock()
%47 = load i64, i64* %9
%48 = sub nsw i64 %46, %47
store i64 %48, i64* %9
%49 = load float*, float** %8
%50 = call i32 @free(float* %49)
%51 = load float*, float** %10
%52 = call i32 @free(float* %51)
%53 = load i64, i64* %9
%54 = sitofp i64 %53 to double
%55 = load double, double* @CLOCKS_PER_SEC
%56 = fdiv double %54, %55
store double %56, double* %11
%57 = load double, double* %11
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), double %57, i32 %58)
%60 = load i32, i32* %6
%61 = sitofp i32 %60 to double
%62 = load double, double* %11
%63 = fdiv double %61, %62
%64 = fdiv double %63, 1.000000e+06
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), double %64)
br label %66
66: ; preds = %41, %14
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [50 x i8] c"Give me a number of FLOPs (100000000 for example)\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [56 x i8] c"The program took %f seconds to execute %d square roots\0A\00"
@.str.2 = [64 x i8] c"MFLOPS (millions of floating point operations per second) = %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %88
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = shl i32 %9, 2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to float*
%13 = icmp sgt i32 %9, 0
br i1 %13, label %14, label %73
14: ; preds = %6
%15 = zext i32 %9 to i64
%16 = icmp ult i32 %9, 8
br i1 %16, label %64, label %17
17: ; preds = %14
%18 = and i64 %15, 4294967288
%19 = add nsw i64 %18, -8
%20 = lshr exact i64 %19, 3
%21 = add nuw nsw i64 %20, 1
%22 = and i64 %21, 1
%23 = icmp eq i64 %19, 0
br i1 %23, label %50, label %24
24: ; preds = %17
%25 = and i64 %21, 4611686018427387902
br label %26
26: ; preds = %26, %24
%27 = phi i64 [ 0, %24 ], [ %46, %26 ]
%28 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %24 ], [ %47, %26 ]
%29 = phi i64 [ 0, %24 ], [ %48, %26 ]
%30 = add <4 x i32> %28, <i32 4, i32 4, i32 4, i32 4>
%31 = sitofp <4 x i32> %28 to <4 x float>
%32 = sitofp <4 x i32> %30 to <4 x float>
%33 = getelementptr inbounds float, float* %12, i64 %27
%34 = bitcast float* %33 to <4 x float>*
store <4 x float> %31, <4 x float>* %34
%35 = getelementptr inbounds float, float* %33, i64 4
%36 = bitcast float* %35 to <4 x float>*
store <4 x float> %32, <4 x float>* %36
%37 = or i64 %27, 8
%38 = add <4 x i32> %28, <i32 8, i32 8, i32 8, i32 8>
%39 = add <4 x i32> %28, <i32 12, i32 12, i32 12, i32 12>
%40 = sitofp <4 x i32> %38 to <4 x float>
%41 = sitofp <4 x i32> %39 to <4 x float>
%42 = getelementptr inbounds float, float* %12, i64 %37
%43 = bitcast float* %42 to <4 x float>*
store <4 x float> %40, <4 x float>* %43
%44 = getelementptr inbounds float, float* %42, i64 4
%45 = bitcast float* %44 to <4 x float>*
store <4 x float> %41, <4 x float>* %45
%46 = add nuw i64 %27, 16
%47 = add <4 x i32> %28, <i32 16, i32 16, i32 16, i32 16>
%48 = add i64 %29, 2
%49 = icmp eq i64 %48, %25
br i1 %49, label %50, label %26
50: ; preds = %26, %17
%51 = phi i64 [ 0, %17 ], [ %46, %26 ]
%52 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %17 ], [ %47, %26 ]
%53 = icmp eq i64 %22, 0
br i1 %53, label %62, label %54
54: ; preds = %50
%55 = add <4 x i32> %52, <i32 4, i32 4, i32 4, i32 4>
%56 = sitofp <4 x i32> %52 to <4 x float>
%57 = sitofp <4 x i32> %55 to <4 x float>
%58 = getelementptr inbounds float, float* %12, i64 %51
%59 = bitcast float* %58 to <4 x float>*
store <4 x float> %56, <4 x float>* %59
%60 = getelementptr inbounds float, float* %58, i64 4
%61 = bitcast float* %60 to <4 x float>*
store <4 x float> %57, <4 x float>* %61
br label %62
62: ; preds = %50, %54
%63 = icmp eq i64 %18, %15
br i1 %63, label %73, label %64
64: ; preds = %14, %62
%65 = phi i64 [ 0, %14 ], [ %18, %62 ]
br label %66
66: ; preds = %64, %66
%67 = phi i64 [ %71, %66 ], [ %65, %64 ]
%68 = trunc i64 %67 to i32
%69 = sitofp i32 %68 to float
%70 = getelementptr inbounds float, float* %12, i64 %67
store float %69, float* %70
%71 = add nuw nsw i64 %67, 1
%72 = icmp eq i64 %71, %15
br i1 %72, label %73, label %66
73: ; preds = %66, %62, %6
%74 = tail call i64 (...) @clock()
%75 = tail call float* @compute_sqrts(float* %12, i32 %9)
%76 = tail call i64 (...) @clock()
%77 = sub nsw i64 %76, %74
%78 = tail call i32 @free(float* %12)
%79 = tail call i32 @free(float* %75)
%80 = sitofp i64 %77 to double
%81 = load double, double* @CLOCKS_PER_SEC
%82 = fdiv double %80, %81
%83 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), double %82, i32 %9)
%84 = sitofp i32 %9 to double
%85 = fdiv double %84, %82
%86 = fdiv double %85, 1.000000e+06
%87 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), double %86)
br label %88
88: ; preds = %73, %4
ret i32 0
}