#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int main() {
  char buffer[80];
  int rc;
  while (rc = recv(3, buffer, sizeof(buffer), 0)) {
    printf("child received: %s", buffer);
    send(3, buffer, rc, 0);
    memset(buffer, 0, sizeof(buffer));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rsi
mov    $0x3,%edi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
je     11a8 <main+0x68>
lea    -0x60(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
mov    $0x3,%edi
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
jmp    114f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsp,%rsi
mov    $0x3,%edi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     11b5 <main+0x75>
mov    %eax,%ebp
lea    0xe97(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0x3,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
mov    $0x3,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1170 <main+0x30>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"child received: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %8, %0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = call i32 @recv(i32 3, i8* %5, i32 80, i32 0)
store i32 %6, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = load i32, i32* %3
%13 = call i32 @send(i32 3, i8* %11, i32 %12, i32 0)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 80)
br label %4
16: ; preds = %4
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [19 x i8] c"child received: %s\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = call i32 @recv(i32 3, i8* %2, i32 80, i32 0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %10, %5 ], [ %3, %0 ]
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = call i32 @send(i32 3, i8* %2, i32 %6, i32 0)
%9 = call i32 @memset(i8* %2, i32 0, i32 80)
%10 = call i32 @recv(i32 3, i8* %2, i32 80, i32 0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %5
12: ; preds = %5, %0
ret i32 0
}