#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*/ free(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ receive(void **, int *);
int self();
int /*<<< orphan*/ usleep(int);
void fun2() {
  char *data = NULL;
  int size;
  printf("process %d start\n", self());
  while (1) {
    usleep(100);
    printf("process %d execution\n", self());
    receive((void **)&data, &size);
    printf("process %d got: %s (%d)\n", self(), data, size);
    free(data);
    data = NULL;
  }
}


x86 assembly (clang, -O0):
<fun2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1060 <self@plt>
mov    %eax,%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x64,%edi
call   1070 <usleep@plt>
mov    $0x0,%al
call   1060 <self@plt>
mov    %eax,%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <receive@plt>
mov    $0x0,%al
call   1060 <self@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1177 <fun2+0x27>

x86 assembly (clang, -O2):
<fun2>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1060 <self@plt>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe90(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x14(%rsp),%r12
lea    0xe95(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x64,%edi
call   1070 <usleep@plt>
xor    %eax,%eax
call   1060 <self@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <receive@plt>
xor    %eax,%eax
call   1060 <self@plt>
mov    0x8(%rsp),%rdx
mov    0x14(%rsp),%ecx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
movq   $0x0,0x8(%rsp)
jmp    11a0 <fun2+0x50>

LLVM IR (-O0):
@.str = [18 x i8] c"process %d start\0A\00"
@.str.1 = [22 x i8] c"process %d execution\0A\00"
@.str.2 = [25 x i8] c"process %d got: %s (%d)\0A\00"
define void @fun2() {
%1 = alloca i8*
%2 = alloca i32
store i8* null, i8** %1
%3 = call i32 (...) @self()
%4 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %5
5: ; preds = %0, %5
%6 = call i32 @usleep(i32 100)
%7 = call i32 (...) @self()
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 @receive(i8** %1, i32* %2)
%10 = call i32 (...) @self()
%11 = load i8*, i8** %1
%12 = load i32, i32* %2
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %10, i8* %11, i32 %12)
%14 = load i8*, i8** %1
%15 = call i32 @free(i8* %14)
store i8* null, i8** %1
br label %5
}

LLVM IR (-O2):
@.str = [18 x i8] c"process %d start\0A\00"
@.str.1 = [22 x i8] c"process %d execution\0A\00"
@.str.2 = [25 x i8] c"process %d got: %s (%d)\0A\00"
define void @fun2() {
%1 = alloca i8*
%2 = alloca i32
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (...) @self()
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %7, %0
%8 = call i32 @usleep(i32 100)
%9 = call i32 (...) @self()
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @receive(i8** %1, i32* %2)
%12 = call i32 (...) @self()
%13 = load i8*, i8** %1
%14 = load i32, i32* %2
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %13, i32 %14)
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
store i8* null, i8** %1
br label %7
}