#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long long *, ...);
int /*<<< orphan*/ sort_cols(long long **, long long);
int /*<<< orphan*/ sort_rows(long long *, long long);
int main() {
  long long int arr[1000][1000];
  long long int i, j, row_size, col_size;
  long long int k, x, y, z, t, n, m;
  scanf("%lld", &t);
  for (k = 1; k <= t; k++) {
    scanf("%lld %lld", &n, &m);
    for (x = 0; x < n; x++) {
      for (y = 0; y < m; y++) {
        scanf("%lld", &arr[x][y]);
      }
    }
    printf("Original array:\n");
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        printf("%lld ", arr[i][j]);
      }
      printf("\n");
    }
    row_size = n;
    for (i = 0; i < row_size; i++) {
      sort_rows(arr[i], m);
    }
    col_size = m;
    for (i = 0; i < col_size; i++) {
      sort_cols(arr, col_size);
    }
    printf("Sorted Array:\n");
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        printf("%lld ", arr[i][j]);
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1270,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeac(%rip),%rdi
lea    -0x7a1258(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movq   $0x1,-0x7a1238(%rbp)
mov    -0x7a1238(%rbp),%rax
cmp    -0x7a1258(%rbp),%rax
jg     1491 <main+0x351>
lea    0xe73(%rip),%rdi
lea    -0x7a1260(%rbp),%rsi
lea    -0x7a1268(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movq   $0x0,-0x7a1240(%rbp)
mov    -0x7a1240(%rbp),%rax
cmp    -0x7a1260(%rbp),%rax
jge    1244 <main+0x104>
movq   $0x0,-0x7a1248(%rbp)
mov    -0x7a1248(%rbp),%rax
cmp    -0x7a1268(%rbp),%rax
jge    1228 <main+0xe8>
lea    -0x7a1210(%rbp),%rsi
imul   $0x1f40,-0x7a1240(%rbp),%rax
add    %rax,%rsi
mov    -0x7a1248(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x7a1248(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1248(%rbp)
jmp    11cc <main+0x8c>
jmp    122d <main+0xed>
mov    -0x7a1240(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1240(%rbp)
jmp    11ad <main+0x6d>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x7a1218(%rbp)
mov    -0x7a1218(%rbp),%rax
cmp    -0x7a1260(%rbp),%rax
jge    12fa <main+0x1ba>
movq   $0x0,-0x7a1220(%rbp)
mov    -0x7a1220(%rbp),%rax
cmp    -0x7a1268(%rbp),%rax
jge    12d5 <main+0x195>
lea    -0x7a1210(%rbp),%rax
imul   $0x1f40,-0x7a1218(%rbp),%rcx
add    %rcx,%rax
mov    -0x7a1220(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x7a1220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1220(%rbp)
jmp    127c <main+0x13c>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x7a1218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1218(%rbp)
jmp    125d <main+0x11d>
mov    -0x7a1260(%rbp),%rax
mov    %rax,-0x7a1228(%rbp)
movq   $0x0,-0x7a1218(%rbp)
mov    -0x7a1218(%rbp),%rax
cmp    -0x7a1228(%rbp),%rax
jge    135f <main+0x21f>
lea    -0x7a1210(%rbp),%rdi
imul   $0x1f40,-0x7a1218(%rbp),%rax
add    %rax,%rdi
mov    -0x7a1268(%rbp),%rsi
call   1060 <sort_rows@plt>
mov    -0x7a1218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1218(%rbp)
jmp    1313 <main+0x1d3>
mov    -0x7a1268(%rbp),%rax
mov    %rax,-0x7a1230(%rbp)
movq   $0x0,-0x7a1218(%rbp)
mov    -0x7a1218(%rbp),%rax
cmp    -0x7a1230(%rbp),%rax
jge    13b6 <main+0x276>
lea    -0x7a1210(%rbp),%rdi
mov    -0x7a1230(%rbp),%rsi
call   1040 <sort_cols@plt>
mov    -0x7a1218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1218(%rbp)
jmp    1378 <main+0x238>
lea    0xc64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x7a1218(%rbp)
mov    -0x7a1218(%rbp),%rax
cmp    -0x7a1260(%rbp),%rax
jge    146c <main+0x32c>
movq   $0x0,-0x7a1220(%rbp)
mov    -0x7a1220(%rbp),%rax
cmp    -0x7a1268(%rbp),%rax
jge    1447 <main+0x307>
lea    -0x7a1210(%rbp),%rax
imul   $0x1f40,-0x7a1218(%rbp),%rcx
add    %rcx,%rax
mov    -0x7a1220(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xbf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x7a1220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1220(%rbp)
jmp    13ee <main+0x2ae>
lea    0xbe0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x7a1218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1218(%rbp)
jmp    13cf <main+0x28f>
lea    0xbbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x7a1238(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x7a1238(%rbp)
jmp    1172 <main+0x32>
xor    %eax,%eax
add    $0x7a1270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7a1228,%rsp
lea    0xe8d(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpq   $0x0,0x10(%rsp)
jle    13aa <main+0x24a>
mov    $0x1,%eax
lea    0xe69(%rip),%r13
lea    0xe67(%rip),%r14
jmp    11ce <main+0x6e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x18(%rsp),%rcx
lea    0x1(%rcx),%rax
cmp    0x10(%rsp),%rcx
jge    13aa <main+0x24a>
mov    %rax,0x18(%rsp)
lea    0xe26(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
jle    1260 <main+0x100>
mov    (%rsp),%rax
lea    0x20(%rsp),%rbp
xor    %r15d,%r15d
jmp    1220 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0x1f40,%rbp
cmp    %rcx,%r15
jge    1260 <main+0x100>
test   %rax,%rax
jle    1210 <main+0xb0>
mov    %rbp,%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbx
mov    (%rsp),%rax
add    $0x8,%r12
cmp    %rax,%rbx
jl     1230 <main+0xd0>
mov    0x8(%rsp),%rcx
jmp    1210 <main+0xb0>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xda9(%rip),%rdi
call   1040 <puts@plt>
cmpq   $0x0,0x8(%rsp)
lea    0x20(%rsp),%r15
jle    1309 <main+0x1a9>
mov    %r15,%rbp
xor    %r15d,%r15d
jmp    12af <main+0x14f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
mov    0x8(%rsp),%rbx
add    $0x1f40,%rbp
cmp    %rbx,%r15
jge    12e0 <main+0x180>
cmpq   $0x0,(%rsp)
jle    1290 <main+0x130>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    (%rsp),%rbx
jl     12c0 <main+0x160>
jmp    1290 <main+0x130>
nopl   0x0(%rax,%rax,1)
test   %rbx,%rbx
lea    0x20(%rsp),%r15
jle    1309 <main+0x1a9>
mov    %r15,%rbp
nopl   (%rax)
mov    (%rsp),%rsi
mov    %rbp,%rdi
call   1080 <sort_rows@plt>
add    $0x1f40,%rbp
add    $0xffffffffffffffff,%rbx
jne    12f0 <main+0x190>
mov    (%rsp),%rbp
test   %rbp,%rbp
jle    1331 <main+0x1d1>
mov    %rbp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbp,%rsi
call   1060 <sort_cols@plt>
add    $0xffffffffffffffff,%rbx
jne    1320 <main+0x1c0>
lea    0xce8(%rip),%rdi
call   1040 <puts@plt>
cmpq   $0x0,0x8(%rsp)
jle    11b0 <main+0x50>
lea    0x20(%rsp),%rbx
xor    %r15d,%r15d
jmp    1380 <main+0x220>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
add    $0x1f40,%rbx
cmp    0x8(%rsp),%r15
jge    11b0 <main+0x50>
cmpq   $0x0,(%rsp)
jle    1360 <main+0x200>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%rbx,%rbp,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    (%rsp),%rbp
jl     1390 <main+0x230>
jmp    1360 <main+0x200>
xor    %eax,%eax
add    $0x7a1228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [10 x i8] c"%lld %lld\00"
@.str.2 = [17 x i8] c"Original array:\0A\00"
@.str.3 = [6 x i8] c"%lld \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [15 x i8] c"Sorted Array:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x [1000 x i64]]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %1
%14 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %11)
store i64 1, i64* %7
br label %15
15: ; preds = %126, %0
%16 = load i64, i64* %7
%17 = load i64, i64* %11
%18 = icmp sle i64 %16, %17
br i1 %18, label %19, label %129
19: ; preds = %15
%20 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %12, i64* %13)
store i64 0, i64* %8
br label %21
21: ; preds = %40, %19
%22 = load i64, i64* %8
%23 = load i64, i64* %12
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
store i64 0, i64* %9
br label %26
26: ; preds = %36, %25
%27 = load i64, i64* %9
%28 = load i64, i64* %13
%29 = icmp slt i64 %27, %28
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i64, i64* %8
%32 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %2, i64 0, i64 %31
%33 = load i64, i64* %9
%34 = getelementptr inbounds [1000 x i64], [1000 x i64]* %32, i64 0, i64 %33
%35 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %34)
br label %36
36: ; preds = %30
%37 = load i64, i64* %9
%38 = add nsw i64 %37, 1
store i64 %38, i64* %9
br label %26
39: ; preds = %26
br label %40
40: ; preds = %39
%41 = load i64, i64* %8
%42 = add nsw i64 %41, 1
store i64 %42, i64* %8
br label %21
43: ; preds = %21
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %3
br label %45
45: ; preds = %66, %43
%46 = load i64, i64* %3
%47 = load i64, i64* %12
%48 = icmp slt i64 %46, %47
br i1 %48, label %49, label %69
49: ; preds = %45
store i64 0, i64* %4
br label %50
50: ; preds = %61, %49
%51 = load i64, i64* %4
%52 = load i64, i64* %13
%53 = icmp slt i64 %51, %52
br i1 %53, label %54, label %64
54: ; preds = %50
%55 = load i64, i64* %3
%56 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %2, i64 0, i64 %55
%57 = load i64, i64* %4
%58 = getelementptr inbounds [1000 x i64], [1000 x i64]* %56, i64 0, i64 %57
%59 = load i64, i64* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %59)
br label %61
61: ; preds = %54
%62 = load i64, i64* %4
%63 = add nsw i64 %62, 1
store i64 %63, i64* %4
br label %50
64: ; preds = %50
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %64
%67 = load i64, i64* %3
%68 = add nsw i64 %67, 1
store i64 %68, i64* %3
br label %45
69: ; preds = %45
%70 = load i64, i64* %12
store i64 %70, i64* %5
store i64 0, i64* %3
br label %71
71: ; preds = %81, %69
%72 = load i64, i64* %3
%73 = load i64, i64* %5
%74 = icmp slt i64 %72, %73
br i1 %74, label %75, label %84
75: ; preds = %71
%76 = load i64, i64* %3
%77 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %2, i64 0, i64 %76
%78 = getelementptr inbounds [1000 x i64], [1000 x i64]* %77, i64 0, i64 0
%79 = load i64, i64* %13
%80 = call i32 @sort_rows(i64* %78, i64 %79)
br label %81
81: ; preds = %75
%82 = load i64, i64* %3
%83 = add nsw i64 %82, 1
store i64 %83, i64* %3
br label %71
84: ; preds = %71
%85 = load i64, i64* %13
store i64 %85, i64* %6
store i64 0, i64* %3
br label %86
86: ; preds = %95, %84
%87 = load i64, i64* %3
%88 = load i64, i64* %6
%89 = icmp slt i64 %87, %88
br i1 %89, label %90, label %98
90: ; preds = %86
%91 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %2, i64 0, i64 0
%92 = bitcast [1000 x i64]* %91 to i64**
%93 = load i64, i64* %6
%94 = call i32 @sort_cols(i64** %92, i64 %93)
br label %95
95: ; preds = %90
%96 = load i64, i64* %3
%97 = add nsw i64 %96, 1
store i64 %97, i64* %3
br label %86
98: ; preds = %86
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i64 0, i64* %3
br label %100
100: ; preds = %121, %98
%101 = load i64, i64* %3
%102 = load i64, i64* %12
%103 = icmp slt i64 %101, %102
br i1 %103, label %104, label %124
104: ; preds = %100
store i64 0, i64* %4
br label %105
105: ; preds = %116, %104
%106 = load i64, i64* %4
%107 = load i64, i64* %13
%108 = icmp slt i64 %106, %107
br i1 %108, label %109, label %119
109: ; preds = %105
%110 = load i64, i64* %3
%111 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %2, i64 0, i64 %110
%112 = load i64, i64* %4
%113 = getelementptr inbounds [1000 x i64], [1000 x i64]* %111, i64 0, i64 %112
%114 = load i64, i64* %113
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %114)
br label %116
116: ; preds = %109
%117 = load i64, i64* %4
%118 = add nsw i64 %117, 1
store i64 %118, i64* %4
br label %105
119: ; preds = %105
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %121
121: ; preds = %119
%122 = load i64, i64* %3
%123 = add nsw i64 %122, 1
store i64 %123, i64* %3
br label %100
124: ; preds = %100
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %126
126: ; preds = %124
%127 = load i64, i64* %7
%128 = add nsw i64 %127, 1
store i64 %128, i64* %7
br label %15
129: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [10 x i8] c"%lld %lld\00"
@.str.3 = [6 x i8] c"%lld \00"
@str = [16 x i8] c"Original array:\00"
@str.6 = [14 x i8] c"Sorted Array:\00"
define i32 @main() {
%1 = alloca [1000 x [1000 x i64]]
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = bitcast [1000 x [1000 x i64]]* %1 to i8*
%6 = bitcast i64* %2 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%10 = load i64, i64* %2
%11 = icmp slt i64 %10, 1
br i1 %11, label %104, label %12
12: ; preds = %0
%13 = bitcast [1000 x [1000 x i64]]* %1 to i64**
br label %14
14: ; preds = %12, %99
%15 = phi i64 [ 1, %12 ], [ %101, %99 ]
%16 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %3, i64* %4)
%17 = load i64, i64* %3
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %14
%20 = load i64, i64* %4
br label %21
21: ; preds = %19, %35
%22 = phi i64 [ %36, %35 ], [ %17, %19 ]
%23 = phi i64 [ %37, %35 ], [ %20, %19 ]
%24 = phi i64 [ %38, %35 ], [ 0, %19 ]
%25 = icmp sgt i64 %23, 0
br i1 %25, label %26, label %35
26: ; preds = %21, %26
%27 = phi i64 [ %30, %26 ], [ 0, %21 ]
%28 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %1, i64 0, i64 %24, i64 %27
%29 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %28)
%30 = add nuw nsw i64 %27, 1
%31 = load i64, i64* %4
%32 = icmp slt i64 %30, %31
br i1 %32, label %26, label %33
33: ; preds = %26
%34 = load i64, i64* %3
br label %35
35: ; preds = %33, %21
%36 = phi i64 [ %34, %33 ], [ %22, %21 ]
%37 = phi i64 [ %31, %33 ], [ %23, %21 ]
%38 = add nuw nsw i64 %24, 1
%39 = icmp slt i64 %38, %36
br i1 %39, label %21, label %40
40: ; preds = %35, %14
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%42 = load i64, i64* %3
%43 = icmp sgt i64 %42, 0
br i1 %43, label %46, label %70
44: ; preds = %58
%45 = icmp sgt i64 %61, 0
br i1 %45, label %63, label %70
46: ; preds = %40, %58
%47 = phi i64 [ %60, %58 ], [ 0, %40 ]
%48 = load i64, i64* %4
%49 = icmp sgt i64 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %46, %50
%51 = phi i64 [ %55, %50 ], [ 0, %46 ]
%52 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %1, i64 0, i64 %47, i64 %51
%53 = load i64, i64* %52
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %53)
%55 = add nuw nsw i64 %51, 1
%56 = load i64, i64* %4
%57 = icmp slt i64 %55, %56
br i1 %57, label %50, label %58
58: ; preds = %50, %46
%59 = call i32 @putchar(i32 10)
%60 = add nuw nsw i64 %47, 1
%61 = load i64, i64* %3
%62 = icmp slt i64 %60, %61
br i1 %62, label %46, label %44
63: ; preds = %44, %63
%64 = phi i64 [ %68, %63 ], [ 0, %44 ]
%65 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %1, i64 0, i64 %64, i64 0
%66 = load i64, i64* %4
%67 = call i32 @sort_rows(i64* %65, i64 %66)
%68 = add nuw nsw i64 %64, 1
%69 = icmp eq i64 %68, %61
br i1 %69, label %70, label %63
70: ; preds = %63, %40, %44
%71 = load i64, i64* %4
%72 = icmp sgt i64 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %70, %73
%74 = phi i64 [ %76, %73 ], [ 0, %70 ]
%75 = call i32 @sort_cols(i64** %13, i64 %71)
%76 = add nuw nsw i64 %74, 1
%77 = icmp eq i64 %76, %71
br i1 %77, label %78, label %73
78: ; preds = %73, %70
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
%80 = load i64, i64* %3
%81 = icmp sgt i64 %80, 0
br i1 %81, label %82, label %99
82: ; preds = %78, %94
%83 = phi i64 [ %96, %94 ], [ 0, %78 ]
%84 = load i64, i64* %4
%85 = icmp sgt i64 %84, 0
br i1 %85, label %86, label %94
86: ; preds = %82, %86
%87 = phi i64 [ %91, %86 ], [ 0, %82 ]
%88 = getelementptr inbounds [1000 x [1000 x i64]], [1000 x [1000 x i64]]* %1, i64 0, i64 %83, i64 %87
%89 = load i64, i64* %88
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %89)
%91 = add nuw nsw i64 %87, 1
%92 = load i64, i64* %4
%93 = icmp slt i64 %91, %92
br i1 %93, label %86, label %94
94: ; preds = %86, %82
%95 = call i32 @putchar(i32 10)
%96 = add nuw nsw i64 %83, 1
%97 = load i64, i64* %3
%98 = icmp slt i64 %96, %97
br i1 %98, label %82, label %99
99: ; preds = %94, %78
%100 = call i32 @putchar(i32 10)
%101 = add nuw nsw i64 %15, 1
%102 = load i64, i64* %2
%103 = icmp slt i64 %15, %102
br i1 %103, label %14, label %104
104: ; preds = %99, %0
ret i32 0
}