#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 /*<<< orphan*/ Cblacs_gridinfo(int, int *, int *, int *, int *);
int numroc_(int *, int *, int *, int *, int *);
void dmat_ldimget(int *desc, int *nrows, int *ncols) {
  int M = desc[2];
  int N = desc[3];
  int Mb = desc[4];
  int Nb = desc[5];
  int ictxt = desc[1];
  int rsrc = desc[6];
  int csrc = desc[7];
  int nprow, npcol, myprow, mypcol;
  Cblacs_gridinfo(ictxt, &nprow, &npcol, &myprow, &mypcol);
  *nrows = numroc_(&M, &Mb, &myprow, &rsrc, &nprow);
  *ncols = numroc_(&N, &Nb, &mypcol, &csrc, &npcol);
  if (*nrows < 1 || *ncols < 1) {
    *nrows = 0;
    *ncols = 0;
  }
}


x86 assembly (clang, -O0):
<dmat_ldimget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1040 <Cblacs_gridinfo@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1030 <numroc_@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x44(%rbp),%rdx
lea    -0x34(%rbp),%rcx
lea    -0x3c(%rbp),%r8
call   1030 <numroc_@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jl     11ee <dmat_ldimget+0xce>
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1202 <dmat_ldimget+0xe2>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmat_ldimget>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x8(%rdi),%eax
mov    %eax,0x14(%rsp)
mov    0xc(%rdi),%eax
mov    %eax,0x10(%rsp)
mov    0x10(%rdi),%eax
mov    %eax,0xc(%rsp)
mov    0x14(%rdi),%eax
mov    %eax,0x8(%rsp)
mov    0x4(%rdi),%eax
mov    0x18(%rdi),%ecx
mov    %ecx,0x4(%rsp)
mov    0x1c(%rdi),%ecx
mov    %ecx,(%rsp)
lea    0x24(%rsp),%r12
lea    0x20(%rsp),%r15
lea    0x1c(%rsp),%r13
lea    0x18(%rsp),%rbp
mov    %eax,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1040 <Cblacs_gridinfo@plt>
lea    0x14(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x4(%rsp),%rcx
mov    %r13,%rdx
mov    %r12,%r8
call   1030 <numroc_@plt>
mov    %eax,(%rbx)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rcx
mov    %rbp,%rdx
mov    %r15,%r8
call   1030 <numroc_@plt>
mov    %eax,(%r14)
cmpl   $0x0,(%rbx)
jle    11c7 <dmat_ldimget+0xa7>
test   %eax,%eax
jg     11d4 <dmat_ldimget+0xb4>
movl   $0x0,(%rbx)
movl   $0x0,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @dmat_ldimget(i32* nocapture %0, i32* nocapture %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = bitcast i32* %4 to i8*
%15 = getelementptr inbounds i32, i32* %0, i64 2
%16 = load i32, i32* %15
store i32 %16, i32* %4
%17 = bitcast i32* %5 to i8*
%18 = getelementptr inbounds i32, i32* %0, i64 3
%19 = load i32, i32* %18
store i32 %19, i32* %5
%20 = bitcast i32* %6 to i8*
%21 = getelementptr inbounds i32, i32* %0, i64 4
%22 = load i32, i32* %21
store i32 %22, i32* %6
%23 = bitcast i32* %7 to i8*
%24 = getelementptr inbounds i32, i32* %0, i64 5
%25 = load i32, i32* %24
store i32 %25, i32* %7
%26 = getelementptr inbounds i32, i32* %0, i64 1
%27 = load i32, i32* %26
%28 = bitcast i32* %8 to i8*
%29 = getelementptr inbounds i32, i32* %0, i64 6
%30 = load i32, i32* %29
store i32 %30, i32* %8
%31 = bitcast i32* %9 to i8*
%32 = getelementptr inbounds i32, i32* %0, i64 7
%33 = load i32, i32* %32
store i32 %33, i32* %9
%34 = bitcast i32* %10 to i8*
%35 = bitcast i32* %11 to i8*
%36 = bitcast i32* %12 to i8*
%37 = bitcast i32* %13 to i8*
%38 = call i32 @Cblacs_gridinfo(i32 %27, i32* %10, i32* %11, i32* %12, i32* %13)
%39 = call i32 @numroc_(i32* %4, i32* %6, i32* %12, i32* %8, i32* %10)
store i32 %39, i32* %1
%40 = call i32 @numroc_(i32* %5, i32* %7, i32* %13, i32* %9, i32* %11)
store i32 %40, i32* %2
%41 = load i32, i32* %1
%42 = icmp slt i32 %41, 1
%43 = icmp slt i32 %40, 1
%44 = select i1 %42, i1 true, i1 %43
br i1 %44, label %45, label %46
45: ; preds = %3
store i32 0, i32* %1
store i32 0, i32* %2
br label %46
46: ; preds = %3, %45
ret void
}