#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 pow(double, double);
void matrix_pow(double **Y, double **X, int n, int m, double pw) {
  int i, j;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j)
      Y[i][j] = pow(X[i][j], pw);
}


x86 assembly (clang, -O0):
<matrix_pow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a6 <matrix_pow+0x96>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1193 <matrix_pow+0x83>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <pow@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1145 <matrix_pow+0x35>
jmp    1198 <matrix_pow+0x88>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <matrix_pow+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_pow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    11e4 <matrix_pow+0xd4>
mov    %ecx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %edx,%eax
mov    %rax,0x10(%rsp)
mov    %ecx,%r13d
mov    %r13,0x8(%rsp)
and    $0xfffffffe,%r13d
xor    %r12d,%r12d
movsd  %xmm0,(%rsp)
jmp    115f <matrix_pow+0x4f>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    0x10(%rsp),%r12
je     11e4 <matrix_pow+0xd4>
test   %r14d,%r14d
jle    1150 <matrix_pow+0x40>
xor    %r15d,%r15d
cmp    $0x1,%r14d
je     11b9 <matrix_pow+0xa9>
nopl   (%rax)
mov    (%rbx,%r12,8),%rax
movsd  (%rax,%r15,8),%xmm0
movsd  (%rsp),%xmm1
call   1030 <pow@plt>
mov    0x0(%rbp,%r12,8),%rax
movsd  %xmm0,(%rax,%r15,8)
mov    (%rbx,%r12,8),%rax
movsd  0x8(%rax,%r15,8),%xmm0
movsd  (%rsp),%xmm1
call   1030 <pow@plt>
mov    0x0(%rbp,%r12,8),%rax
movsd  %xmm0,0x8(%rax,%r15,8)
add    $0x2,%r15
cmp    %r15,%r13
jne    1170 <matrix_pow+0x60>
testb  $0x1,0x8(%rsp)
je     1150 <matrix_pow+0x40>
mov    (%rbx,%r12,8),%rax
movsd  (%rax,%r15,8),%xmm0
movsd  (%rsp),%xmm1
call   1030 <pow@plt>
mov    0x0(%rbp,%r12,8),%rax
movsd  %xmm0,(%rax,%r15,8)
jmp    1150 <matrix_pow+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @matrix_pow(double** %0, double** %1, i32 %2, i32 %3, double %4) {
%6 = alloca double**
%7 = alloca double**
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
store double** %0, double*** %6
store double** %1, double*** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store double %4, double* %10
store i32 0, i32* %11
br label %13
13: ; preds = %46, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %49
17: ; preds = %13
store i32 0, i32* %12
br label %18
18: ; preds = %42, %17
%19 = load i32, i32* %12
%20 = load i32, i32* %9
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = load double**, double*** %7
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double*, double** %23, i64 %25
%27 = load double*, double** %26
%28 = load i32, i32* %12
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double, double* %10
%33 = call double @pow(double %31, double %32)
%34 = load double**, double*** %6
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
%38 = load double*, double** %37
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
store double %33, double* %41
br label %42
42: ; preds = %22
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
br label %18
45: ; preds = %18
br label %46
46: ; preds = %45
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
br label %13
49: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @matrix_pow(double** nocapture %0, double** nocapture %1, i32 %2, i32 %3, double %4) {
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %51
7: ; preds = %5
%8 = icmp sgt i32 %3, 0
%9 = zext i32 %2 to i64
%10 = zext i32 %3 to i64
%11 = and i64 %10, 1
%12 = icmp eq i32 %3, 1
%13 = and i64 %10, 4294967294
%14 = icmp eq i64 %11, 0
br label %15
15: ; preds = %7, %48
%16 = phi i64 [ 0, %7 ], [ %49, %48 ]
br i1 %8, label %17, label %48
17: ; preds = %15
%18 = getelementptr inbounds double*, double** %1, i64 %16
%19 = getelementptr inbounds double*, double** %0, i64 %16
br i1 %12, label %39, label %20
20: ; preds = %17, %20
%21 = phi i64 [ %36, %20 ], [ 0, %17 ]
%22 = phi i64 [ %37, %20 ], [ 0, %17 ]
%23 = load double*, double** %18
%24 = getelementptr inbounds double, double* %23, i64 %21
%25 = load double, double* %24
%26 = tail call double @pow(double %25, double %4)
%27 = load double*, double** %19
%28 = getelementptr inbounds double, double* %27, i64 %21
store double %26, double* %28
%29 = or i64 %21, 1
%30 = load double*, double** %18
%31 = getelementptr inbounds double, double* %30, i64 %29
%32 = load double, double* %31
%33 = tail call double @pow(double %32, double %4)
%34 = load double*, double** %19
%35 = getelementptr inbounds double, double* %34, i64 %29
store double %33, double* %35
%36 = add nuw nsw i64 %21, 2
%37 = add i64 %22, 2
%38 = icmp eq i64 %37, %13
br i1 %38, label %39, label %20
39: ; preds = %20, %17
%40 = phi i64 [ 0, %17 ], [ %36, %20 ]
br i1 %14, label %48, label %41
41: ; preds = %39
%42 = load double*, double** %18
%43 = getelementptr inbounds double, double* %42, i64 %40
%44 = load double, double* %43
%45 = tail call double @pow(double %44, double %4)
%46 = load double*, double** %19
%47 = getelementptr inbounds double, double* %46, i64 %40
store double %45, double* %47
br label %48
48: ; preds = %41, %39, %15
%49 = add nuw nsw i64 %16, 1
%50 = icmp eq i64 %49, %9
br i1 %50, label %51, label %15
51: ; preds = %48, %5
ret void
}