#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*/ comm_finalize();
int /*<<< orphan*/ comm_init(int /*<<< orphan*/);
int comm_rank();
int comm_size();
unsigned int luby_color(unsigned int, int *);
int /*<<< orphan*/ mpi_finalize();
int /*<<< orphan*/ mpi_init();
int /*<<< orphan*/ mpi_world();
int /*<<< orphan*/ print(char *, int, unsigned int);
int main() {
  unsigned nneigh;
  int neigh[2];
  unsigned color;
  mpi_init();
  comm_init(mpi_world());
  neigh[0] = (comm_rank() + (comm_size() - 1)) % comm_size();
  neigh[1] = (comm_rank() + 1) % comm_size();
  nneigh = (unsigned)(comm_size() - 1);
  nneigh = (((2) < (nneigh)) ? (2) : (nneigh));
  color = luby_color(nneigh, neigh);
  print("%d colored %d\n", comm_rank(), color);
  comm_finalize();
  mpi_finalize();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <mpi_init@plt>
mov    $0x0,%al
call   1060 <mpi_world@plt>
mov    %eax,%edi
call   1050 <comm_init@plt>
mov    $0x0,%al
call   1080 <comm_rank@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <comm_size@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <comm_size@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    $0x0,%al
call   1080 <comm_rank@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <comm_size@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1030 <comm_size@plt>
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jae    122b <main+0x9b>
mov    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    1231 <main+0xa1>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10b0 <luby_color@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1080 <comm_rank@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xda7(%rip),%rdi
call   1070 <print@plt>
mov    $0x0,%al
call   1090 <comm_finalize@plt>
mov    $0x0,%al
call   10a0 <mpi_finalize@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <mpi_init@plt>
xor    %eax,%eax
call   1060 <mpi_world@plt>
mov    %eax,%edi
call   1050 <comm_init@plt>
xor    %eax,%eax
call   1080 <comm_rank@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <comm_size@plt>
add    %eax,%ebx
add    $0xffffffff,%ebx
xor    %eax,%eax
call   1030 <comm_size@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %edx,0x8(%rsp)
xor    %eax,%eax
call   1080 <comm_rank@plt>
mov    %eax,%ebx
add    $0x1,%ebx
xor    %eax,%eax
call   1030 <comm_size@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %edx,0xc(%rsp)
xor    %eax,%eax
call   1030 <comm_size@plt>
add    $0xffffffff,%eax
cmp    $0x2,%eax
mov    $0x2,%edi
cmovb  %eax,%edi
lea    0x8(%rsp),%rsi
call   10b0 <luby_color@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <comm_rank@plt>
lea    0xde2(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1070 <print@plt>
xor    %eax,%eax
call   1090 <comm_finalize@plt>
xor    %eax,%eax
call   10a0 <mpi_finalize@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%d colored %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @mpi_init()
%6 = call i32 (...) @mpi_world()
%7 = call i32 @comm_init(i32 %6)
%8 = call i32 (...) @comm_rank()
%9 = call i32 (...) @comm_size()
%10 = sub nsw i32 %9, 1
%11 = add nsw i32 %8, %10
%12 = call i32 (...) @comm_size()
%13 = srem i32 %11, %12
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 %13, i32* %14
%15 = call i32 (...) @comm_rank()
%16 = add nsw i32 %15, 1
%17 = call i32 (...) @comm_size()
%18 = srem i32 %16, %17
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %18, i32* %19
%20 = call i32 (...) @comm_size()
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp ult i32 2, %22
br i1 %23, label %24, label %25
24: ; preds = %0
br label %27
25: ; preds = %0
%26 = load i32, i32* %2
br label %27
27: ; preds = %25, %24
%28 = phi i32 [ 2, %24 ], [ %26, %25 ]
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%31 = call i32 @luby_color(i32 %29, i32* %30)
store i32 %31, i32* %4
%32 = call i32 (...) @comm_rank()
%33 = load i32, i32* %4
%34 = call i32 @print(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %33)
%35 = call i32 (...) @comm_finalize()
%36 = call i32 (...) @mpi_finalize()
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"%d colored %d\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = tail call i32 (...) @mpi_init()
%4 = tail call i32 (...) @mpi_world()
%5 = tail call i32 @comm_init(i32 %4)
%6 = tail call i32 (...) @comm_rank()
%7 = tail call i32 (...) @comm_size()
%8 = add i32 %6, -1
%9 = add i32 %8, %7
%10 = tail call i32 (...) @comm_size()
%11 = srem i32 %9, %10
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
store i32 %11, i32* %12
%13 = tail call i32 (...) @comm_rank()
%14 = add nsw i32 %13, 1
%15 = tail call i32 (...) @comm_size()
%16 = srem i32 %14, %15
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
store i32 %16, i32* %17
%18 = tail call i32 (...) @comm_size()
%19 = add nsw i32 %18, -1
%20 = icmp ult i32 %19, 2
%21 = select i1 %20, i32 %19, i32 2
%22 = call i32 @luby_color(i32 %21, i32* %12)
%23 = call i32 (...) @comm_rank()
%24 = call i32 @print(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %22)
%25 = call i32 (...) @comm_finalize()
%26 = call i32 (...) @mpi_finalize()
ret i32 0
}