#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*/ add_pair_to_comm_schedule(int **, int, int);
void fill_comm_schedule(int **sched, int npes) {
  int pe, i, n;
  if (npes % 2 == 0) {
    n = npes;
    for (pe = 0; pe < npes; ++pe)
      add_pair_to_comm_schedule(sched, pe, pe);
  } else
    n = npes + 1;
  for (pe = 0; pe < n - 1; ++pe) {
    add_pair_to_comm_schedule(sched, pe, npes % 2 == 0 ? npes - 1 : pe);
    for (i = 1; i < n / 2; ++i) {
      int pe_a, pe_b;
      pe_a = pe - i;
      if (pe_a < 0)
        pe_a += n - 1;
      pe_b = (pe + i) % (n - 1);
      add_pair_to_comm_schedule(sched, pe_a, pe_b);
    }
  }
}


x86 assembly (clang, -O0):
<fill_comm_schedule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116e <fill_comm_schedule+0x5e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1169 <fill_comm_schedule+0x59>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <add_pair_to_comm_schedule@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1140 <fill_comm_schedule+0x30>
jmp    1177 <fill_comm_schedule+0x67>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    125a <fill_comm_schedule+0x14a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11bf <fill_comm_schedule+0xaf>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c5 <fill_comm_schedule+0xb5>
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
call   1030 <add_pair_to_comm_schedule@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    1247 <fill_comm_schedule+0x137>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1218 <fill_comm_schedule+0x108>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1030 <add_pair_to_comm_schedule@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11db <fill_comm_schedule+0xcb>
jmp    124c <fill_comm_schedule+0x13c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117e <fill_comm_schedule+0x6e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_comm_schedule>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r14d
mov    %rdi,%r13
test   $0x1,%r14b
jne    1161 <fill_comm_schedule+0x51>
test   %r14d,%r14d
jle    1227 <fill_comm_schedule+0x117>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
call   1030 <add_pair_to_comm_schedule@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1140 <fill_comm_schedule+0x30>
mov    %r14d,%ebp
cmp    $0x2,%ebp
jge    116e <fill_comm_schedule+0x5e>
jmp    1227 <fill_comm_schedule+0x117>
lea    0x1(%r14),%ebp
cmp    $0x2,%ebp
jl     1227 <fill_comm_schedule+0x117>
lea    -0x1(%rbp),%ebx
lea    -0x1(%r14),%eax
mov    %eax,0x14(%rsp)
mov    %ebp,%eax
shr    %eax
cmp    $0x3,%eax
mov    $0x2,%ecx
cmovge %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x10(%rsp)
xor    %r15d,%r15d
movl   $0x1,0xc(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
mov    %r14,0x20(%rsp)
mov    %rbp,0x18(%rsp)
jmp    11cd <fill_comm_schedule+0xbd>
xchg   %ax,%ax
add    $0x1,%r15d
addl   $0x1,0xc(%rsp)
addl   $0x1,0x8(%rsp)
cmp    %ebx,%r15d
mov    0x20(%rsp),%r14
mov    0x18(%rsp),%rbp
je     1227 <fill_comm_schedule+0x117>
test   $0x1,%r14b
mov    %r15d,%edx
cmove  0x14(%rsp),%edx
mov    %r13,%rdi
mov    %r15d,%esi
call   1030 <add_pair_to_comm_schedule@plt>
cmp    $0x4,%ebp
jb     11b0 <fill_comm_schedule+0xa0>
mov    0x8(%rsp),%r14d
mov    0xc(%rsp),%ebp
mov    0x10(%rsp),%r12d
nopw   0x0(%rax,%rax,1)
mov    %r14d,%esi
sar    $0x1f,%esi
and    %ebx,%esi
add    %r14d,%esi
mov    %ebp,%eax
cltd
idiv   %ebx
mov    %r13,%rdi
call   1030 <add_pair_to_comm_schedule@plt>
add    $0x1,%ebp
add    $0xffffffff,%r14d
add    $0xffffffff,%r12d
jne    1200 <fill_comm_schedule+0xf0>
jmp    11b0 <fill_comm_schedule+0xa0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fill_comm_schedule(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32** %0, i32*** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = srem i32 %10, 2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %2
%14 = load i32, i32* %4
store i32 %14, i32* %7
store i32 0, i32* %5
br label %15
15: ; preds = %24, %13
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32**, i32*** %3
%21 = load i32, i32* %5
%22 = load i32, i32* %5
%23 = call i32 @add_pair_to_comm_schedule(i32** %20, i32 %21, i32 %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %15
27: ; preds = %15
br label %31
28: ; preds = %2
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %31
31: ; preds = %28, %27
store i32 0, i32* %5
br label %32
32: ; preds = %82, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %85
37: ; preds = %32
%38 = load i32**, i32*** %3
%39 = load i32, i32* %5
%40 = load i32, i32* %4
%41 = srem i32 %40, 2
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = load i32, i32* %4
%45 = sub nsw i32 %44, 1
br label %48
46: ; preds = %37
%47 = load i32, i32* %5
br label %48
48: ; preds = %46, %43
%49 = phi i32 [ %45, %43 ], [ %47, %46 ]
%50 = call i32 @add_pair_to_comm_schedule(i32** %38, i32 %39, i32 %49)
store i32 1, i32* %6
br label %51
51: ; preds = %78, %48
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = sdiv i32 %53, 2
%55 = icmp slt i32 %52, %54
br i1 %55, label %56, label %81
56: ; preds = %51
%57 = load i32, i32* %5
%58 = load i32, i32* %6
%59 = sub nsw i32 %57, %58
store i32 %59, i32* %8
%60 = load i32, i32* %8
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %56
%63 = load i32, i32* %7
%64 = sub nsw i32 %63, 1
%65 = load i32, i32* %8
%66 = add nsw i32 %65, %64
store i32 %66, i32* %8
br label %67
67: ; preds = %62, %56
%68 = load i32, i32* %5
%69 = load i32, i32* %6
%70 = add nsw i32 %68, %69
%71 = load i32, i32* %7
%72 = sub nsw i32 %71, 1
%73 = srem i32 %70, %72
store i32 %73, i32* %9
%74 = load i32**, i32*** %3
%75 = load i32, i32* %8
%76 = load i32, i32* %9
%77 = call i32 @add_pair_to_comm_schedule(i32** %74, i32 %75, i32 %76)
br label %78
78: ; preds = %67
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %51
81: ; preds = %51
br label %82
82: ; preds = %81
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
br label %32
85: ; preds = %32
ret void
}

LLVM IR (-O2):
define void @fill_comm_schedule(i32** %0, i32 %1) {
%3 = and i32 %1, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %41
7: ; preds = %5, %7
%8 = phi i32 [ %10, %7 ], [ 0, %5 ]
%9 = tail call i32 @add_pair_to_comm_schedule(i32** %0, i32 %8, i32 %8)
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, %1
br i1 %11, label %14, label %7
12: ; preds = %2
%13 = add nsw i32 %1, 1
br label %14
14: ; preds = %7, %12
%15 = phi i32 [ %13, %12 ], [ %1, %7 ]
%16 = add i32 %15, -1
%17 = icmp sgt i32 %15, 1
br i1 %17, label %18, label %41
18: ; preds = %14
%19 = add nsw i32 %1, -1
%20 = lshr i32 %15, 1
%21 = icmp ugt i32 %15, 3
%22 = call i32 @llvm.smax.i32(i32 %20, i32 2)
br label %23
23: ; preds = %18, %38
%24 = phi i32 [ 0, %18 ], [ %39, %38 ]
%25 = select i1 %4, i32 %19, i32 %24
%26 = tail call i32 @add_pair_to_comm_schedule(i32** %0, i32 %24, i32 %25)
br i1 %21, label %27, label %38
27: ; preds = %23, %27
%28 = phi i32 [ %36, %27 ], [ 1, %23 ]
%29 = sub nsw i32 %24, %28
%30 = icmp slt i32 %29, 0
%31 = select i1 %30, i32 %16, i32 0
%32 = add nsw i32 %31, %29
%33 = add nuw nsw i32 %28, %24
%34 = srem i32 %33, %16
%35 = tail call i32 @add_pair_to_comm_schedule(i32** %0, i32 %32, i32 %34)
%36 = add nuw nsw i32 %28, 1
%37 = icmp eq i32 %36, %22
br i1 %37, label %38, label %27
38: ; preds = %27, %23
%39 = add nuw nsw i32 %24, 1
%40 = icmp eq i32 %39, %16
br i1 %40, label %41, label %23
41: ; preds = %38, %5, %14
ret void
}