#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*/ check_comm_schedule(int **, int);
int /*<<< orphan*/ empty_comm_schedule(int **, int);
int /*<<< orphan*/ fill_comm_schedule(int **, int);
int /*<<< orphan*/ free_comm_schedule(int **, int);
scalar_t__ malloc(int);
int **make_comm_schedule(int npes) {
  int **sched;
  int i;
  sched = (int **)malloc(sizeof(int *) * npes);
  if (!sched)
    return NULL;
  for (i = 0; i < npes; ++i)
    sched[i] = NULL;
  for (i = 0; i < npes; ++i) {
    sched[i] = (int *)malloc(sizeof(int) * 10 * (npes + 1));
    if (!sched[i]) {
      free_comm_schedule(sched, npes);
      return NULL;
    }
  }
  empty_comm_schedule(sched, npes);
  fill_comm_schedule(sched, npes);
  if (!check_comm_schedule(sched, npes)) {
    free_comm_schedule(sched, npes);
    return NULL;
  }
  return sched;
}


x86 assembly (clang, -O0):
<make_comm_schedule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <make_comm_schedule+0x36>
movq   $0x0,-0x8(%rbp)
jmp    1279 <make_comm_schedule+0x129>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b7 <make_comm_schedule+0x67>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <make_comm_schedule+0x3d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122b <make_comm_schedule+0xdb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
imul   $0x28,%rax,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1218 <make_comm_schedule+0xc8>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <free_comm_schedule@plt>
movq   $0x0,-0x8(%rbp)
jmp    1279 <make_comm_schedule+0x129>
jmp    121d <make_comm_schedule+0xcd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11be <make_comm_schedule+0x6e>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <empty_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <fill_comm_schedule@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <check_comm_schedule@plt>
cmp    $0x0,%eax
jne    1271 <make_comm_schedule+0x121>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <free_comm_schedule@plt>
movq   $0x0,-0x8(%rbp)
jmp    1279 <make_comm_schedule+0x129>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_comm_schedule>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11f9 <make_comm_schedule+0x99>
mov    %rax,%r12
test   %r14d,%r14d
jle    11c9 <make_comm_schedule+0x69>
mov    %r14d,%r15d
lea    0x0(,%r15,8),%rdx
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    (%r14,%r14,4),%eax
lea    0x28(,%rax,8),%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     11ee <make_comm_schedule+0x8e>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <make_comm_schedule+0x50>
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <empty_comm_schedule@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <fill_comm_schedule@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1070 <check_comm_schedule@plt>
test   %eax,%eax
jne    11fc <make_comm_schedule+0x9c>
mov    %r12,%rdi
mov    %r14d,%esi
call   1030 <free_comm_schedule@plt>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32** @make_comm_schedule(i32 %0) {
%2 = alloca i32**
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32**
store i32** %11, i32*** %4
%12 = load i32**, i32*** %4
%13 = icmp ne i32** %12, null
br i1 %13, label %15, label %14
14: ; preds = %1
store i32** null, i32*** %2
br label %76
15: ; preds = %1
store i32 0, i32* %5
br label %16
16: ; preds = %25, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32**, i32*** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32*, i32** %21, i64 %23
store i32* null, i32** %24
br label %25
25: ; preds = %20
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %16
28: ; preds = %16
store i32 0, i32* %5
br label %29
29: ; preds = %56, %28
%30 = load i32, i32* %5
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %59
33: ; preds = %29
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = mul i64 40, %36
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i32*
%41 = load i32**, i32*** %4
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32*, i32** %41, i64 %43
store i32* %40, i32** %44
%45 = load i32**, i32*** %4
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32*, i32** %45, i64 %47
%49 = load i32*, i32** %48
%50 = icmp ne i32* %49, null
br i1 %50, label %55, label %51
51: ; preds = %33
%52 = load i32**, i32*** %4
%53 = load i32, i32* %3
%54 = call i32 @free_comm_schedule(i32** %52, i32 %53)
store i32** null, i32*** %2
br label %76
55: ; preds = %33
br label %56
56: ; preds = %55
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %29
59: ; preds = %29
%60 = load i32**, i32*** %4
%61 = load i32, i32* %3
%62 = call i32 @empty_comm_schedule(i32** %60, i32 %61)
%63 = load i32**, i32*** %4
%64 = load i32, i32* %3
%65 = call i32 @fill_comm_schedule(i32** %63, i32 %64)
%66 = load i32**, i32*** %4
%67 = load i32, i32* %3
%68 = call i32 @check_comm_schedule(i32** %66, i32 %67)
%69 = icmp ne i32 %68, 0
br i1 %69, label %74, label %70
70: ; preds = %59
%71 = load i32**, i32*** %4
%72 = load i32, i32* %3
%73 = call i32 @free_comm_schedule(i32** %71, i32 %72)
store i32** null, i32*** %2
br label %76
74: ; preds = %59
%75 = load i32**, i32*** %4
store i32** %75, i32*** %2
br label %76
76: ; preds = %74, %70, %51, %14
%77 = load i32**, i32*** %2
ret i32** %77
}

LLVM IR (-O2):
define i32** @make_comm_schedule(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32**
%5 = inttoptr i64 %3 to i8*
%6 = icmp eq i64 %3, 0
br i1 %6, label %31, label %7
7: ; preds = %1
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %24
9: ; preds = %7
%10 = zext i32 %0 to i64
%11 = shl nuw nsw i64 %10, 3
%12 = mul i32 %0, 40
%13 = add i32 %12, 40
%14 = zext i32 %0 to i64
br label %17
15: ; preds = %17
%16 = icmp eq i64 %23, %14
br i1 %16, label %24, label %17
17: ; preds = %9, %15
%18 = phi i64 [ 0, %9 ], [ %23, %15 ]
%19 = tail call i64 @malloc(i32 %13)
%20 = inttoptr i64 %19 to i32*
%21 = getelementptr inbounds i32*, i32** %4, i64 %18
store i32* %20, i32** %21
%22 = icmp eq i64 %19, 0
%23 = add nuw nsw i64 %18, 1
br i1 %22, label %29, label %15
24: ; preds = %15, %7
%25 = tail call i32 @empty_comm_schedule(i32** %4, i32 %0)
%26 = tail call i32 @fill_comm_schedule(i32** %4, i32 %0)
%27 = tail call i32 @check_comm_schedule(i32** %4, i32 %0)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %17, %24
%30 = tail call i32 @free_comm_schedule(i32** %4, i32 %0)
br label %31
31: ; preds = %29, %24, %1
%32 = phi i32** [ null, %1 ], [ %4, %24 ], [ null, %29 ]
ret i32** %32
}