#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 M_PI;
double RAND_MAX;
scalar_t__ calloc(int, int);
double cos(double);
int gpu2norm_d(int, double *, double *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ scanf(char *, int *);
double sin(double);
int main(int argc, char *argv[]) {
  int dim, i;
  double *v;
  double result;
  printf("Give the dimension : ");
  scanf("%d", &dim);
  v = (double *)calloc(2 * dim, sizeof(double));
  printf("The components of a random vector :\n");
  for (i = 0; i < dim; i++) {
    double r = ((double)rand()) / RAND_MAX;
    double angle = 2.0 * M_PI * r;
    v[2 * i] = cos(angle);
    v[2 * i + 1] = sin(angle);
    printf("%22.15le  %22.15le\n", v[2 * i], v[2 * i + 1]);
  }
  int rtn = gpu2norm_d(dim, v, &result);
  printf("The result returned by the call : %.15le\n", result);
  return 0;
}


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)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe83(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1290 <main+0x120>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2df4(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe03(%rip),%xmm0
mov    0x2de4(%rip),%rax
mulsd  (%rax),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1070 <cos@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
call   1050 <sin@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xdcb(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cd <main+0x5d>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1080 <gpu2norm_d@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xdab(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe73(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
add    %edi,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    1264 <main+0xe4>
mov    0x2e01(%rip),%r15
mov    0x2e02(%rip),%r12
lea    0xe2c(%rip),%r13
mov    %r14,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%r15),%xmm1
movsd  (%r12),%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1080 <cos@plt>
movsd  %xmm0,(%rbx)
movsd  0x8(%rsp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movsd  %xmm0,0x8(%rbx)
movsd  (%rbx),%xmm0
mov    %r13,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rdi
add    $0x10,%rbx
cmp    %rdi,%rbp
jl     1200 <main+0x80>
lea    0x10(%rsp),%rdx
mov    %r14,%rsi
call   1090 <gpu2norm_d@plt>
movsd  0x10(%rsp),%xmm0
lea    0xdaf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Give the dimension : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [37 x i8] c"The components of a random vector :\0A\00"
@RAND_MAX = global double 0.000000e+00
@M_PI = global double 0.000000e+00
@.str.3 = [20 x i8] c"%22.15le %22.15le\0A\00"
@.str.4 = [42 x i8] c"The result returned by the call : %.15le\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 double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%15 = load i32, i32* %6
%16 = mul nsw i32 2, %15
%17 = call i64 @calloc(i32 %16, i32 8)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %20
20: ; preds = %62, %2
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %65
24: ; preds = %20
%25 = call i64 (...) @rand()
%26 = sitofp i64 %25 to double
%27 = load double, double* @RAND_MAX
%28 = fdiv double %26, %27
store double %28, double* %10
%29 = load double, double* @M_PI
%30 = fmul double 2.000000e+00, %29
%31 = load double, double* %10
%32 = fmul double %30, %31
store double %32, double* %11
%33 = load double, double* %11
%34 = call double @cos(double %33)
%35 = load double*, double** %8
%36 = load i32, i32* %7
%37 = mul nsw i32 2, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %35, i64 %38
store double %34, double* %39
%40 = load double, double* %11
%41 = call double @sin(double %40)
%42 = load double*, double** %8
%43 = load i32, i32* %7
%44 = mul nsw i32 2, %43
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %42, i64 %46
store double %41, double* %47
%48 = load double*, double** %8
%49 = load i32, i32* %7
%50 = mul nsw i32 2, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %48, i64 %51
%53 = load double, double* %52
%54 = load double*, double** %8
%55 = load i32, i32* %7
%56 = mul nsw i32 2, %55
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %54, i64 %58
%60 = load double, double* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double %53, double %60)
br label %62
62: ; preds = %24
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
br label %20
65: ; preds = %20
%66 = load i32, i32* %6
%67 = load double*, double** %8
%68 = call i32 @gpu2norm_d(i32 %66, double* %67, double* %9)
store i32 %68, i32* %12
%69 = load double, double* %9
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), double %69)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Give the dimension : \00"
@.str.1 = [3 x i8] c"%d\00"
@RAND_MAX = global double 0.000000e+00
@M_PI = global double 0.000000e+00
@.str.3 = [20 x i8] c"%22.15le %22.15le\0A\00"
@.str.4 = [42 x i8] c"The result returned by the call : %.15le\0A\00"
@str = [36 x i8] c"The components of a random vector :\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca double
%5 = bitcast i32* %3 to i8*
%6 = bitcast double* %4 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = shl nsw i32 %9, 1
%11 = call i64 @calloc(i32 %10, i32 8)
%12 = inttoptr i64 %11 to double*
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %37
16: ; preds = %2, %16
%17 = phi i64 [ %33, %16 ], [ 0, %2 ]
%18 = call i64 (...) @rand()
%19 = sitofp i64 %18 to double
%20 = load double, double* @RAND_MAX
%21 = fdiv double %19, %20
%22 = load double, double* @M_PI
%23 = fmul double %22, 2.000000e+00
%24 = fmul double %21, %23
%25 = call double @cos(double %24)
%26 = shl nuw nsw i64 %17, 1
%27 = getelementptr inbounds double, double* %12, i64 %26
store double %25, double* %27
%28 = call double @sin(double %24)
%29 = or i64 %26, 1
%30 = getelementptr inbounds double, double* %12, i64 %29
store double %28, double* %30
%31 = load double, double* %27
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double %31, double %28)
%33 = add nuw nsw i64 %17, 1
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %16, label %37
37: ; preds = %16, %2
%38 = phi i32 [ %14, %2 ], [ %34, %16 ]
%39 = call i32 @gpu2norm_d(i32 %38, double* %12, double* %4)
%40 = load double, double* %4
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), double %40)
ret i32 0
}