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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ memset(char *, int, int);
int readn(int, char *, int);
int recvMsg(int fd, void *vptr, int *n) {
  char head[10 + 1];
  char *ptr = vptr;
  memset(head, 0x00, sizeof(head));
  if ((readn(fd, head, sizeof(head))) != sizeof(head))
    return -1;
  *n = atoi(head);
  if ((readn(fd, ptr, *n)) != *n)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<recvMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x23(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x23(%rbp),%rsi
mov    $0xb,%edx
call   1040 <readn@plt>
cltq
cmp    $0xb,%rax
je     1184 <recvMsg+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <recvMsg+0x96>
lea    -0x23(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1040 <readn@plt>
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
je     11bf <recvMsg+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <recvMsg+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvMsg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xd(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1030 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xb,%edx
call   1040 <readn@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xb,%ecx
jne    1196 <recvMsg+0x66>
lea    0xd(%rsp),%rdi
call   1050 <atoi@plt>
mov    %eax,(%r15)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <readn@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    (%r15),%ecx
setne  %al
neg    %eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @recvMsg(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [11 x i8]
%9 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%10 = load i8*, i8** %6
store i8* %10, i8** %9
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 11)
%13 = load i32, i32* %5
%14 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%15 = call i32 @readn(i32 %13, i8* %14, i32 11)
%16 = sext i32 %15 to i64
%17 = icmp ne i64 %16, 11
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 -1, i32* %4
br label %33
19: ; preds = %3
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%21 = call i32 @atoi(i8* %20)
%22 = load i32*, i32** %7
store i32 %21, i32* %22
%23 = load i32, i32* %5
%24 = load i8*, i8** %9
%25 = load i32*, i32** %7
%26 = load i32, i32* %25
%27 = call i32 @readn(i32 %23, i8* %24, i32 %26)
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = icmp ne i32 %27, %29
br i1 %30, label %31, label %32
31: ; preds = %19
store i32 -1, i32* %4
br label %33
32: ; preds = %19
store i32 0, i32* %4
br label %33
33: ; preds = %32, %31, %18
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @recvMsg(i32 %0, i8* %1, i32* nocapture %2) {
%4 = alloca [11 x i8]
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 11)
%7 = call i32 @readn(i32 %0, i8* %5, i32 11)
%8 = icmp eq i32 %7, 11
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = call i32 @atoi(i8* %5)
store i32 %10, i32* %2
%11 = call i32 @readn(i32 %0, i8* %1, i32 %10)
%12 = load i32, i32* %2
%13 = icmp ne i32 %11, %12
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %9, %3
%16 = phi i32 [ -1, %3 ], [ %14, %9 ]
ret i32 %16
}