#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*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ mympi_init(int, char **, int *, int *, int *);
int /*<<< orphan*/ mympi_recv(char *, int, int /*<<< orphan*/, int, int, int *);
int /*<<< orphan*/ mympi_send(char *, int, int, int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ printf(char *, int, char *);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Insufficient arguents, Reveived %d argument(s). Usage %s <rank> "
           "<n_proc>\n",
           argc - 1, argv[0]);
    exit(0);
  }
  char *msg;
  msg = (char *)malloc(sizeof(char) * 16);
  memset(msg, 'a', sizeof(char) * 16);
  int rank, numproc;
  int *handle = (int)malloc(sizeof(int));
  int *status = (int)malloc(sizeof(int));
  mympi_init(argc, argv, &rank, &numproc, handle);
  char *recvd = (char *)malloc(sizeof(char));
  if (rank == 0) {
    mympi_send(msg, 1, 1, 0, *(handle + rank), status);
  } else {
    mympi_recv(recvd, 1, 0, rank, *(handle + rank), status);
    printf("Rank:%d: Msg:%s\n", rank, recvd);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b0 <main+0x40>
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x61,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    $0x4,%edi
call   1060 <malloc@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%r8
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1030 <mympi_init@plt>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1248 <main+0xd8>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%r8d
mov    -0x30(%rbp),%r9
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %edx,%esi
call   1070 <mympi_send@plt>
jmp    127e <main+0x10e>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rdx
mov    (%rax,%rdx,4),%r8d
mov    -0x30(%rbp),%r9
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <mympi_recv@plt>
mov    -0x1c(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xdd1(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
cmp    $0x2,%edi
jle    1245 <main+0xd5>
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x61,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    $0x4,%edi
call   1060 <malloc@plt>
movslq %eax,%rbx
mov    $0x4,%edi
call   1060 <malloc@plt>
movslq %eax,%r14
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%r8
call   1030 <mympi_init@plt>
mov    $0x1,%edi
call   1060 <malloc@plt>
movslq 0x8(%rsp),%rcx
test   %rcx,%rcx
je     121c <main+0xac>
mov    %rax,%rbp
mov    (%rbx,%rcx,4),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    %r14,%r9
call   1080 <mympi_recv@plt>
mov    0x8(%rsp),%esi
lea    0xe38(%rip),%rdi
mov    %rbp,%rdx
call   1040 <printf@plt>
jmp    1236 <main+0xc6>
mov    (%rbx),%r8d
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r9
call   1070 <mympi_send@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%ebp
mov    (%r15),%rdx
lea    0xdae(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [74 x i8] c"Insufficient arguents, Reveived %d argument(s). Usage %s <rank> <n_proc>\0A\00"
@.str.1 = [17 x i8] c"Rank:%d: Msg:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = call i64 @malloc(i32 16)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = call i32 @memset(i8* %25, i8 signext 97, i32 16)
%27 = call i64 @malloc(i32 4)
%28 = trunc i64 %27 to i32
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %9
%31 = call i64 @malloc(i32 4)
%32 = trunc i64 %31 to i32
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i32*
store i32* %34, i32** %10
%35 = load i32, i32* %4
%36 = load i8**, i8*** %5
%37 = load i32*, i32** %9
%38 = call i32 @mympi_init(i32 %35, i8** %36, i32* %7, i32* %8, i32* %37)
%39 = call i64 @malloc(i32 1)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %11
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %22
%44 = load i8*, i8** %6
%45 = load i32*, i32** %9
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
%50 = load i32*, i32** %10
%51 = call i32 @mympi_send(i8* %44, i32 1, i32 1, i32 0, i32 %49, i32* %50)
br label %65
52: ; preds = %22
%53 = load i8*, i8** %11
%54 = load i32, i32* %7
%55 = load i32*, i32** %9
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %58
%60 = load i32*, i32** %10
%61 = call i32 @mympi_recv(i8* %53, i32 1, i32 0, i32 %54, i32 %59, i32* %60)
%62 = load i32, i32* %7
%63 = load i8*, i8** %11
%64 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %62, i8* %63)
br label %65
65: ; preds = %52, %43
ret i32 0
}

LLVM IR (-O2):
@.str = [74 x i8] c"Insufficient arguents, Reveived %d argument(s). Usage %s <rank> <n_proc>\0A\00"
@.str.1 = [17 x i8] c"Rank:%d: Msg:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = add nsw i32 %0, -1
%8 = load i8*, i8** %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %8)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = tail call i64 @malloc(i32 16)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @memset(i8* %13, i8 signext 97, i32 16)
%15 = bitcast i32* %3 to i8*
%16 = bitcast i32* %4 to i8*
%17 = tail call i64 @malloc(i32 4)
%18 = shl i64 %17, 32
%19 = ashr exact i64 %18, 32
%20 = inttoptr i64 %19 to i32*
%21 = tail call i64 @malloc(i32 4)
%22 = shl i64 %21, 32
%23 = ashr exact i64 %22, 32
%24 = inttoptr i64 %23 to i32*
%25 = call i32 @mympi_init(i32 %0, i8** %1, i32* %3, i32* %4, i32* %20)
%26 = call i64 @malloc(i32 1)
%27 = inttoptr i64 %26 to i8*
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %11
%31 = load i32, i32* %20
%32 = call i32 @mympi_send(i8* %13, i32 1, i32 1, i32 0, i32 %31, i32* %24)
br label %40
33: ; preds = %11
%34 = sext i32 %28 to i64
%35 = getelementptr inbounds i32, i32* %20, i64 %34
%36 = load i32, i32* %35
%37 = call i32 @mympi_recv(i8* %27, i32 1, i32 0, i32 %28, i32 %36, i32* %24)
%38 = load i32, i32* %3
%39 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %27)
br label %40
40: ; preds = %33, %30
ret i32 0
}