#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*/ cm_cleanup();
int /*<<< orphan*/ cm_get_root(double *);
int /*<<< orphan*/ cm_set_matrix(double *, int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  double matrix[] = {5, 10, 30, 8, 10, 30, 100, 20, 30, 100, 354, 70};
  double *root = NULL;
  int i;
  cm_set_matrix(matrix, 3);
  root = (double *)malloc(3 * sizeof(double));
  if (root == NULL) {
    cm_cleanup();
    return -1;
  }
  cm_get_root(root);
  printf("\nroot:\n");
  for (i = 0; i < 3; i++) {
    printf("%f\t", root[i]);
  }
  printf("\n");
  cm_cleanup();
  if (root) {
    free(root);
    root = NULL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x60,%edx
call   1060 <memcpy@plt>
movq   $0x0,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x3,%esi
call   1040 <cm_set_matrix@plt>
mov    $0x18,%edi
call   1080 <malloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11d9 <main+0x69>
mov    $0x0,%al
call   1070 <cm_cleanup@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <main+0xf2>
mov    -0x78(%rbp),%rdi
call   1090 <cm_get_root@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x7c(%rbp)
cmpl   $0x3,-0x7c(%rbp)
jge    122a <main+0xba>
mov    -0x78(%rbp),%rax
movslq -0x7c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe53(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    11f7 <main+0x87>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <cm_cleanup@plt>
cmpq   $0x0,-0x78(%rbp)
je     125b <main+0xeb>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x78(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe6f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe53(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe37(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x3,%esi
call   1040 <cm_set_matrix@plt>
mov    $0x18,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1250 <main+0xd0>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <cm_get_root@plt>
lea    0xe69(%rip),%rdi
call   1060 <puts@plt>
movsd  (%rbx),%xmm0
lea    0xe55(%rip),%rbp
mov    %rbp,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  0x8(%rbx),%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  0x10(%rbx),%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <cm_cleanup@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    125c <main+0xdc>
xor    %eax,%eax
call   1080 <cm_cleanup@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.matrix = [12 x double] [double 5.000000e+00, double 1.000000e+01, double 3.000000e+01, double 8.000000e+00, double 1.000000e+01, double 3.000000e+01, double 1.000000e+02, double 2.000000e+01, double 3.000000e+01, double 1.000000e+02, double 3.540000e+02, double 7.000000e+01]
@.str = [8 x i8] c"\0Aroot:\0A\00"
@.str.1 = [4 x i8] c"%f\09\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x double]
%3 = alloca double*
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [12 x double]* %2 to i8*
store double* null, double** %3
%6 = getelementptr inbounds [12 x double], [12 x double]* %2, i64 0, i64 0
%7 = call i32 @cm_set_matrix(double* %6, i32 3)
%8 = call i64 @malloc(i32 24)
%9 = inttoptr i64 %8 to double*
store double* %9, double** %3
%10 = load double*, double** %3
%11 = icmp eq double* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (...) @cm_cleanup()
store i32 -1, i32* %1
br label %40
14: ; preds = %0
%15 = load double*, double** %3
%16 = call i32 @cm_get_root(double* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %18
18: ; preds = %28, %14
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load double*, double** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %26)
br label %28
28: ; preds = %21
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %18
31: ; preds = %18
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 (...) @cm_cleanup()
%34 = load double*, double** %3
%35 = icmp ne double* %34, null
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load double*, double** %3
%38 = call i32 @free(double* %37)
store double* null, double** %3
br label %39
39: ; preds = %36, %31
store i32 0, i32* %1
br label %40
40: ; preds = %39, %12
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@__const.main.matrix = [12 x double] [double 5.000000e+00, double 1.000000e+01, double 3.000000e+01, double 8.000000e+00, double 1.000000e+01, double 3.000000e+01, double 1.000000e+02, double 2.000000e+01, double 3.000000e+01, double 1.000000e+02, double 3.540000e+02, double 7.000000e+01]
@.str.1 = [4 x i8] c"%f\09\00"
@str = [7 x i8] c"\0Aroot:\00"
define i32 @main() {
%1 = alloca [12 x double]
%2 = bitcast [12 x double]* %1 to i8*
%3 = getelementptr inbounds [12 x double], [12 x double]* %1, i64 0, i64 0
%4 = call i32 @cm_set_matrix(double* %3, i32 3)
%5 = call i64 @malloc(i32 24)
%6 = inttoptr i64 %5 to double*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (...) @cm_cleanup()
br label %24
10: ; preds = %0
%11 = call i32 @cm_get_root(double* %6)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%13 = load double, double* %6
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %13)
%15 = getelementptr inbounds double, double* %6, i64 1
%16 = load double, double* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %16)
%18 = getelementptr inbounds double, double* %6, i64 2
%19 = load double, double* %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %19)
%21 = call i32 @putchar(i32 10)
%22 = call i32 (...) @cm_cleanup()
%23 = call i32 @free(double* %6)
br label %24
24: ; preds = %10, %8
%25 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %25
}