#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_sub_total(FILE *stream, const double *energy,
                                  const double **res, size_t l, size_t c) {
  int i, k;
  double *sum;
  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];
  fprintf(stream, "\n");
  for (k = 0; k < c; k++) {
    fprintf(stream, "%12.6g\t", sum[k]);
  }
  fprintf(stream, "\n\n");
  free(sum);
}


x86 assembly (clang, -O0):
<glb_channel_printf_sub_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_sub_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_sub_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_sub_total+0x63>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1241 <glb_channel_printf_sub_total+0x101>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    122e <glb_channel_printf_sub_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_sub_total+0xab>
jmp    1233 <glb_channel_printf_sub_total+0xf3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d6 <glb_channel_printf_sub_total+0x96>
mov    -0x8(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1295 <glb_channel_printf_sub_total+0x155>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xda6(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    125a <glb_channel_printf_sub_total+0x11a>
mov    -0x8(%rbp),%rdi
lea    0xd8e(%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_sub_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     12a6 <glb_channel_printf_sub_total+0x136>
mov    %rax,%rbx
test   %r15,%r15
je     11b5 <glb_channel_printf_sub_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_sub_total+0xcf>
mov    %r15,%rax
and    $0xfffffffffffffffe,%rax
xor    %ecx,%ecx
jmp    11d9 <glb_channel_printf_sub_total+0x69>
nopl   0x0(%rax)
add    $0x1,%rcx
cmp    %r12,%rcx
je     123f <glb_channel_printf_sub_total+0xcf>
test   %r15,%r15
je     11d0 <glb_channel_printf_sub_total+0x60>
xor    %edx,%edx
cmp    $0x1,%r15
je     1223 <glb_channel_printf_sub_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_sub_total+0x80>
test   $0x1,%r15b
je     11d0 <glb_channel_printf_sub_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_sub_total+0x60>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
test   %r15,%r15
je     127c <glb_channel_printf_sub_total+0x10c>
xor    %r13d,%r13d
lea    0xdcb(%rip),%r12
nopl   0x0(%rax,%rax,1)
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    1260 <glb_channel_printf_sub_total+0xf0>
lea    0xdab(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%rcx
lea    0xd49(%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 = [2 x i8] c"\0A\00"
@.str.2 = [8 x i8] c"%12.6g\09\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @glb_channel_printf_sub_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*
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
%14 = load i64, i64* %10
%15 = mul i64 8, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %13
%19 = load double*, double** %13
%20 = icmp eq double* %19, null
br i1 %20, label %21, label %25
21: ; preds = %5
%22 = load i32*, i32** @stderr
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %5
store i32 0, i32* %12
br label %26
26: ; preds = %36, %25
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = load i64, i64* %10
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %26
%32 = load double*, double** %13
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double 0.000000e+00, double* %35
br label %36
36: ; preds = %31
%37 = load i32, i32* %12
%38 = add nsw i32 %37, 1
store i32 %38, i32* %12
br label %26
39: ; preds = %26
store i32 0, i32* %11
br label %40
40: ; preds = %71, %39
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = load i64, i64* %9
%44 = icmp ult i64 %42, %43
br i1 %44, label %45, label %74
45: ; preds = %40
store i32 0, i32* %12
br label %46
46: ; preds = %67, %45
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = load i64, i64* %10
%50 = icmp ult i64 %48, %49
br i1 %50, label %51, label %70
51: ; preds = %46
%52 = load double**, double*** %8
%53 = load i32, i32* %12
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double*, double** %52, i64 %54
%56 = load double*, double** %55
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = load double*, double** %13
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = fadd double %65, %60
store double %66, double* %64
br label %67
67: ; preds = %51
%68 = load i32, i32* %12
%69 = add nsw i32 %68, 1
store i32 %69, i32* %12
br label %46
70: ; preds = %46
br label %71
71: ; preds = %70
%72 = load i32, i32* %11
%73 = add nsw i32 %72, 1
store i32 %73, i32* %11
br label %40
74: ; preds = %40
%75 = load i32*, i32** %6
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %12
br label %77
77: ; preds = %90, %74
%78 = load i32, i32* %12
%79 = sext i32 %78 to i64
%80 = load i64, i64* %10
%81 = icmp ult i64 %79, %80
br i1 %81, label %82, label %93
82: ; preds = %77
%83 = load i32*, i32** %6
%84 = load double*, double** %13
%85 = load i32, i32* %12
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
%88 = load double, double* %87
%89 = call i32 (i32*, i8*, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %88)
br label %90
90: ; preds = %82
%91 = load i32, i32* %12
%92 = add nsw i32 %91, 1
store i32 %92, i32* %12
br label %77
93: ; preds = %77
%94 = load i32*, i32** %6
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%96 = load double*, double** %13
%97 = call i32 @free(double* %96)
ret void
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [38 x i8] c"glb: FATAL: Memory allocation failed\0A\00"
@.str.2 = [8 x i8] c"%12.6g\09\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @glb_channel_printf_sub_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 %64, 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, %61
%28 = phi i64 [ %62, %61 ], [ 0, %22 ]
br i1 %13, label %61, label %29
29: ; preds = %27
br i1 %24, label %51, label %30
30: ; preds = %29, %30
%31 = phi i64 [ %48, %30 ], [ 0, %29 ]
%32 = phi i64 [ %49, %30 ], [ 0, %29 ]
%33 = getelementptr inbounds double*, double** %2, i64 %31
%34 = load double*, double** %33
%35 = getelementptr inbounds double, double* %34, i64 %28
%36 = load double, double* %35
%37 = getelementptr inbounds double, double* %9, i64 %31
%38 = load double, double* %37
%39 = fadd double %36, %38
store double %39, double* %37
%40 = or i64 %31, 1
%41 = getelementptr inbounds double*, double** %2, i64 %40
%42 = load double*, double** %41
%43 = getelementptr inbounds double, double* %42, i64 %28
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %9, i64 %40
%46 = load double, double* %45
%47 = fadd double %44, %46
store double %47, double* %45
%48 = add nuw nsw i64 %31, 2
%49 = add i64 %32, 2
%50 = icmp eq i64 %49, %25
br i1 %50, label %51, label %30
51: ; preds = %30, %29
%52 = phi i64 [ 0, %29 ], [ %48, %30 ]
br i1 %26, label %61, label %53
53: ; preds = %51
%54 = getelementptr inbounds double*, double** %2, i64 %52
%55 = load double*, double** %54
%56 = getelementptr inbounds double, double* %55, i64 %28
%57 = load double, double* %56
%58 = getelementptr inbounds double, double* %9, i64 %52
%59 = load double, double* %58
%60 = fadd double %57, %59
store double %60, double* %58
br label %61
61: ; preds = %53, %51, %27
%62 = add nuw nsw i64 %28, 1
%63 = icmp eq i64 %62, %3
br i1 %63, label %64, label %27
64: ; preds = %61, %20
%65 = tail call i32 @fputc(i32 10, i32* %0)
br i1 %13, label %73, label %66
66: ; preds = %64, %66
%67 = phi i64 [ %71, %66 ], [ 0, %64 ]
%68 = getelementptr inbounds double, double* %9, i64 %67
%69 = load double, double* %68
%70 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %69)
%71 = add nuw i64 %67, 1
%72 = icmp eq i64 %71, %4
br i1 %72, label %73, label %66
73: ; preds = %66, %64
%74 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %0)
%75 = tail call i32 @free(double* %9)
ret void
}