#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 cos(double);
double *malloc(int);
double *funcio_trigonometrica(int n, double *x) {
  int i = 0;
  double *f = malloc(sizeof(double) * n);
  for (i = 0; i < n; i++) {
    f[i] = cos(x[i]);
  }
  return f;
}


x86 assembly (clang, -O0):
<funcio_trigonometrica>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1189 <funcio_trigonometrica+0x69>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <cos@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <funcio_trigonometrica+0x30>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<funcio_trigonometrica>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    11fb <funcio_trigonometrica+0xdb>
mov    %r15d,%r12d
lea    -0x1(%r12),%rax
mov    %r12d,%r15d
and    $0x3,%r15d
cmp    $0x3,%rax
jae    1161 <funcio_trigonometrica+0x41>
xor    %ebx,%ebx
jmp    11c4 <funcio_trigonometrica+0xa4>
and    $0xfffffffc,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  0x0(%r13,%rbx,8),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,(%r14,%rbx,8)
movsd  0x8(%r13,%rbx,8),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x8(%r14,%rbx,8)
movsd  0x10(%r13,%rbx,8),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x10(%r14,%rbx,8)
movsd  0x18(%r13,%rbx,8),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x18(%r14,%rbx,8)
add    $0x4,%rbx
cmp    %rbx,%r12
jne    1170 <funcio_trigonometrica+0x50>
test   %r15,%r15
je     11fb <funcio_trigonometrica+0xdb>
lea    (%r14,%rbx,8),%r12
lea    0x0(%r13,%rbx,8),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x0(%r13,%rbx,8),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11e0 <funcio_trigonometrica+0xc0>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @funcio_trigonometrica(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
%6 = alloca double*
store i32 %0, i32* %3
store double* %1, double** %4
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call double* @malloc(i32 %10)
store double* %11, double** %6
store i32 0, i32* %5
br label %12
12: ; preds = %27, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load double*, double** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = call double @cos(double %21)
%23 = load double*, double** %6
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
store double %22, double* %26
br label %27
27: ; preds = %16
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %12
30: ; preds = %12
%31 = load double*, double** %6
ret double* %31
}

LLVM IR (-O2):
define noalias double* @funcio_trigonometrica(i32 %0, double* nocapture %1) {
%3 = shl i32 %0, 3
%4 = tail call double* @malloc(i32 %3)
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %51
6: ; preds = %2
%7 = zext i32 %0 to i64
%8 = add nsw i64 %7, -1
%9 = and i64 %7, 3
%10 = icmp ult i64 %8, 3
br i1 %10, label %38, label %11
11: ; preds = %6
%12 = and i64 %7, 4294967292
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ 0, %11 ], [ %35, %13 ]
%15 = phi i64 [ 0, %11 ], [ %36, %13 ]
%16 = getelementptr inbounds double, double* %1, i64 %14
%17 = load double, double* %16
%18 = tail call double @cos(double %17)
%19 = getelementptr inbounds double, double* %4, i64 %14
store double %18, double* %19
%20 = or i64 %14, 1
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
%23 = tail call double @cos(double %22)
%24 = getelementptr inbounds double, double* %4, i64 %20
store double %23, double* %24
%25 = or i64 %14, 2
%26 = getelementptr inbounds double, double* %1, i64 %25
%27 = load double, double* %26
%28 = tail call double @cos(double %27)
%29 = getelementptr inbounds double, double* %4, i64 %25
store double %28, double* %29
%30 = or i64 %14, 3
%31 = getelementptr inbounds double, double* %1, i64 %30
%32 = load double, double* %31
%33 = tail call double @cos(double %32)
%34 = getelementptr inbounds double, double* %4, i64 %30
store double %33, double* %34
%35 = add nuw nsw i64 %14, 4
%36 = add i64 %15, 4
%37 = icmp eq i64 %36, %12
br i1 %37, label %38, label %13
38: ; preds = %13, %6
%39 = phi i64 [ 0, %6 ], [ %35, %13 ]
%40 = icmp eq i64 %9, 0
br i1 %40, label %51, label %41
41: ; preds = %38, %41
%42 = phi i64 [ %48, %41 ], [ %39, %38 ]
%43 = phi i64 [ %49, %41 ], [ 0, %38 ]
%44 = getelementptr inbounds double, double* %1, i64 %42
%45 = load double, double* %44
%46 = tail call double @cos(double %45)
%47 = getelementptr inbounds double, double* %4, i64 %42
store double %46, double* %47
%48 = add nuw nsw i64 %42, 1
%49 = add i64 %43, 1
%50 = icmp eq i64 %49, %9
br i1 %50, label %51, label %41
51: ; preds = %38, %41, %2
ret double* %4
}