#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_exch();
int /*<<< orphan*/ comm_finalize();
int /*<<< orphan*/ comm_from();
int /*<<< orphan*/ comm_init(int /*<<< orphan*/);
int /*<<< orphan*/ comm_pack(char const *, int, int);
scalar_t__ comm_rank();
scalar_t__ comm_recv();
int /*<<< orphan*/ comm_size();
int /*<<< orphan*/ comm_unpack(char *, int);
int /*<<< orphan*/ mpi_finalize();
int /*<<< orphan*/ mpi_init();
int /*<<< orphan*/ mpi_world();
int /*<<< orphan*/ print(char *, scalar_t__, ...);
int main() {
  const char *out0 = "one";
  const char *out1 = "two";
  char in[4];
  mpi_init();
  comm_init(mpi_world());
  print("yo, rank %d here\n", comm_rank());
  print("rep'n all %d of the world\n", comm_size());
  if (comm_rank() == 0)
    comm_pack(out0, 4, 1);
  else
    comm_pack(out1, 4, 0);
  comm_exch();
  while (comm_recv()) {
    comm_unpack(in, 4);
    print("%d got \"%s\" from %d\n", comm_rank(), in, comm_from());
  }
  comm_finalize();
  mpi_finalize();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe1a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe13(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <mpi_init@plt>
mov    $0x0,%al
call   1070 <mpi_world@plt>
mov    %eax,%edi
call   1060 <comm_init@plt>
mov    $0x0,%al
call   1090 <comm_rank@plt>
mov    %rax,%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1080 <print@plt>
mov    $0x0,%al
call   1030 <comm_size@plt>
movslq %eax,%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1080 <print@plt>
mov    $0x0,%al
call   1090 <comm_rank@plt>
cmp    $0x0,%rax
jne    1263 <main+0x93>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10c0 <comm_pack@plt>
jmp    1273 <main+0xa3>
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
xor    %edx,%edx
call   10c0 <comm_pack@plt>
mov    $0x0,%al
call   10f0 <comm_exch@plt>
mov    $0x0,%al
call   1050 <comm_recv@plt>
cmp    $0x0,%rax
je     12d0 <main+0x100>
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
call   10d0 <comm_unpack@plt>
mov    $0x0,%al
call   1090 <comm_rank@plt>
mov    %rax,-0x30(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10e0 <comm_from@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %eax,%ecx
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1080 <print@plt>
jmp    127a <main+0xaa>
mov    $0x0,%al
call   10a0 <comm_finalize@plt>
mov    $0x0,%al
call   10b0 <mpi_finalize@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <mpi_init@plt>
xor    %eax,%eax
call   1070 <mpi_world@plt>
mov    %eax,%edi
call   1060 <comm_init@plt>
xor    %eax,%eax
call   1090 <comm_rank@plt>
lea    0xe0c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <print@plt>
xor    %eax,%eax
call   1030 <comm_size@plt>
movslq %eax,%rsi
lea    0xe03(%rip),%rdi
xor    %eax,%eax
call   1080 <print@plt>
xor    %eax,%eax
call   1090 <comm_rank@plt>
test   %rax,%rax
je     123a <main+0x6a>
lea    0xdd3(%rip),%rdi
mov    $0x4,%esi
xor    %edx,%edx
jmp    124b <main+0x7b>
lea    0xdbf(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10c0 <comm_pack@plt>
xor    %eax,%eax
call   10f0 <comm_exch@plt>
xor    %eax,%eax
call   1050 <comm_recv@plt>
test   %rax,%rax
je     12ac <main+0xdc>
lea    0xc(%rsp),%r15
lea    0xdc6(%rip),%r14
nop
mov    %r15,%rdi
mov    $0x4,%esi
call   10d0 <comm_unpack@plt>
xor    %eax,%eax
call   1090 <comm_rank@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10e0 <comm_from@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <print@plt>
xor    %eax,%eax
call   1050 <comm_recv@plt>
test   %rax,%rax
jne    1270 <main+0xa0>
xor    %eax,%eax
call   10a0 <comm_finalize@plt>
xor    %eax,%eax
call   10b0 <mpi_finalize@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"one\00"
@.str.1 = [4 x i8] c"two\00"
@.str.2 = [18 x i8] c"yo, rank %d here\0A\00"
@.str.3 = [27 x i8] c"rep'n all %d of the world\0A\00"
@.str.4 = [21 x i8] c"%d got \22%s\22 from %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [4 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %3
%5 = call i32 (...) @mpi_init()
%6 = call i32 (...) @mpi_world()
%7 = call i32 @comm_init(i32 %6)
%8 = call i64 (...) @comm_rank()
%9 = call i32 (i8*, i64, ...) @print(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %8)
%10 = call i32 (...) @comm_size()
%11 = sext i32 %10 to i64
%12 = call i32 (i8*, i64, ...) @print(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i64 %11)
%13 = call i64 (...) @comm_rank()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = call i32 @comm_pack(i8* %16, i32 4, i32 1)
br label %21
18: ; preds = %0
%19 = load i8*, i8** %3
%20 = call i32 @comm_pack(i8* %19, i32 4, i32 0)
br label %21
21: ; preds = %18, %15
%22 = call i32 (...) @comm_exch()
br label %23
23: ; preds = %26, %21
%24 = call i64 (...) @comm_recv()
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%28 = call i32 @comm_unpack(i8* %27, i32 4)
%29 = call i64 (...) @comm_rank()
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%31 = call i32 (...) @comm_from()
%32 = call i32 (i8*, i64, ...) @print(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %29, i8* %30, i32 %31)
br label %23
33: ; preds = %23
%34 = call i32 (...) @comm_finalize()
%35 = call i32 (...) @mpi_finalize()
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"one\00"
@.str.1 = [4 x i8] c"two\00"
@.str.2 = [18 x i8] c"yo, rank %d here\0A\00"
@.str.3 = [27 x i8] c"rep'n all %d of the world\0A\00"
@.str.4 = [21 x i8] c"%d got \22%s\22 from %d\0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @mpi_init()
%4 = tail call i32 (...) @mpi_world()
%5 = tail call i32 @comm_init(i32 %4)
%6 = tail call i64 (...) @comm_rank()
%7 = tail call i32 (i8*, i64, ...) @print(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %6)
%8 = tail call i32 (...) @comm_size()
%9 = sext i32 %8 to i64
%10 = tail call i32 (i8*, i64, ...) @print(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i64 %9)
%11 = tail call i64 (...) @comm_rank()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @comm_pack(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4, i32 1)
br label %17
15: ; preds = %0
%16 = tail call i32 @comm_pack(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 0)
br label %17
17: ; preds = %15, %13
%18 = tail call i32 (...) @comm_exch()
%19 = call i64 (...) @comm_recv()
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %17, %21
%22 = call i32 @comm_unpack(i8* %2, i32 4)
%23 = call i64 (...) @comm_rank()
%24 = call i32 (...) @comm_from()
%25 = call i32 (i8*, i64, ...) @print(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %23, i8* %2, i32 %24)
%26 = call i64 (...) @comm_recv()
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %21
28: ; preds = %21, %17
%29 = call i32 (...) @comm_finalize()
%30 = call i32 (...) @mpi_finalize()
ret i32 0
}