#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 */
scalar_t__ calloc(int, int);
double exp(double);
double **matrix_sigmoid(double **mat, int mat_row, int mat_col) {
  double **sigmoid = (double **)calloc(mat_row, sizeof(double *));
  for (int i = 0; i < mat_row; i++)
    sigmoid[i] = (double *)calloc(mat_col, sizeof(double));
  for (int i = 0; i < mat_row; i++)
    for (int j = 0; j < mat_col; j++)
      sigmoid[i][j] = 1.0 / (1.0 + exp(-mat[i][j]));
  return sigmoid;
}


x86 assembly (clang, -O0):
<matrix_sigmoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1180 <matrix_sigmoid+0x60>
mov    -0x10(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <matrix_sigmoid+0x2a>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1225 <matrix_sigmoid+0x105>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1212 <matrix_sigmoid+0xf2>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <exp@plt>
movsd  0xe21(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xe15(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <matrix_sigmoid+0x7a>
jmp    1217 <matrix_sigmoid+0xf7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1187 <matrix_sigmoid+0x67>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_sigmoid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r13
mov    %esi,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %r12d,%r12d
jle    1201 <matrix_sigmoid+0xe1>
mov    %r12d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%r15,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <matrix_sigmoid+0x40>
mov    %rbx,(%rsp)
test   %r12d,%r12d
jle    1201 <matrix_sigmoid+0xe1>
mov    %r14d,%ebx
xor    %ebp,%ebp
movapd 0xe70(%rip),%xmm1
jmp    11ad <matrix_sigmoid+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    (%rsp),%rbp
mov    %r12d,%r14d
je     1201 <matrix_sigmoid+0xe1>
mov    %r14d,%r12d
test   %r14d,%r14d
jle    11a0 <matrix_sigmoid+0x80>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbp,8),%rax
movsd  (%rax,%r14,8),%xmm0
xorpd  %xmm1,%xmm0
call   1040 <exp@plt>
movsd  0xe34(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  %xmm0,%xmm1
mov    (%r15,%rbp,8),%rax
movsd  %xmm1,(%rax,%r14,8)
movapd 0xe0a(%rip),%xmm1
add    $0x1,%r14
cmp    %r14,%rbx
jne    11c0 <matrix_sigmoid+0xa0>
jmp    11a0 <matrix_sigmoid+0x80>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @matrix_sigmoid(double** %0, i32 %1, i32 %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca i32
%7 = alloca double**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = call i64 @calloc(i32 %11, i32 8)
%13 = inttoptr i64 %12 to double**
store double** %13, double*** %7
store i32 0, i32* %8
br label %14
14: ; preds = %26, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32, i32* %6
%20 = call i64 @calloc(i32 %19, i32 8)
%21 = inttoptr i64 %20 to double*
%22 = load double**, double*** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double*, double** %22, i64 %24
store double* %21, double** %25
br label %26
26: ; preds = %18
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %14
29: ; preds = %14
store i32 0, i32* %9
br label %30
30: ; preds = %65, %29
%31 = load i32, i32* %9
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %68
34: ; preds = %30
store i32 0, i32* %10
br label %35
35: ; preds = %61, %34
%36 = load i32, i32* %10
%37 = load i32, i32* %6
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %64
39: ; preds = %35
%40 = load double**, double*** %4
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double*, double** %40, i64 %42
%44 = load double*, double** %43
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = fneg double %48
%50 = call double @exp(double %49)
%51 = fadd double 1.000000e+00, %50
%52 = fdiv double 1.000000e+00, %51
%53 = load double**, double*** %7
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double*, double** %53, i64 %55
%57 = load double*, double** %56
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
store double %52, double* %60
br label %61
61: ; preds = %39
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %35
64: ; preds = %35
br label %65
65: ; preds = %64
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %30
68: ; preds = %30
%69 = load double**, double*** %7
ret double** %69
}

LLVM IR (-O2):
define double** @matrix_sigmoid(double** nocapture %0, i32 %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %1, i32 8)
%5 = inttoptr i64 %4 to double**
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %26
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %14
9: ; preds = %14
br i1 %6, label %10, label %26
10: ; preds = %9
%11 = icmp sgt i32 %2, 0
%12 = zext i32 %1 to i64
%13 = zext i32 %2 to i64
br label %21
14: ; preds = %7, %14
%15 = phi i64 [ 0, %7 ], [ %19, %14 ]
%16 = tail call i64 @calloc(i32 %2, i32 8)
%17 = inttoptr i64 %16 to double*
%18 = getelementptr inbounds double*, double** %5, i64 %15
store double* %17, double** %18
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %9, label %14
21: ; preds = %10, %27
%22 = phi i64 [ 0, %10 ], [ %28, %27 ]
br i1 %11, label %23, label %27
23: ; preds = %21
%24 = getelementptr inbounds double*, double** %0, i64 %22
%25 = getelementptr inbounds double*, double** %5, i64 %22
br label %30
26: ; preds = %27, %3, %9
ret double** %5
27: ; preds = %30, %21
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, %12
br i1 %29, label %26, label %21
30: ; preds = %23, %30
%31 = phi i64 [ 0, %23 ], [ %41, %30 ]
%32 = load double*, double** %24
%33 = getelementptr inbounds double, double* %32, i64 %31
%34 = load double, double* %33
%35 = fneg double %34
%36 = tail call double @exp(double %35)
%37 = fadd double %36, 1.000000e+00
%38 = fdiv double 1.000000e+00, %37
%39 = load double*, double** %25
%40 = getelementptr inbounds double, double* %39, i64 %31
store double %38, double* %40
%41 = add nuw nsw i64 %31, 1
%42 = icmp eq i64 %41, %13
br i1 %42, label %27, label %30
}