#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 asum(double *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ getdiag(double *, double *, int);
double trace(double *a, int n) {
  double *diags, t;
  if ((diags = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  getdiag(diags, a, n);
  t = asum(diags, n);
  free(diags);
  return t;
}


x86 assembly (clang, -O0):
<trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1189 <trace+0x39>
mov    -0xc(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <getdiag@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <asum@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117f <trace+0x2f>
lea    0xe88(%rip),%rdi
mov    %ebp,%esi
call   1050 <fatalx@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <getdiag@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <asum@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @trace(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double*
%6 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i64 @calloc(i32 %7, i32 8)
%9 = inttoptr i64 %8 to double*
store double* %9, double** %5
%10 = icmp eq double* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* %4
%13 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11, %2
%15 = load double*, double** %5
%16 = load double*, double** %3
%17 = load i32, i32* %4
%18 = call i32 @getdiag(double* %15, double* %16, i32 %17)
%19 = load double*, double** %5
%20 = load i32, i32* %4
%21 = call double @asum(double* %19, i32 %20)
store double %21, double* %6
%22 = load double*, double** %5
%23 = call i32 @free(double* %22)
%24 = load double, double* %6
ret double %24
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @trace(double* %0, i32 %1) {
%3 = tail call i64 @calloc(i32 %1, i32 8)
%4 = inttoptr i64 %3 to double*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %8
8: ; preds = %6, %2
%9 = tail call i32 @getdiag(double* %4, double* %0, i32 %1)
%10 = tail call double @asum(double* %4, i32 %1)
%11 = tail call i32 @free(double* %4)
ret double %10
}