#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 **MM(int **, int **);
int **MM2(int **, int **);
int (*powerni(int A[][2], int N))[2] {
  int Y[2][2] = {{1, 0}, {0, 1}};
  int(*y)[2], (*x)[2];
  x = A;
  y = Y;
  while (N > 0) {
    if ((N % 2) != 0)
      y = MM2(y, x);
    x = MM(x, x);
    N /= 2;
  }
  return y;
}


x86 assembly (clang, -O0):
<powerni>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11a8 <powerni+0x88>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1184 <powerni+0x64>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <MM2@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <MM@plt>
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1155 <powerni+0x35>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<powerni>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movaps 0xed0(%rip),%xmm0
movaps %xmm0,(%rsp)
test   %esi,%esi
jle    117e <powerni+0x5e>
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%r15
jmp    1169 <powerni+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r14,%rsi
call   1040 <MM@plt>
mov    %rax,%r14
mov    %ebx,%eax
shr    %eax
cmp    $0x1,%ebx
mov    %eax,%ebx
jbe    1181 <powerni+0x61>
test   $0x1,%bl
je     1150 <powerni+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <MM2@plt>
mov    %rax,%r15
jmp    1150 <powerni+0x30>
mov    %rsp,%r15
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.powerni.Y = [2 x [2 x i32]] [[2 x i32] [i32 1, i32 0], [2 x i32] [i32 0, i32 1]]
define [2 x i32]* @powerni([2 x i32]* %0, i32 %1) {
%3 = alloca [2 x i32]*
%4 = alloca i32
%5 = alloca [2 x [2 x i32]]
%6 = alloca [2 x i32]*
%7 = alloca [2 x i32]*
store [2 x i32]* %0, [2 x i32]** %3
store i32 %1, i32* %4
%8 = bitcast [2 x [2 x i32]]* %5 to i8*
%9 = load [2 x i32]*, [2 x i32]** %3
store [2 x i32]* %9, [2 x i32]** %7
%10 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %5, i64 0, i64 0
store [2 x i32]* %10, [2 x i32]** %6
br label %11
11: ; preds = %25, %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %34
14: ; preds = %11
%15 = load i32, i32* %4
%16 = srem i32 %15, 2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load [2 x i32]*, [2 x i32]** %6
%20 = bitcast [2 x i32]* %19 to i32**
%21 = load [2 x i32]*, [2 x i32]** %7
%22 = bitcast [2 x i32]* %21 to i32**
%23 = call i32** @MM2(i32** %20, i32** %22)
%24 = bitcast i32** %23 to [2 x i32]*
store [2 x i32]* %24, [2 x i32]** %6
br label %25
25: ; preds = %18, %14
%26 = load [2 x i32]*, [2 x i32]** %7
%27 = bitcast [2 x i32]* %26 to i32**
%28 = load [2 x i32]*, [2 x i32]** %7
%29 = bitcast [2 x i32]* %28 to i32**
%30 = call i32** @MM(i32** %27, i32** %29)
%31 = bitcast i32** %30 to [2 x i32]*
store [2 x i32]* %31, [2 x i32]** %7
%32 = load i32, i32* %4
%33 = sdiv i32 %32, 2
store i32 %33, i32* %4
br label %11
34: ; preds = %11
%35 = load [2 x i32]*, [2 x i32]** %6
ret [2 x i32]* %35
}

LLVM IR (-O2):
@__const.powerni.Y = [2 x [2 x i32]] [[2 x i32] [i32 1, i32 0], [2 x i32] [i32 0, i32 1]]
define [2 x i32]* @powerni([2 x i32]* %0, i32 %1) {
%3 = alloca [2 x [2 x i32]]
%4 = bitcast [2 x [2 x i32]]* %3 to i8*
%5 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %3, i64 0, i64 0
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %25
7: ; preds = %2, %18
%8 = phi [2 x i32]* [ %22, %18 ], [ %0, %2 ]
%9 = phi [2 x i32]* [ %19, %18 ], [ %5, %2 ]
%10 = phi i32 [ %23, %18 ], [ %1, %2 ]
%11 = and i32 %10, 1
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %7
%14 = bitcast [2 x i32]* %9 to i32**
%15 = bitcast [2 x i32]* %8 to i32**
%16 = call i32** @MM2(i32** %14, i32** %15)
%17 = bitcast i32** %16 to [2 x i32]*
br label %18
18: ; preds = %7, %13
%19 = phi [2 x i32]* [ %17, %13 ], [ %9, %7 ]
%20 = bitcast [2 x i32]* %8 to i32**
%21 = call i32** @MM(i32** %20, i32** %20)
%22 = bitcast i32** %21 to [2 x i32]*
%23 = lshr i32 %10, 1
%24 = icmp ult i32 %10, 2
br i1 %24, label %25, label %7
25: ; preds = %18, %2
%26 = phi [2 x i32]* [ %5, %2 ], [ %19, %18 ]
ret [2 x i32]* %26
}