#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 exp(double);
scalar_t__ malloc(int);
double **sigmoid(double **matrix, int row, int column) {
  double **result = (double **)malloc(row * sizeof(double *));
  for (int i = 0; i < row; i++) {
    result[i] = (double *)malloc(column * sizeof(double));
    for (int j = 0; j < column; j++) {
      result[i][j] = 1.0 / (1 + exp(-matrix[i][j]));
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<sigmoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1203 <sigmoid+0xe3>
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f0 <sigmoid+0xd0>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <exp@plt>
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe37(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117d <sigmoid+0x5d>
jmp    11f5 <sigmoid+0xd5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <sigmoid+0x2c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigmoid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %esi,%r12d
mov    %rdi,%r15
lea    0x0(,%r12,8),%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11e4 <sigmoid+0xc4>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0xc(%rsp)
mov    %r12d,%r12d
mov    %eax,%ebp
xor    %r14d,%r14d
jmp    1179 <sigmoid+0x59>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r12,%r14
je     11e4 <sigmoid+0xc4>
mov    0xc(%rsp),%edi
call   1030 <malloc@plt>
mov    %rax,(%rbx,%r14,8)
cmpl   $0x0,0x10(%rsp)
movaps 0xe6e(%rip),%xmm1
jle    1170 <sigmoid+0x50>
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    (%r15,%r14,8),%rax
movsd  (%rax,%r13,8),%xmm0
xorps  %xmm1,%xmm0
call   1040 <exp@plt>
movsd  0xe56(%rip),%xmm1
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
mov    (%rbx,%r14,8),%rax
movsd  %xmm1,(%rax,%r13,8)
movaps 0xe27(%rip),%xmm1
add    $0x1,%r13
cmp    %r13,%rbp
jne    11a0 <sigmoid+0x80>
jmp    1170 <sigmoid+0x50>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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