#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ *stderr;
void glb_channel_printf_total(FILE *stream, const double *energy,
                              const double **res, size_t l, size_t c) {
  int i, k;
  double *sum, tsum;
  sum = (double *)malloc(sizeof(double) * c);
  if (sum == NULL) {
    fprintf(stderr, "glb: FATAL: Memory allocation failed\n");
    exit(1);
  }
  for (k = 0; k < c; k++)
    sum[k] = 0.0;
  for (i = 0; i < l; i++)
    for (k = 0; k < c; k++)
      sum[k] += res[k][i];
  tsum = 0.0;
  for (k = 0; k < c; k++)
    tsum += sum[k];
  fprintf(stream, "%12.6g ||\t", tsum);
  for (k = 0; k < c; k++) {
    fprintf(stream, "%12.6g\t", sum[k]);
  }
  fprintf(stream, "\n");
  free(sum);
}


x86 assembly (clang, -O0):
<glb_channel_printf_total>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119c <glb_channel_printf_total+0x5c>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rdi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11cf <glb_channel_printf_total+0x8f>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a3 <glb_channel_printf_total+0x63>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1241 <glb_channel_printf_total+0x101>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    122e <glb_channel_printf_total+0xee>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11eb <glb_channel_printf_total+0xab>
jmp    1233 <glb_channel_printf_total+0xf3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d6 <glb_channel_printf_total+0x96>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1283 <glb_channel_printf_total+0x143>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1250 <glb_channel_printf_total+0x110>
mov    -0x8(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
lea    0xd93(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12dc <glb_channel_printf_total+0x19c>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd6a(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12a1 <glb_channel_printf_total+0x161>
mov    -0x8(%rbp),%rdi
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glb_channel_printf_total>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rdi,%r14
lea    0x0(,%r8,8),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     134a <glb_channel_printf_total+0x1da>
mov    %rax,%rbx
test   %r15,%r15
je     11b5 <glb_channel_printf_total+0x45>
lea    0x0(,%r15,8),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
test   %r12,%r12
je     123f <glb_channel_printf_total+0xcf>
mov    %r15,%rax
and    $0xfffffffffffffffe,%rax
xor    %ecx,%ecx
jmp    11d9 <glb_channel_printf_total+0x69>
nopl   0x0(%rax)
add    $0x1,%rcx
cmp    %r12,%rcx
je     123f <glb_channel_printf_total+0xcf>
test   %r15,%r15
je     11d0 <glb_channel_printf_total+0x60>
xor    %edx,%edx
cmp    $0x1,%r15
je     1223 <glb_channel_printf_total+0xb3>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rdx,8),%rsi
movsd  (%rsi,%rcx,8),%xmm0
addsd  (%rbx,%rdx,8),%xmm0
movsd  %xmm0,(%rbx,%rdx,8)
mov    0x8(%r13,%rdx,8),%rsi
movsd  (%rsi,%rcx,8),%xmm0
addsd  0x8(%rbx,%rdx,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rdx,8)
add    $0x2,%rdx
cmp    %rdx,%rax
jne    11f0 <glb_channel_printf_total+0x80>
test   $0x1,%r15b
je     11d0 <glb_channel_printf_total+0x60>
mov    0x0(%r13,%rdx,8),%rsi
movsd  (%rsi,%rcx,8),%xmm0
addsd  (%rbx,%rdx,8),%xmm0
movsd  %xmm0,(%rbx,%rdx,8)
jmp    11d0 <glb_channel_printf_total+0x60>
test   %r15,%r15
je     125c <glb_channel_printf_total+0xec>
lea    -0x1(%r15),%rcx
mov    %r15d,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
jae    1276 <glb_channel_printf_total+0x106>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    12c8 <glb_channel_printf_total+0x158>
lea    0xdc3(%rip),%rsi
xorpd  %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <fprintf@plt>
jmp    132c <glb_channel_printf_total+0x1bc>
mov    %r15,%rdx
and    $0xfffffffffffffff8,%rdx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rbx,%rcx,8),%xmm0
addsd  0x8(%rbx,%rcx,8),%xmm0
addsd  0x10(%rbx,%rcx,8),%xmm0
addsd  0x18(%rbx,%rcx,8),%xmm0
addsd  0x20(%rbx,%rcx,8),%xmm0
addsd  0x28(%rbx,%rcx,8),%xmm0
addsd  0x30(%rbx,%rcx,8),%xmm0
addsd  0x38(%rbx,%rcx,8),%xmm0
add    $0x8,%rcx
cmp    %rcx,%rdx
jne    1290 <glb_channel_printf_total+0x120>
test   %rax,%rax
je     12ee <glb_channel_printf_total+0x17e>
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rcx,%rdx,8),%xmm0
add    $0x1,%rdx
cmp    %rdx,%rax
jne    12e0 <glb_channel_printf_total+0x170>
lea    0xd31(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <fprintf@plt>
test   %r15,%r15
je     132c <glb_channel_printf_total+0x1bc>
xor    %r13d,%r13d
lea    0xd23(%rip),%r12
xchg   %ax,%ax
movsd  (%rbx,%r13,8),%xmm0
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    1310 <glb_channel_printf_total+0x1a0>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    0x2c8f(%rip),%rax
mov    (%rax),%rcx
lea    0xca5(%rip),%rdi
mov    $0x25,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [38 x i8] c"glb: FATAL: Memory allocation failed\0A\00"
@.str.1 = [11 x i8] c"%12.6g ||\09\00"
@.str.2 = [8 x i8] c"%12.6g\09\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @glb_channel_printf_total(i32* %0, double* %1, double** %2, i64 %3, i64 %4) {
%6 = alloca i32*
%7 = alloca double*
%8 = alloca double**
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
%14 = alloca double
store i32* %0, i32** %6
store double* %1, double** %7
store double** %2, double*** %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%15 = load i64, i64* %10
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %13
%20 = load double*, double** %13
%21 = icmp eq double* %20, null
br i1 %21, label %22, label %26
22: ; preds = %5
%23 = load i32*, i32** @stderr
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %5
store i32 0, i32* %12
br label %27
27: ; preds = %37, %26
%28 = load i32, i32* %12
%29 = sext i32 %28 to i64
%30 = load i64, i64* %10
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %40
32: ; preds = %27
%33 = load double*, double** %13
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
store double 0.000000e+00, double* %36
br label %37
37: ; preds = %32
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
br label %27
40: ; preds = %27
store i32 0, i32* %11
br label %41
41: ; preds = %72, %40
%42 = load i32, i32* %11
%43 = sext i32 %42 to i64
%44 = load i64, i64* %9
%45 = icmp ult i64 %43, %44
br i1 %45, label %46, label %75
46: ; preds = %41
store i32 0, i32* %12
br label %47
47: ; preds = %68, %46
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = load i64, i64* %10
%51 = icmp ult i64 %49, %50
br i1 %51, label %52, label %71
52: ; preds = %47
%53 = load double**, double*** %8
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double*, double** %53, i64 %55
%57 = load double*, double** %56
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
%61 = load double, double* %60
%62 = load double*, double** %13
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
%66 = load double, double* %65
%67 = fadd double %66, %61
store double %67, double* %65
br label %68
68: ; preds = %52
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 1
store i32 %70, i32* %12
br label %47
71: ; preds = %47
br label %72
72: ; preds = %71
%73 = load i32, i32* %11
%74 = add nsw i32 %73, 1
store i32 %74, i32* %11
br label %41
75: ; preds = %41
store double 0.000000e+00, double* %14
store i32 0, i32* %12
br label %76
76: ; preds = %89, %75
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = load i64, i64* %10
%80 = icmp ult i64 %78, %79
br i1 %80, label %81, label %92
81: ; preds = %76
%82 = load double*, double** %13
%83 = load i32, i32* %12
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
%86 = load double, double* %85
%87 = load double, double* %14
%88 = fadd double %87, %86
store double %88, double* %14
br label %89
89: ; preds = %81
%90 = load i32, i32* %12
%91 = add nsw i32 %90, 1
store i32 %91, i32* %12
br label %76
92: ; preds = %76
%93 = load i32*, i32** %6
%94 = load double, double* %14
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %94)
store i32 0, i32* %12
br label %96
96: ; preds = %109, %92
%97 = load i32, i32* %12
%98 = sext i32 %97 to i64
%99 = load i64, i64* %10
%100 = icmp ult i64 %98, %99
br i1 %100, label %101, label %112
101: ; preds = %96
%102 = load i32*, i32** %6
%103 = load double*, double** %13
%104 = load i32, i32* %12
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds double, double* %103, i64 %105
%107 = load double, double* %106
%108 = call i32 (i32*, i8*, ...) @fprintf(i32* %102, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %107)
br label %109
109: ; preds = %101
%110 = load i32, i32* %12
%111 = add nsw i32 %110, 1
store i32 %111, i32* %12
br label %96
112: ; preds = %96
%113 = load i32*, i32** %6
%114 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%115 = load double*, double** %13
%116 = call i32 @free(double* %115)
ret void
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [38 x i8] c"glb: FATAL: Memory allocation failed\0A\00"
@.str.1 = [11 x i8] c"%12.6g ||\09\00"
@.str.2 = [8 x i8] c"%12.6g\09\00"
define void @glb_channel_printf_total(i32* nocapture %0, double* nocapture readnone %1, double** nocapture %2, i64 %3, i64 %4) {
%6 = trunc i64 %4 to i32
%7 = shl i32 %6, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = inttoptr i64 %8 to i8*
%11 = icmp eq i64 %8, 0
br i1 %11, label %16, label %12
12: ; preds = %5
%13 = icmp eq i64 %4, 0
br i1 %13, label %20, label %14
14: ; preds = %12
%15 = shl nuw i64 %4, 3
br label %20
16: ; preds = %5
%17 = load i32*, i32** @stderr
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 37, i64 1, i32* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %14, %12
%21 = icmp eq i64 %3, 0
br i1 %21, label %30, label %22
22: ; preds = %20
%23 = and i64 %4, 1
%24 = icmp eq i64 %4, 1
%25 = and i64 %4, -2
%26 = icmp eq i64 %23, 0
br label %27
27: ; preds = %22, %70
%28 = phi i64 [ %71, %70 ], [ 0, %22 ]
br i1 %13, label %70, label %29
29: ; preds = %27
br i1 %24, label %60, label %39
30: ; preds = %70, %20
br i1 %13, label %37, label %31
31: ; preds = %30
%32 = add i64 %4, -1
%33 = and i64 %4, 7
%34 = icmp ult i64 %32, 7
br i1 %34, label %111, label %35
35: ; preds = %31
%36 = and i64 %4, -8
br label %73
37: ; preds = %30
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00)
br label %136
39: ; preds = %29, %39
%40 = phi i64 [ %57, %39 ], [ 0, %29 ]
%41 = phi i64 [ %58, %39 ], [ 0, %29 ]
%42 = getelementptr inbounds double*, double** %2, i64 %40
%43 = load double*, double** %42
%44 = getelementptr inbounds double, double* %43, i64 %28
%45 = load double, double* %44
%46 = getelementptr inbounds double, double* %9, i64 %40
%47 = load double, double* %46
%48 = fadd double %45, %47
store double %48, double* %46
%49 = or i64 %40, 1
%50 = getelementptr inbounds double*, double** %2, i64 %49
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i64 %28
%53 = load double, double* %52
%54 = getelementptr inbounds double, double* %9, i64 %49
%55 = load double, double* %54
%56 = fadd double %53, %55
store double %56, double* %54
%57 = add nuw nsw i64 %40, 2
%58 = add i64 %41, 2
%59 = icmp eq i64 %58, %25
br i1 %59, label %60, label %39
60: ; preds = %39, %29
%61 = phi i64 [ 0, %29 ], [ %57, %39 ]
br i1 %26, label %70, label %62
62: ; preds = %60
%63 = getelementptr inbounds double*, double** %2, i64 %61
%64 = load double*, double** %63
%65 = getelementptr inbounds double, double* %64, i64 %28
%66 = load double, double* %65
%67 = getelementptr inbounds double, double* %9, i64 %61
%68 = load double, double* %67
%69 = fadd double %66, %68
store double %69, double* %67
br label %70
70: ; preds = %62, %60, %27
%71 = add nuw nsw i64 %28, 1
%72 = icmp eq i64 %71, %3
br i1 %72, label %30, label %27
73: ; preds = %73, %35
%74 = phi i64 [ 0, %35 ], [ %108, %73 ]
%75 = phi double [ 0.000000e+00, %35 ], [ %107, %73 ]
%76 = phi i64 [ 0, %35 ], [ %109, %73 ]
%77 = getelementptr inbounds double, double* %9, i64 %74
%78 = load double, double* %77
%79 = fadd double %75, %78
%80 = or i64 %74, 1
%81 = getelementptr inbounds double, double* %9, i64 %80
%82 = load double, double* %81
%83 = fadd double %79, %82
%84 = or i64 %74, 2
%85 = getelementptr inbounds double, double* %9, i64 %84
%86 = load double, double* %85
%87 = fadd double %83, %86
%88 = or i64 %74, 3
%89 = getelementptr inbounds double, double* %9, i64 %88
%90 = load double, double* %89
%91 = fadd double %87, %90
%92 = or i64 %74, 4
%93 = getelementptr inbounds double, double* %9, i64 %92
%94 = load double, double* %93
%95 = fadd double %91, %94
%96 = or i64 %74, 5
%97 = getelementptr inbounds double, double* %9, i64 %96
%98 = load double, double* %97
%99 = fadd double %95, %98
%100 = or i64 %74, 6
%101 = getelementptr inbounds double, double* %9, i64 %100
%102 = load double, double* %101
%103 = fadd double %99, %102
%104 = or i64 %74, 7
%105 = getelementptr inbounds double, double* %9, i64 %104
%106 = load double, double* %105
%107 = fadd double %103, %106
%108 = add nuw nsw i64 %74, 8
%109 = add i64 %76, 8
%110 = icmp eq i64 %109, %36
br i1 %110, label %111, label %73
111: ; preds = %73, %31
%112 = phi double [ undef, %31 ], [ %107, %73 ]
%113 = phi i64 [ 0, %31 ], [ %108, %73 ]
%114 = phi double [ 0.000000e+00, %31 ], [ %107, %73 ]
%115 = icmp eq i64 %33, 0
br i1 %115, label %126, label %116
116: ; preds = %111, %116
%117 = phi i64 [ %123, %116 ], [ %113, %111 ]
%118 = phi double [ %122, %116 ], [ %114, %111 ]
%119 = phi i64 [ %124, %116 ], [ 0, %111 ]
%120 = getelementptr inbounds double, double* %9, i64 %117
%121 = load double, double* %120
%122 = fadd double %118, %121
%123 = add nuw nsw i64 %117, 1
%124 = add i64 %119, 1
%125 = icmp eq i64 %124, %33
br i1 %125, label %126, label %116
126: ; preds = %116, %111
%127 = phi double [ %112, %111 ], [ %122, %116 ]
%128 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %127)
br i1 %13, label %136, label %129
129: ; preds = %126, %129
%130 = phi i64 [ %134, %129 ], [ 0, %126 ]
%131 = getelementptr inbounds double, double* %9, i64 %130
%132 = load double, double* %131
%133 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %132)
%134 = add nuw i64 %130, 1
%135 = icmp eq i64 %134, %4
br i1 %135, label %136, label %129
136: ; preds = %129, %37, %126
%137 = tail call i32 @fputc(i32 10, i32* %0)
%138 = tail call i32 @free(double* %9)
ret void
}