#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 */
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ gamma_index(int, int *, double *, double *, double *, int,
                               int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, double);
int main() {
  double mat1[] = {1, 2, 6, 4};
  double mat2[] = {1, 6, 4.2, 7.5};
  double *mat3 = (double *)malloc(sizeof(double) * 4);
  int shape[] = {2, 2};
  gamma_index(2, shape, mat1, mat2, mat3, 2, 2);
  for (int i = 0; i < 4; i++) {
    printf("%f\n", mat3[i]);
  }
  free(mat3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea1(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe98(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    -0x60(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x50(%rbp),%rcx
mov    -0x58(%rbp),%r8
mov    $0x2,%r9d
mov    %r9d,%edi
movl   $0x2,(%rsp)
call   1060 <gamma_index@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x4,-0x64(%rbp)
jge    121d <main+0xdd>
mov    -0x58(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11ec <main+0xac>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeae(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movabs $0x200000002,%rax
mov    %rax,0x8(%rsp)
movl   $0x2,(%rsp)
lea    0x8(%rsp),%rsi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0x2,%edi
mov    %rbx,%r8
mov    $0x2,%r9d
call   1060 <gamma_index@plt>
movsd  (%rbx),%xmm0
lea    0xe79(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0x8(%rbx),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0x10(%rbx),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
movsd  0x18(%rbx),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.mat1 = [4 x double] [double 1.000000e+00, double 2.000000e+00, double 6.000000e+00, double 4.000000e+00]
@__const.main.mat2 = [4 x double] [double 1.000000e+00, double 6.000000e+00, double 4.200000e+00, double 7.500000e+00]
@__const.main.shape = [2 x i32] [i32 2, i32 2]
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x double]
%3 = alloca [4 x double]
%4 = alloca double*
%5 = alloca [2 x i32]
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [4 x double]* %2 to i8*
%8 = bitcast [4 x double]* %3 to i8*
%9 = call i64 @malloc(i32 32)
%10 = inttoptr i64 %9 to double*
store double* %10, double** %4
%11 = bitcast [2 x i32]* %5 to i8*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%13 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%14 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%15 = load double*, double** %4
%16 = call i32 @gamma_index(i32 2, i32* %12, double* %13, double* %14, double* %15, i32 2, i32 2)
store i32 0, i32* %6
br label %17
17: ; preds = %27, %0
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load double*, double** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %17
30: ; preds = %17
%31 = load double*, double** %4
%32 = call i32 @free(double* %31)
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@__const.main.mat1 = [4 x double] [double 1.000000e+00, double 2.000000e+00, double 6.000000e+00, double 4.000000e+00]
@__const.main.mat2 = [4 x double] [double 1.000000e+00, double 6.000000e+00, double 4.200000e+00, double 7.500000e+00]
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca [4 x double]
%2 = alloca [4 x double]
%3 = alloca i64
%4 = bitcast [4 x double]* %1 to i8*
%5 = bitcast [4 x double]* %2 to i8*
%6 = tail call i64 @malloc(i32 32)
%7 = inttoptr i64 %6 to double*
%8 = bitcast i64* %3 to i8*
store i64 8589934594, i64* %3
%9 = bitcast i64* %3 to i32*
%10 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%11 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%12 = call i32 @gamma_index(i32 2, i32* %9, double* %10, double* %11, double* %7, i32 2, i32 2)
%13 = load double, double* %7
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %13)
%15 = getelementptr inbounds double, double* %7, i64 1
%16 = load double, double* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %16)
%18 = getelementptr inbounds double, double* %7, i64 2
%19 = load double, double* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %19)
%21 = getelementptr inbounds double, double* %7, i64 3
%22 = load double, double* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %22)
%24 = call i32 @free(double* %7)
ret i32 0
}