#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 atoi(char *);
int check_comm_schedule(int **, int);
int /*<<< orphan*/ empty_comm_schedule(int **, int);
int /*<<< orphan*/ fill_comm_schedule(int **, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free_comm_schedule(int **, int);
int /*<<< orphan*/ invert_comm_schedule(int **, int);
int **make_comm_schedule(int);
int /*<<< orphan*/ print_comm_schedule(int **, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort_comm_schedule(int **, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int **sched;
  int npes = -1, sortpe = -1, steps;
  if (argc >= 2) {
    npes = atoi(argv[1]);
    if (npes <= 0) {
      fprintf(stderr, "npes must be positive!");
      return 1;
    }
  }
  if (argc >= 3) {
    sortpe = atoi(argv[2]);
    if (sortpe < 0 || sortpe >= npes) {
      fprintf(stderr, "sortpe must be between 0 and npes-1.\n");
      return 1;
    }
  }
  if (npes != -1) {
    printf("Computing schedule for npes = %d:\n", npes);
    sched = make_comm_schedule(npes);
    if (!sched) {
      fprintf(stderr, "Out of memory!");
      return 6;
    }
    if (steps = check_comm_schedule(sched, npes))
      printf("schedule OK (takes %d steps to complete).\n", steps);
    else
      printf("schedule not OK.\n");
    print_comm_schedule(sched, npes);
    if (sortpe != -1) {
      printf("\nSorting schedule for sortpe = %d...\n", sortpe);
      sort_comm_schedule(sched, npes, sortpe);
      if (steps = check_comm_schedule(sched, npes))
        printf("schedule OK (takes %d steps to complete).\n", steps);
      else
        printf("schedule not OK.\n");
      print_comm_schedule(sched, npes);
      printf("\nInverting schedule...\n");
      invert_comm_schedule(sched, npes);
      if (steps = check_comm_schedule(sched, npes))
        printf("schedule OK (takes %d steps to complete).\n", steps);
      else
        printf("schedule not OK.\n");
      print_comm_schedule(sched, npes);
      free_comm_schedule(sched, npes);
    }
  } else {
    printf("Doing infinite tests...\n");
    for (npes = 1;; ++npes) {
      printf("npes = %d...", npes);
      sched = make_comm_schedule(npes);
      if (!sched) {
        fprintf(stderr, "Out of memory!\n");
        return 5;
      }
      for (sortpe = 0; sortpe < npes; ++sortpe) {
        empty_comm_schedule(sched, npes);
        fill_comm_schedule(sched, npes);
        if (!check_comm_schedule(sched, npes)) {
          fprintf(stderr, "\n -- fill error for sortpe = %d!\n", sortpe);
          return 2;
        }
        sort_comm_schedule(sched, npes, sortpe);
        if (!check_comm_schedule(sched, npes)) {
          fprintf(stderr, "\n -- sort error for sortpe = %d!\n", sortpe);
          return 3;
        }
        invert_comm_schedule(sched, npes);
        if (!check_comm_schedule(sched, npes)) {
          fprintf(stderr, "\n -- invert error for sortpe = %d!\n", sortpe);
          return 4;
        }
      }
      free_comm_schedule(sched, npes);
      printf("OK\n");
      if (npes % 50 == 0)
        printf("(...Hit Ctrl-C to stop...)\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1220 <main+0x70>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     121b <main+0x6b>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x40a>
jmp    1220 <main+0x70>
cmpl   $0x3,-0x8(%rbp)
jl     1278 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     1250 <main+0xa0>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1273 <main+0xc3>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x40a>
jmp    1278 <main+0xc8>
cmpl   $0xffffffff,-0x1c(%rbp)
je     13fa <main+0x24a>
mov    -0x1c(%rbp),%esi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   10c0 <make_comm_schedule@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12cd <main+0x11d>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x6,-0x4(%rbp)
jmp    15ba <main+0x40a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <check_comm_schedule@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     12fb <main+0x14b>
mov    -0x24(%rbp),%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1309 <main+0x159>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10d0 <print_comm_schedule@plt>
cmpl   $0xffffffff,-0x20(%rbp)
je     13f5 <main+0x245>
mov    -0x20(%rbp),%esi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10b0 <sort_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <check_comm_schedule@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     136d <main+0x1bd>
mov    -0x24(%rbp),%esi
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    137b <main+0x1cb>
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10d0 <print_comm_schedule@plt>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <invert_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <check_comm_schedule@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     13cf <main+0x21f>
mov    -0x24(%rbp),%esi
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13dd <main+0x22d>
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10d0 <print_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <free_comm_schedule@plt>
jmp    15b3 <main+0x403>
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   10c0 <make_comm_schedule@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    145a <main+0x2aa>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
lea    0xcc9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    15ba <main+0x40a>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1564 <main+0x3b4>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <empty_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <fill_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <check_comm_schedule@plt>
cmp    $0x0,%eax
jne    14c0 <main+0x310>
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xc73(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    15ba <main+0x40a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10b0 <sort_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <check_comm_schedule@plt>
cmp    $0x0,%eax
jne    150a <main+0x35a>
mov    0x2af5(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xc4b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    15ba <main+0x40a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <invert_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <check_comm_schedule@plt>
cmp    $0x0,%eax
jne    1551 <main+0x3a1>
mov    0x2aae(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xc26(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    15ba <main+0x40a>
jmp    1556 <main+0x3a6>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1461 <main+0x2b1>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <free_comm_schedule@plt>
lea    0xc11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x32,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    15a0 <main+0x3f0>
lea    0xbf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    15a5 <main+0x3f5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    140f <main+0x25f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1262 <main+0xa2>
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
test   %eax,%eax
jle    13a0 <main+0x1e0>
mov    %eax,%r12d
mov    $0xffffffff,%r15d
cmp    $0x3,%ebx
jb     1215 <main+0x55>
mov    0x10(%rbp),%rdi
call   10b0 <atoi@plt>
test   %eax,%eax
js     143f <main+0x27f>
mov    %eax,%r15d
cmp    %r12d,%eax
jge    143f <main+0x27f>
lea    0xe21(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12d,%edi
call   10d0 <make_comm_schedule@plt>
test   %rax,%rax
je     141e <main+0x25e>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12d,%esi
call   1090 <check_comm_schedule@plt>
test   %eax,%eax
je     1460 <main+0x2a0>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    146c <main+0x2ac>
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4b(%rip),%rdi
mov    $0x1,%r13d
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <make_comm_schedule@plt>
test   %rax,%rax
je     137f <main+0x1bf>
mov    %rax,%rbx
lea    0xeb9(%rip),%r14
lea    0xeb5(%rip),%r15
lea    0xe0e(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r13d,%esi
call   1080 <empty_comm_schedule@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1070 <fill_comm_schedule@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1090 <check_comm_schedule@plt>
test   %eax,%eax
je     13b5 <main+0x1f5>
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
call   10c0 <sort_comm_schedule@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1090 <check_comm_schedule@plt>
test   %eax,%eax
je     13d8 <main+0x218>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1040 <invert_comm_schedule@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1090 <check_comm_schedule@plt>
test   %eax,%eax
je     13fb <main+0x23b>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    12c0 <main+0x100>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1050 <free_comm_schedule@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
imul   $0xc28f5c29,%r13d,%eax
ror    %eax
cmp    $0x51eb851,%eax
ja     135a <main+0x19a>
mov    %r15,%rdi
call   1030 <puts@plt>
add    $0x1,%r13d
mov    %r12,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13d,%edi
call   10d0 <make_comm_schedule@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12b2 <main+0xf2>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
lea    0xd3e(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x5,%eax
jmp    1534 <main+0x374>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
lea    0xc50(%rip),%rsi
jmp    144f <main+0x28f>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
lea    0xd18(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x2,%eax
jmp    1534 <main+0x374>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
lea    0xd17(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x3,%eax
jmp    1534 <main+0x374>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
lea    0xd16(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x4,%eax
jmp    1534 <main+0x374>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
lea    0xc32(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x6,%eax
jmp    1534 <main+0x374>
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
lea    0xbc8(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%eax
jmp    1534 <main+0x374>
lea    0xd2b(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   10e0 <print_comm_schedule@plt>
cmp    $0xffffffff,%r15d
je     1532 <main+0x372>
lea    0xc12(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   10c0 <sort_comm_schedule@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1090 <check_comm_schedule@plt>
test   %eax,%eax
je     14c1 <main+0x301>
lea    0xbb9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    14cd <main+0x30d>
lea    0xcca(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   10e0 <print_comm_schedule@plt>
lea    0xc9c(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <invert_comm_schedule@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1090 <check_comm_schedule@plt>
test   %eax,%eax
je     1510 <main+0x350>
lea    0xb6a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    151c <main+0x35c>
lea    0xc7b(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   10e0 <print_comm_schedule@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1050 <free_comm_schedule@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"npes must be positive!\00"
@.str.1 = [38 x i8] c"sortpe must be between 0 and npes-1.\0A\00"
@.str.2 = [35 x i8] c"Computing schedule for npes = %d:\0A\00"
@.str.3 = [15 x i8] c"Out of memory!\00"
@.str.4 = [43 x i8] c"schedule OK (takes %d steps to complete).\0A\00"
@.str.5 = [18 x i8] c"schedule not OK.\0A\00"
@.str.6 = [38 x i8] c"\0ASorting schedule for sortpe = %d...\0A\00"
@.str.7 = [24 x i8] c"\0AInverting schedule...\0A\00"
@.str.8 = [25 x i8] c"Doing infinite tests...\0A\00"
@.str.9 = [13 x i8] c"npes = %d...\00"
@.str.10 = [16 x i8] c"Out of memory!\0A\00"
@.str.11 = [34 x i8] c"\0A -- fill error for sortpe = %d!\0A\00"
@.str.12 = [34 x i8] c"\0A -- sort error for sortpe = %d!\0A\00"
@.str.13 = [36 x i8] c"\0A -- invert error for sortpe = %d!\0A\00"
@.str.14 = [4 x i8] c"OK\0A\00"
@.str.15 = [28 x i8] c"(...Hit Ctrl-C to stop...)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
store i32 -1, i32* %8
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 2
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %187
22: ; preds = %12
br label %23
23: ; preds = %22, %2
%24 = load i32, i32* %4
%25 = icmp sge i32 %24, 3
br i1 %25, label %26, label %41
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %26
%34 = load i32, i32* %8
%35 = load i32, i32* %7
%36 = icmp sge i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33, %26
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %187
40: ; preds = %33
br label %41
41: ; preds = %40, %23
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, -1
br i1 %43, label %44, label %111
44: ; preds = %41
%45 = load i32, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %7
%48 = call i32** @make_comm_schedule(i32 %47)
store i32** %48, i32*** %6
%49 = load i32**, i32*** %6
%50 = icmp ne i32** %49, null
br i1 %50, label %54, label %51
51: ; preds = %44
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 6, i32* %3
br label %187
54: ; preds = %44
%55 = load i32**, i32*** %6
%56 = load i32, i32* %7
%57 = call i32 @check_comm_schedule(i32** %55, i32 %56)
store i32 %57, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i32, i32* %9
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %60)
br label %64
62: ; preds = %54
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %62, %59
%65 = load i32**, i32*** %6
%66 = load i32, i32* %7
%67 = call i32 @print_comm_schedule(i32** %65, i32 %66)
%68 = load i32, i32* %8
%69 = icmp ne i32 %68, -1
br i1 %69, label %70, label %110
70: ; preds = %64
%71 = load i32, i32* %8
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %71)
%73 = load i32**, i32*** %6
%74 = load i32, i32* %7
%75 = load i32, i32* %8
%76 = call i32 @sort_comm_schedule(i32** %73, i32 %74, i32 %75)
%77 = load i32**, i32*** %6
%78 = load i32, i32* %7
%79 = call i32 @check_comm_schedule(i32** %77, i32 %78)
store i32 %79, i32* %9
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %70
%82 = load i32, i32* %9
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %82)
br label %86
84: ; preds = %70
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %86
86: ; preds = %84, %81
%87 = load i32**, i32*** %6
%88 = load i32, i32* %7
%89 = call i32 @print_comm_schedule(i32** %87, i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%91 = load i32**, i32*** %6
%92 = load i32, i32* %7
%93 = call i32 @invert_comm_schedule(i32** %91, i32 %92)
%94 = load i32**, i32*** %6
%95 = load i32, i32* %7
%96 = call i32 @check_comm_schedule(i32** %94, i32 %95)
store i32 %96, i32* %9
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %86
%99 = load i32, i32* %9
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %99)
br label %103
101: ; preds = %86
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %103
103: ; preds = %101, %98
%104 = load i32**, i32*** %6
%105 = load i32, i32* %7
%106 = call i32 @print_comm_schedule(i32** %104, i32 %105)
%107 = load i32**, i32*** %6
%108 = load i32, i32* %7
%109 = call i32 @free_comm_schedule(i32** %107, i32 %108)
br label %110
110: ; preds = %103, %64
br label %186
111: ; preds = %41
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %7
br label %113
113: ; preds = %183, %111
%114 = load i32, i32* %7
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i32 %114)
%116 = load i32, i32* %7
%117 = call i32** @make_comm_schedule(i32 %116)
store i32** %117, i32*** %6
%118 = load i32**, i32*** %6
%119 = icmp ne i32** %118, null
br i1 %119, label %123, label %120
120: ; preds = %113
%121 = load i32, i32* @stderr
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
store i32 5, i32* %3
br label %187
123: ; preds = %113
store i32 0, i32* %8
br label %124
124: ; preds = %169, %123
%125 = load i32, i32* %8
%126 = load i32, i32* %7
%127 = icmp slt i32 %125, %126
br i1 %127, label %128, label %172
128: ; preds = %124
%129 = load i32**, i32*** %6
%130 = load i32, i32* %7
%131 = call i32 @empty_comm_schedule(i32** %129, i32 %130)
%132 = load i32**, i32*** %6
%133 = load i32, i32* %7
%134 = call i32 @fill_comm_schedule(i32** %132, i32 %133)
%135 = load i32**, i32*** %6
%136 = load i32, i32* %7
%137 = call i32 @check_comm_schedule(i32** %135, i32 %136)
%138 = icmp ne i32 %137, 0
br i1 %138, label %143, label %139
139: ; preds = %128
%140 = load i32, i32* @stderr
%141 = load i32, i32* %8
%142 = call i32 (i32, i8*, ...) @fprintf(i32 %140, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i32 %141)
store i32 2, i32* %3
br label %187
143: ; preds = %128
%144 = load i32**, i32*** %6
%145 = load i32, i32* %7
%146 = load i32, i32* %8
%147 = call i32 @sort_comm_schedule(i32** %144, i32 %145, i32 %146)
%148 = load i32**, i32*** %6
%149 = load i32, i32* %7
%150 = call i32 @check_comm_schedule(i32** %148, i32 %149)
%151 = icmp ne i32 %150, 0
br i1 %151, label %156, label %152
152: ; preds = %143
%153 = load i32, i32* @stderr
%154 = load i32, i32* %8
%155 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i32 %154)
store i32 3, i32* %3
br label %187
156: ; preds = %143
%157 = load i32**, i32*** %6
%158 = load i32, i32* %7
%159 = call i32 @invert_comm_schedule(i32** %157, i32 %158)
%160 = load i32**, i32*** %6
%161 = load i32, i32* %7
%162 = call i32 @check_comm_schedule(i32** %160, i32 %161)
%163 = icmp ne i32 %162, 0
br i1 %163, label %168, label %164
164: ; preds = %156
%165 = load i32, i32* @stderr
%166 = load i32, i32* %8
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %165, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0), i32 %166)
store i32 4, i32* %3
br label %187
168: ; preds = %156
br label %169
169: ; preds = %168
%170 = load i32, i32* %8
%171 = add nsw i32 %170, 1
store i32 %171, i32* %8
br label %124
172: ; preds = %124
%173 = load i32**, i32*** %6
%174 = load i32, i32* %7
%175 = call i32 @free_comm_schedule(i32** %173, i32 %174)
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0))
%177 = load i32, i32* %7
%178 = srem i32 %177, 50
%179 = icmp eq i32 %178, 0
br i1 %179, label %180, label %182
180: ; preds = %172
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
br label %182
182: ; preds = %180, %172
br label %183
183: ; preds = %182
%184 = load i32, i32* %7
%185 = add nsw i32 %184, 1
store i32 %185, i32* %7
br label %113
186: ; preds = %110
store i32 0, i32* %3
br label %187
187: ; preds = %186, %164, %152, %139, %120, %51, %37, %19
%188 = load i32, i32* %3
ret i32 %188
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"npes must be positive!\00"
@.str.1 = [38 x i8] c"sortpe must be between 0 and npes-1.\0A\00"
@.str.2 = [35 x i8] c"Computing schedule for npes = %d:\0A\00"
@.str.3 = [15 x i8] c"Out of memory!\00"
@.str.4 = [43 x i8] c"schedule OK (takes %d steps to complete).\0A\00"
@.str.6 = [38 x i8] c"\0ASorting schedule for sortpe = %d...\0A\00"
@.str.9 = [13 x i8] c"npes = %d...\00"
@.str.10 = [16 x i8] c"Out of memory!\0A\00"
@.str.11 = [34 x i8] c"\0A -- fill error for sortpe = %d!\0A\00"
@.str.12 = [34 x i8] c"\0A -- sort error for sortpe = %d!\0A\00"
@.str.13 = [36 x i8] c"\0A -- invert error for sortpe = %d!\0A\00"
@str = [24 x i8] c"Doing infinite tests...\00"
@str.16 = [3 x i8] c"OK\00"
@str.17 = [27 x i8] c"(...Hit Ctrl-C to stop...)\00"
@str.20 = [23 x i8] c"\0AInverting schedule...\00"
@str.21 = [17 x i8] c"schedule not OK.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %64
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %113
12: ; preds = %4
%13 = icmp ugt i32 %0, 2
br i1 %13, label %14, label %24
14: ; preds = %12
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp sgt i32 %17, -1
%19 = icmp slt i32 %17, %7
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %24, label %21
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %113
24: ; preds = %12, %14
%25 = phi i32 [ %17, %14 ], [ -1, %12 ]
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%27 = tail call i32** @make_comm_schedule(i32 %7)
%28 = icmp eq i32** %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %113
32: ; preds = %24
%33 = tail call i32 @check_comm_schedule(i32** %27, i32 %7)
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %39
37: ; preds = %32
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.21, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
%40 = tail call i32 @print_comm_schedule(i32** %27, i32 %7)
%41 = icmp eq i32 %25, -1
br i1 %41, label %113, label %42
42: ; preds = %39
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%44 = tail call i32 @sort_comm_schedule(i32** %27, i32 %7, i32 %25)
%45 = tail call i32 @check_comm_schedule(i32** %27, i32 %7)
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %42
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %51
49: ; preds = %42
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.21, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
%52 = tail call i32 @print_comm_schedule(i32** %27, i32 %7)
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.20, i64 0, i64 0))
%54 = tail call i32 @invert_comm_schedule(i32** %27, i32 %7)
%55 = tail call i32 @check_comm_schedule(i32** %27, i32 %7)
%56 = icmp eq i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %51
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %55)
br label %61
59: ; preds = %51
%60 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.21, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
%62 = tail call i32 @print_comm_schedule(i32** %27, i32 %7)
%63 = tail call i32 @free_comm_schedule(i32** %27, i32 %7)
br label %113
64: ; preds = %2
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i32 1)
%67 = tail call i32** @make_comm_schedule(i32 1)
%68 = icmp eq i32** %67, null
br i1 %68, label %72, label %69
69: ; preds = %64, %108
%70 = phi i32** [ %111, %108 ], [ %67, %64 ]
%71 = phi i32 [ %109, %108 ], [ 1, %64 ]
br label %75
72: ; preds = %108, %64
%73 = load i32, i32* @stderr
%74 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %113
75: ; preds = %69, %98
%76 = phi i32 [ 0, %69 ], [ %99, %98 ]
%77 = tail call i32 @empty_comm_schedule(i32** %70, i32 %71)
%78 = tail call i32 @fill_comm_schedule(i32** %70, i32 %71)
%79 = tail call i32 @check_comm_schedule(i32** %70, i32 %71)
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %75
%82 = load i32, i32* @stderr
%83 = tail call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i32 %76)
br label %113
84: ; preds = %75
%85 = tail call i32 @sort_comm_schedule(i32** %70, i32 %71, i32 %76)
%86 = tail call i32 @check_comm_schedule(i32** %70, i32 %71)
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %84
%89 = load i32, i32* @stderr
%90 = tail call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i32 %76)
br label %113
91: ; preds = %84
%92 = tail call i32 @invert_comm_schedule(i32** %70, i32 %71)
%93 = tail call i32 @check_comm_schedule(i32** %70, i32 %71)
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = load i32, i32* @stderr
%97 = tail call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0), i32 %76)
br label %113
98: ; preds = %91
%99 = add nuw nsw i32 %76, 1
%100 = icmp eq i32 %99, %71
br i1 %100, label %101, label %75
101: ; preds = %98
%102 = tail call i32 @free_comm_schedule(i32** %70, i32 %71)
%103 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.16, i64 0, i64 0))
%104 = urem i32 %71, 50
%105 = icmp eq i32 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %101
%107 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.17, i64 0, i64 0))
br label %108
108: ; preds = %101, %106
%109 = add nuw nsw i32 %71, 1
%110 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i32 %109)
%111 = tail call i32** @make_comm_schedule(i32 %109)
%112 = icmp eq i32** %111, null
br i1 %112, label %72, label %69
113: ; preds = %61, %39, %95, %88, %81, %72, %29, %21, %9
%114 = phi i32 [ 1, %9 ], [ 1, %21 ], [ 6, %29 ], [ 4, %95 ], [ 3, %88 ], [ 2, %81 ], [ 5, %72 ], [ 0, %39 ], [ 0, %61 ]
ret i32 %114
}