#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 */
struct matrix {
  int dummy;
};

/* Variables and functions */
scalar_t__ matrix_multiply(struct matrix **, struct matrix **);
int /*<<< orphan*/ matrix_release(struct matrix *);
struct matrix *matrix_transpose(struct matrix *);
int matrix_construct_r(struct matrix *matrix, struct matrix **result) {
  int res;
  struct matrix *xt;
  res = 0;
  xt = matrix_transpose(matrix);
  if (!xt)
    res = -1;
  else {
    struct matrix *params[2];
    struct matrix *ptr;
    params[0] = xt;
    params[1] = matrix;
    if (0 > matrix_multiply(params, &ptr))
      res = -1;
    else {
      *result = ptr;
      matrix_release(xt);
    }
  }
  return res;
}


x86 assembly (clang, -O0):
<matrix_construct_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <matrix_transpose@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <matrix_construct_r+0x3b>
movl   $0xffffffff,-0x14(%rbp)
jmp    11bb <matrix_construct_r+0x8b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <matrix_multiply@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11a2 <matrix_construct_r+0x72>
movl   $0xffffffff,-0x14(%rbp)
jmp    11b6 <matrix_construct_r+0x86>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <matrix_release@plt>
jmp    11bb <matrix_construct_r+0x8b>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_construct_r>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <matrix_transpose@plt>
test   %rax,%rax
je     117e <matrix_construct_r+0x4e>
mov    %rax,%r15
mov    %rax,0x10(%rsp)
mov    %rbx,0x18(%rsp)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <matrix_multiply@plt>
test   %rax,%rax
js     117e <matrix_construct_r+0x4e>
mov    0x8(%rsp),%rax
mov    %rax,(%r14)
mov    %r15,%rdi
call   1030 <matrix_release@plt>
xor    %eax,%eax
jmp    1183 <matrix_construct_r+0x53>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.matrix = type { i32 }
define i32 @matrix_construct_r(%struct.matrix* %0, %struct.matrix** %1) {
%3 = alloca %struct.matrix*
%4 = alloca %struct.matrix**
%5 = alloca i32
%6 = alloca %struct.matrix*
%7 = alloca [2 x %struct.matrix*]
%8 = alloca %struct.matrix*
store %struct.matrix* %0, %struct.matrix** %3
store %struct.matrix** %1, %struct.matrix*** %4
store i32 0, i32* %5
%9 = load %struct.matrix*, %struct.matrix** %3
%10 = call %struct.matrix* @matrix_transpose(%struct.matrix* %9)
store %struct.matrix* %10, %struct.matrix** %6
%11 = load %struct.matrix*, %struct.matrix** %6
%12 = icmp ne %struct.matrix* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 -1, i32* %5
br label %29
14: ; preds = %2
%15 = load %struct.matrix*, %struct.matrix** %6
%16 = getelementptr inbounds [2 x %struct.matrix*], [2 x %struct.matrix*]* %7, i64 0, i64 0
store %struct.matrix* %15, %struct.matrix** %16
%17 = load %struct.matrix*, %struct.matrix** %3
%18 = getelementptr inbounds [2 x %struct.matrix*], [2 x %struct.matrix*]* %7, i64 0, i64 1
store %struct.matrix* %17, %struct.matrix** %18
%19 = getelementptr inbounds [2 x %struct.matrix*], [2 x %struct.matrix*]* %7, i64 0, i64 0
%20 = call i64 @matrix_multiply(%struct.matrix** %19, %struct.matrix** %8)
%21 = icmp sgt i64 0, %20
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 -1, i32* %5
br label %28
23: ; preds = %14
%24 = load %struct.matrix*, %struct.matrix** %8
%25 = load %struct.matrix**, %struct.matrix*** %4
store %struct.matrix* %24, %struct.matrix** %25
%26 = load %struct.matrix*, %struct.matrix** %6
%27 = call i32 @matrix_release(%struct.matrix* %26)
br label %28
28: ; preds = %23, %22
br label %29
29: ; preds = %28, %13
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
%struct.matrix = type { i32 }
define i32 @matrix_construct_r(%struct.matrix* %0, %struct.matrix** nocapture writeonly %1) {
%3 = alloca [2 x %struct.matrix*]
%4 = alloca %struct.matrix*
%5 = tail call %struct.matrix* @matrix_transpose(%struct.matrix* %0)
%6 = icmp eq %struct.matrix* %5, null
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = bitcast [2 x %struct.matrix*]* %3 to i8*
%9 = bitcast %struct.matrix** %4 to i8*
%10 = getelementptr inbounds [2 x %struct.matrix*], [2 x %struct.matrix*]* %3, i64 0, i64 0
store %struct.matrix* %5, %struct.matrix** %10
%11 = getelementptr inbounds [2 x %struct.matrix*], [2 x %struct.matrix*]* %3, i64 0, i64 1
store %struct.matrix* %0, %struct.matrix** %11
%12 = call i64 @matrix_multiply(%struct.matrix** %10, %struct.matrix** %4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %7
%15 = load %struct.matrix*, %struct.matrix** %4
store %struct.matrix* %15, %struct.matrix** %1
%16 = call i32 @matrix_release(%struct.matrix* %5)
br label %17
17: ; preds = %7, %14
%18 = phi i32 [ 0, %14 ], [ -1, %7 ]
br label %19
19: ; preds = %2, %17
%20 = phi i32 [ %18, %17 ], [ -1, %2 ]
ret i32 %20
}