#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ MSG_PEEK;
unsigned int O_NONBLOCK;
unsigned int fcntl(int, int /*<<< orphan*/, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int so_recvtest(int fd) {
  char buf;
  int i;
  unsigned int flags;
  flags = fcntl(fd, F_GETFL);
  fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  i = recv(fd, &buf, 1, MSG_PEEK);
  fcntl(fd, F_SETFL, flags);
  return i;
}


x86 assembly (clang, -O0):
<so_recvtest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    0x2e91(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0x4(%rbp),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%ecx
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <recv@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<so_recvtest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    %eax,%r14d
mov    0x2e8d(%rip),%r15
mov    (%r15),%esi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
or     %r14d,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%ecx
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <recv@plt>
mov    %eax,%ebp
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@MSG_PEEK = global i32 0
define i32 @so_recvtest(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* @F_GETFL
%8 = call i32 (i32, i32, ...) @fcntl(i32 %6, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %2
%10 = load i32, i32* @F_SETFL
%11 = load i32, i32* %5
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %11, %12
%14 = call i32 (i32, i32, ...) @fcntl(i32 %9, i32 %10, i32 %13)
%15 = load i32, i32* %2
%16 = load i32, i32* @MSG_PEEK
%17 = call i32 @recv(i32 %15, i8* %3, i32 1, i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %2
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* %5
%21 = call i32 (i32, i32, ...) @fcntl(i32 %18, i32 %19, i32 %20)
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@MSG_PEEK = global i32 0
define i32 @so_recvtest(i32 %0) {
%2 = alloca i8
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %3)
%5 = load i32, i32* @F_SETFL
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %4
%8 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %5, i32 %7)
%9 = load i32, i32* @MSG_PEEK
%10 = call i32 @recv(i32 %0, i8* %2, i32 1, i32 %9)
%11 = load i32, i32* @F_SETFL
%12 = call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %11, i32 %4)
ret i32 %10
}