#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*/ uint8_t;
struct pollfd {
  int fd;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ POLLRDNORM;
scalar_t__ poll(struct pollfd *, int, int);
size_t recv(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t hw_recv(int session_id, int timeout, uint8_t buffer[],
               size_t buffer_len) {
  struct pollfd fd[1];
  fd[0].fd = session_id;
  fd[0].events = POLLRDNORM;
  return poll(fd, 1, timeout) ? recv(session_id, buffer, buffer_len, 0) : 0;
}


x86 assembly (clang, -O0):
<hw_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1040 <poll@plt>
cmp    $0x0,%rax
je     117e <hw_recv+0x5e>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x28(%rbp)
jmp    1189 <hw_recv+0x69>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    1189 <hw_recv+0x69>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hw_recv>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%edx
mov    %edi,%ebp
mov    %edi,0x8(%rsp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
call   1040 <poll@plt>
test   %rax,%rax
je     1168 <hw_recv+0x48>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
jmp    116a <hw_recv+0x4a>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@POLLRDNORM = global i32 0
define i64 @hw_recv(i32 %0, i32 %1, i32* %2, i64 %3) {
%5 = alloca [1 x %struct.pollfd]
%6 = bitcast [1 x %struct.pollfd]* %5 to i8*
%7 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0
%8 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 0
store i32 %0, i32* %8
%9 = load i32, i32* @POLLRDNORM
%10 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 1
store i32 %9, i32* %10
%11 = call i64 @poll(%struct.pollfd* %7, i32 1, i32 %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %4
%14 = call i64 @recv(i32 %0, i32* %2, i64 %3, i32 0)
br label %15
15: ; preds = %4, %13
%16 = phi i64 [ %14, %13 ], [ 0, %4 ]
ret i64 %16
}