#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*/ msg;

/* Variables and functions */
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
size_t recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
size_t write(int /*<<< orphan*/, char *, size_t);
int admin_receive(int fd) {
  char msg[512];
  size_t len;
  while ((len = recv(fd, msg, sizeof(msg), 0)) > 0) {
    if (write(fileno(stdout), msg, len) != len)
      return -1;
  }
  if (len < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<admin_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jbe    11a6 <admin_receive+0x76>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
lea    -0x210(%rbp),%rsi
mov    -0x218(%rbp),%rdx
call   1040 <write@plt>
cmp    -0x218(%rbp),%rax
je     11a1 <admin_receive+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <admin_receive+0x97>
jmp    113e <admin_receive+0xe>
cmpq   $0x0,-0x218(%rbp)
jae    11c0 <admin_receive+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <admin_receive+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<admin_receive>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %edi,%r15d
mov    %rsp,%r14
mov    0x2e94(%rip),%r12
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     118a <admin_receive+0x5a>
mov    %rax,%rbx
mov    (%r12),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <write@plt>
cmp    %rbx,%rax
je     1150 <admin_receive+0x20>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @admin_receive(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = alloca i64
store i32 %0, i32* %3
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %3
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = call i64 @recv(i32 %7, i8* %8, i32 512, i32 0)
store i64 %9, i64* %5
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = load i32, i32* @stdout
%13 = call i32 @fileno(i32 %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%15 = load i64, i64* %5
%16 = call i64 @write(i32 %13, i8* %14, i64 %15)
%17 = load i64, i64* %5
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 -1, i32* %2
br label %26
20: ; preds = %11
br label %6
21: ; preds = %6
%22 = load i64, i64* %5
%23 = icmp ult i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 -1, i32* %2
br label %26
25: ; preds = %21
store i32 0, i32* %2
br label %26
26: ; preds = %25, %24, %19
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @admin_receive(i32 %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %7, %1
%5 = call i64 @recv(i32 %0, i8* %3, i32 512, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = load i32, i32* @stdout
%9 = call i32 @fileno(i32 %8)
%10 = call i64 @write(i32 %9, i8* %3, i64 %5)
%11 = icmp eq i64 %10, %5
br i1 %11, label %4, label %12
12: ; preds = %4, %7
%13 = phi i32 [ -1, %7 ], [ 0, %4 ]
ret i32 %13
}