#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 */
scalar_t__ malloc(int);
double *create_constant_field(int size, int dim, double val) {
  double *res = (double *)malloc(sizeof(double) * size * dim);
  for (int i = 0; i < size * dim; i++) {
    res[i] = val;
  }
  return res;
}


x86 assembly (clang, -O0):
<create_constant_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
imul   -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    1177 <create_constant_field+0x67>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <create_constant_field+0x35>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_constant_field>:
push   %rbx
sub    $0x10,%rsp
movaps %xmm0,(%rsp)
mov    %edi,%ebx
imul   %esi,%ebx
lea    0x0(,%rbx,8),%edi
call   1030 <malloc@plt>
movaps (%rsp),%xmm1
test   %ebx,%ebx
jle    123e <create_constant_field+0x12e>
mov    %ebx,%ecx
cmp    $0x4,%ebx
jae    1144 <create_constant_field+0x34>
xor    %edx,%edx
jmp    1230 <create_constant_field+0x120>
mov    %ecx,%edx
and    $0xfffffffc,%edx
movaps %xmm1,%xmm0
movlhps %xmm1,%xmm0
lea    -0x4(%rdx),%rbx
mov    %rbx,%rdi
shr    $0x2,%rdi
add    $0x1,%rdi
mov    %edi,%esi
and    $0x7,%esi
cmp    $0x1c,%rbx
jae    1170 <create_constant_field+0x60>
xor    %ebx,%ebx
jmp    11f1 <create_constant_field+0xe1>
and    $0xfffffffffffffff8,%rdi
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movups %xmm0,(%rax,%rbx,8)
movups %xmm0,0x10(%rax,%rbx,8)
movups %xmm0,0x20(%rax,%rbx,8)
movups %xmm0,0x30(%rax,%rbx,8)
movups %xmm0,0x40(%rax,%rbx,8)
movups %xmm0,0x50(%rax,%rbx,8)
movups %xmm0,0x60(%rax,%rbx,8)
movups %xmm0,0x70(%rax,%rbx,8)
movups %xmm0,0x80(%rax,%rbx,8)
movups %xmm0,0x90(%rax,%rbx,8)
movups %xmm0,0xa0(%rax,%rbx,8)
movups %xmm0,0xb0(%rax,%rbx,8)
movups %xmm0,0xc0(%rax,%rbx,8)
movups %xmm0,0xd0(%rax,%rbx,8)
movups %xmm0,0xe0(%rax,%rbx,8)
movups %xmm0,0xf0(%rax,%rbx,8)
add    $0x20,%rbx
add    $0xfffffffffffffff8,%rdi
jne    1180 <create_constant_field+0x70>
test   %rsi,%rsi
je     1222 <create_constant_field+0x112>
lea    (%rax,%rbx,8),%rdi
add    $0x10,%rdi
shl    $0x5,%rsi
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movups %xmm0,-0x10(%rdi,%rbx,1)
movups %xmm0,(%rdi,%rbx,1)
add    $0x20,%rbx
cmp    %rbx,%rsi
jne    1210 <create_constant_field+0x100>
cmp    %rcx,%rdx
je     123e <create_constant_field+0x12e>
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,(%rax,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1230 <create_constant_field+0x120>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double* @create_constant_field(i32 %0, i32 %1, double %2) {
%4 = shl i32 %0, 3
%5 = mul i32 %4, %1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = mul i32 %1, %0
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %88
10: ; preds = %3
%11 = zext i32 %8 to i64
%12 = icmp ult i32 %8, 4
br i1 %12, label %86, label %13
13: ; preds = %10
%14 = and i64 %11, 4294967292
%15 = insertelement <2 x double> poison, double %2, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = insertelement <2 x double> poison, double %2, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = add nsw i64 %14, -4
%20 = lshr exact i64 %19, 2
%21 = add nuw nsw i64 %20, 1
%22 = and i64 %21, 7
%23 = icmp ult i64 %19, 28
br i1 %23, label %71, label %24
24: ; preds = %13
%25 = and i64 %21, 9223372036854775800
br label %26
26: ; preds = %26, %24
%27 = phi i64 [ 0, %24 ], [ %68, %26 ]
%28 = phi i64 [ 0, %24 ], [ %69, %26 ]
%29 = getelementptr inbounds double, double* %7, i64 %27
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> %16, <2 x double>* %30
%31 = getelementptr inbounds double, double* %29, i64 2
%32 = bitcast double* %31 to <2 x double>*
store <2 x double> %18, <2 x double>* %32
%33 = or i64 %27, 4
%34 = getelementptr inbounds double, double* %7, i64 %33
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> %16, <2 x double>* %35
%36 = getelementptr inbounds double, double* %34, i64 2
%37 = bitcast double* %36 to <2 x double>*
store <2 x double> %18, <2 x double>* %37
%38 = or i64 %27, 8
%39 = getelementptr inbounds double, double* %7, i64 %38
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> %16, <2 x double>* %40
%41 = getelementptr inbounds double, double* %39, i64 2
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> %18, <2 x double>* %42
%43 = or i64 %27, 12
%44 = getelementptr inbounds double, double* %7, i64 %43
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> %16, <2 x double>* %45
%46 = getelementptr inbounds double, double* %44, i64 2
%47 = bitcast double* %46 to <2 x double>*
store <2 x double> %18, <2 x double>* %47
%48 = or i64 %27, 16
%49 = getelementptr inbounds double, double* %7, i64 %48
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %16, <2 x double>* %50
%51 = getelementptr inbounds double, double* %49, i64 2
%52 = bitcast double* %51 to <2 x double>*
store <2 x double> %18, <2 x double>* %52
%53 = or i64 %27, 20
%54 = getelementptr inbounds double, double* %7, i64 %53
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %16, <2 x double>* %55
%56 = getelementptr inbounds double, double* %54, i64 2
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %18, <2 x double>* %57
%58 = or i64 %27, 24
%59 = getelementptr inbounds double, double* %7, i64 %58
%60 = bitcast double* %59 to <2 x double>*
store <2 x double> %16, <2 x double>* %60
%61 = getelementptr inbounds double, double* %59, i64 2
%62 = bitcast double* %61 to <2 x double>*
store <2 x double> %18, <2 x double>* %62
%63 = or i64 %27, 28
%64 = getelementptr inbounds double, double* %7, i64 %63
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %16, <2 x double>* %65
%66 = getelementptr inbounds double, double* %64, i64 2
%67 = bitcast double* %66 to <2 x double>*
store <2 x double> %18, <2 x double>* %67
%68 = add nuw i64 %27, 32
%69 = add i64 %28, 8
%70 = icmp eq i64 %69, %25
br i1 %70, label %71, label %26
71: ; preds = %26, %13
%72 = phi i64 [ 0, %13 ], [ %68, %26 ]
%73 = icmp eq i64 %22, 0
br i1 %73, label %84, label %74
74: ; preds = %71, %74
%75 = phi i64 [ %81, %74 ], [ %72, %71 ]
%76 = phi i64 [ %82, %74 ], [ 0, %71 ]
%77 = getelementptr inbounds double, double* %7, i64 %75
%78 = bitcast double* %77 to <2 x double>*
store <2 x double> %16, <2 x double>* %78
%79 = getelementptr inbounds double, double* %77, i64 2
%80 = bitcast double* %79 to <2 x double>*
store <2 x double> %18, <2 x double>* %80
%81 = add nuw i64 %75, 4
%82 = add i64 %76, 1
%83 = icmp eq i64 %82, %22
br i1 %83, label %84, label %74
84: ; preds = %74, %71
%85 = icmp eq i64 %14, %11
br i1 %85, label %88, label %86
86: ; preds = %10, %84
%87 = phi i64 [ 0, %10 ], [ %14, %84 ]
br label %89
88: ; preds = %89, %84, %3
ret double* %7
89: ; preds = %86, %89
%90 = phi i64 [ %92, %89 ], [ %87, %86 ]
%91 = getelementptr inbounds double, double* %7, i64 %90
store double %2, double* %91
%92 = add nuw nsw i64 %90, 1
%93 = icmp eq i64 %92, %11
br i1 %93, label %88, label %89
}