#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 *getValues(int *, int *);
int /*<<< orphan*/ printf(char *, int, ...);
double sumitems(double *, int, int);
void main() {
  double B[] = {1, 3, 4, 9, 2, 8, 3, 2};
  int rowB = 2, colB = 4;
  printf("sumitems: %6.2f\n", sumitems(B, rowB, colB));
  int numberRow, numberCol, i;
  double *matrix = getValues(&numberRow, &numberCol);
  printf("Matrix of size [%d,%d]", numberRow, numberCol);
  for (i = 0; i < numberRow * numberCol; i++) {
    printf("A[%d] = %5.2f\n", i, matrix[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x40(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
movl   $0x2,-0x44(%rbp)
movl   $0x4,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x48(%rbp),%edx
call   1060 <sumitems@plt>
cvttsd2si %xmm0,%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x4c(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <getValues@plt>
mov    %rax,-0x60(%rbp)
mov    -0x4c(%rbp),%esi
mov    -0x50(%rbp),%edx
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x4c(%rbp),%ecx
imul   -0x50(%rbp),%ecx
cmp    %ecx,%eax
jge    11f6 <main+0xb6>
mov    -0x54(%rbp),%esi
mov    -0x60(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe87(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11b8 <main+0x78>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
movaps 0xef0(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movapd 0xe9b(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    $0x4,%edx
call   1050 <sumitems@plt>
cvttsd2si %xmm0,%esi
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <getValues@plt>
mov    %rax,%r14
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%eax
imul   0xc(%rsp),%eax
test   %eax,%eax
jle    11f9 <main+0xc9>
xor    %ebx,%ebx
lea    0xe99(%rip),%r15
nop
movsd  (%r14,%rbx,8),%xmm0
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
movslq 0x8(%rsp),%rcx
imul   %rax,%rcx
cmp    %rcx,%rbx
jl     11d0 <main+0xa0>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.B = [8 x double] [double 1.000000e+00, double 3.000000e+00, double 4.000000e+00, double 9.000000e+00, double 2.000000e+00, double 8.000000e+00, double 3.000000e+00, double 2.000000e+00]
@.str = [17 x i8] c"sumitems: %6.2f\0A\00"
@.str.1 = [23 x i8] c"Matrix of size [%d,%d]\00"
@.str.2 = [15 x i8] c"A[%d] = %5.2f\0A\00"
define void @main() {
%1 = alloca [8 x double]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = bitcast [8 x double]* %1 to i8*
store i32 2, i32* %2
store i32 4, i32* %3
%9 = getelementptr inbounds [8 x double], [8 x double]* %1, i64 0, i64 0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call double @sumitems(double* %9, i32 %10, i32 %11)
%13 = fptosi double %12 to i32
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call double* @getValues(i32* %4, i32* %5)
store double* %15, double** %7
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
store i32 0, i32* %6
br label %19
19: ; preds = %33, %0
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = mul nsw i32 %21, %22
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %36
25: ; preds = %19
%26 = load i32, i32* %6
%27 = load double*, double** %7
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %26, double %31)
br label %33
33: ; preds = %25
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %19
36: ; preds = %19
ret void
}

LLVM IR (-O2):
@__const.main.B = [8 x double] [double 1.000000e+00, double 3.000000e+00, double 4.000000e+00, double 9.000000e+00, double 2.000000e+00, double 8.000000e+00, double 3.000000e+00, double 2.000000e+00]
@.str = [17 x i8] c"sumitems: %6.2f\0A\00"
@.str.1 = [23 x i8] c"Matrix of size [%d,%d]\00"
@.str.2 = [15 x i8] c"A[%d] = %5.2f\0A\00"
define void @main() {
%1 = alloca [8 x double]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [8 x double]* %1 to i8*
%5 = getelementptr inbounds [8 x double], [8 x double]* %1, i64 0, i64 0
%6 = call double @sumitems(double* %5, i32 2, i32 4)
%7 = fptosi double %6 to i32
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = call double* @getValues(i32* %2, i32* %3)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = mul nsw i32 %16, %15
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %0, %19
%20 = phi i64 [ %25, %19 ], [ 0, %0 ]
%21 = getelementptr inbounds double, double* %11, i64 %20
%22 = load double, double* %21
%23 = trunc i64 %20 to i32
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %23, double %22)
%25 = add nuw nsw i64 %20, 1
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = mul nsw i32 %27, %26
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %25, %29
br i1 %30, label %19, label %31
31: ; preds = %19, %0
ret void
}