#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 canRead(int);
int recv(int, char *, int, int /*<<< orphan*/);
int waitForRead(int, int /*<<< orphan*/ *);
int recvFromSock(int sockFd, char *buffer, int maxSize, int isBlock) {
  if (isBlock) {
    if (waitForRead(sockFd, NULL) != 1) {
      return -1;
    }
  } else {
    if (canRead(sockFd) != 1) {
      return -1;
    }
  }
  int recvLen = recv(sockFd, buffer, maxSize, 0);
  return recvLen;
}


x86 assembly (clang, -O0):
<recvFromSock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1175 <recvFromSock+0x45>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <waitForRead@plt>
cmp    $0x1,%eax
je     1170 <recvFromSock+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <recvFromSock+0x81>
jmp    1197 <recvFromSock+0x67>
mov    -0x8(%rbp),%edi
call   1040 <canRead@plt>
cmp    $0x1,%eax
je     1192 <recvFromSock+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <recvFromSock+0x81>
jmp    1197 <recvFromSock+0x67>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvFromSock>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
test   %ecx,%ecx
je     115f <recvFromSock+0x2f>
xor    %esi,%esi
call   1050 <waitForRead@plt>
cmp    $0x1,%eax
jne    1169 <recvFromSock+0x39>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <recv@plt>
call   1040 <canRead@plt>
cmp    $0x1,%eax
je     114c <recvFromSock+0x1c>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @recvFromSock(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %4
%14 = load i32, i32* %6
%15 = call i32 @waitForRead(i32 %14, i32* null)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %5
br label %31
18: ; preds = %13
br label %25
19: ; preds = %4
%20 = load i32, i32* %6
%21 = call i32 @canRead(i32 %20)
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %5
br label %31
24: ; preds = %19
br label %25
25: ; preds = %24, %18
%26 = load i32, i32* %6
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = call i32 @recv(i32 %26, i8* %27, i32 %28, i32 0)
store i32 %29, i32* %10
%30 = load i32, i32* %10
store i32 %30, i32* %5
br label %31
31: ; preds = %25, %23, %17
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @recvFromSock(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = tail call i32 @waitForRead(i32 %0, i32* null)
%8 = icmp eq i32 %7, 1
br i1 %8, label %12, label %14
9: ; preds = %4
%10 = tail call i32 @canRead(i32 %0)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9, %6
%13 = tail call i32 @recv(i32 %0, i8* %1, i32 %2, i32 0)
br label %14
14: ; preds = %9, %6, %12
%15 = phi i32 [ %13, %12 ], [ -1, %6 ], [ -1, %9 ]
ret i32 %15
}