#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*/ swap_by_ind(int, int, double *);
void xpose_inplace_nonsquare(const int m, const int n, double *x) {
  int i, j, k, idx;
  for (k = 0; k < n * m; k++) {
    idx = k;
    while (true) {
      idx = (idx % n) * m + idx / n;
      if (idx >= k)
        break;
    }
    swap_by_ind(k, idx, x);
  }
  return;
}


x86 assembly (clang, -O0):
<xpose_inplace_nonsquare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   -0x4(%rbp),%ecx
cmp    %ecx,%eax
jge    1193 <xpose_inplace_nonsquare+0x83>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x8(%rbp)
imul   -0x4(%rbp),%edx
mov    %edx,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1171 <xpose_inplace_nonsquare+0x61>
jmp    1176 <xpose_inplace_nonsquare+0x66>
jmp    1141 <xpose_inplace_nonsquare+0x31>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <swap_by_ind@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1129 <xpose_inplace_nonsquare+0x19>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xpose_inplace_nonsquare>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
imul   %edi,%r12d
test   %r12d,%r12d
jle    1163 <xpose_inplace_nonsquare+0x53>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %ebp,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %edx,%eax
cltd
idiv   %r15d
imul   %ebx,%edx
add    %eax,%edx
cmp    %ebp,%edx
jl     1140 <xpose_inplace_nonsquare+0x30>
mov    %ebp,%edi
mov    %edx,%esi
mov    %r14,%rdx
call   1030 <swap_by_ind@plt>
add    $0x1,%ebp
cmp    %r12d,%ebp
jne    1130 <xpose_inplace_nonsquare+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @xpose_inplace_nonsquare(i32 %0, i32 %1, double* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store double* %2, double** %6
store i32 0, i32* %9
br label %11
11: ; preds = %39, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = mul nsw i32 %13, %14
%16 = icmp slt i32 %12, %15
br i1 %16, label %17, label %42
17: ; preds = %11
%18 = load i32, i32* %9
store i32 %18, i32* %10
br label %19
19: ; preds = %17, %33
%20 = load i32, i32* %10
%21 = load i32, i32* %5
%22 = srem i32 %20, %21
%23 = load i32, i32* %4
%24 = mul nsw i32 %22, %23
%25 = load i32, i32* %10
%26 = load i32, i32* %5
%27 = sdiv i32 %25, %26
%28 = add nsw i32 %24, %27
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = icmp sge i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %19
br label %34
33: ; preds = %19
br label %19
34: ; preds = %32
%35 = load i32, i32* %9
%36 = load i32, i32* %10
%37 = load double*, double** %6
%38 = call i32 @swap_by_ind(i32 %35, i32 %36, double* %37)
br label %39
39: ; preds = %34
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %11
42: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @xpose_inplace_nonsquare(i32 %0, i32 %1, double* %2) {
%4 = mul i32 %1, %0
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %3, %15
%7 = phi i32 [ %17, %15 ], [ 0, %3 ]
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ %13, %8 ], [ %7, %6 ]
%10 = srem i32 %9, %1
%11 = mul nsw i32 %10, %0
%12 = sdiv i32 %9, %1
%13 = add nsw i32 %11, %12
%14 = icmp slt i32 %13, %7
br i1 %14, label %8, label %15
15: ; preds = %8
%16 = tail call i32 @swap_by_ind(i32 %7, i32 %13, double* %2)
%17 = add nuw nsw i32 %7, 1
%18 = icmp eq i32 %17, %4
br i1 %18, label %19, label %6
19: ; preds = %15, %3
ret void
}