#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 get_ticker();
scalar_t__ lw_sock_peek_ex(int *, int);
scalar_t__ lw_sock_recv_buffer_ex(int *, char *, int);
int lw_sock_recv_buffer(int *sock, char *buffer, int len) {
  int result = 0;
  int limit_ticker;
  limit_ticker = get_ticker() + 15000;
  while (limit_ticker > get_ticker() && !result && *sock >= 0) {
    if (lw_sock_peek_ex(sock, len)) {
      if (lw_sock_recv_buffer_ex(sock, buffer, len)) {
        result = 1;
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<lw_sock_recv_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <get_ticker@plt>
add    $0x3a98,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <get_ticker@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1d(%rbp)
jle    1194 <lw_sock_recv_buffer+0x64>
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jne    1194 <lw_sock_recv_buffer+0x64>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
setge  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a4 <lw_sock_recv_buffer+0x74>
jmp    11e5 <lw_sock_recv_buffer+0xb5>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <lw_sock_peek_ex@plt>
cmp    $0x0,%rax
je     11e0 <lw_sock_recv_buffer+0xb0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <lw_sock_recv_buffer_ex@plt>
cmp    $0x0,%rax
je     11db <lw_sock_recv_buffer+0xab>
movl   $0x1,-0x18(%rbp)
jmp    11e0 <lw_sock_recv_buffer+0xb0>
jmp    1159 <lw_sock_recv_buffer+0x29>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lw_sock_recv_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <get_ticker@plt>
mov    %eax,%r15d
add    $0x3a98,%r15d
xor    %eax,%eax
call   1050 <get_ticker@plt>
jmp    1182 <lw_sock_recv_buffer+0x52>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <lw_sock_recv_buffer_ex@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
xor    %eax,%eax
call   1050 <get_ticker@plt>
test   %ebp,%ebp
jne    11a2 <lw_sock_recv_buffer+0x72>
cmp    %eax,%r15d
jle    11a2 <lw_sock_recv_buffer+0x72>
cmpl   $0x0,(%rbx)
js     11a0 <lw_sock_recv_buffer+0x70>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <lw_sock_peek_ex@plt>
test   %rax,%rax
jne    1160 <lw_sock_recv_buffer+0x30>
xor    %ebp,%ebp
jmp    1177 <lw_sock_recv_buffer+0x47>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lw_sock_recv_buffer(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = call i32 (...) @get_ticker()
%10 = add nsw i32 %9, 15000
store i32 %10, i32* %8
br label %11
11: ; preds = %37, %3
%12 = load i32, i32* %8
%13 = call i32 (...) @get_ticker()
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = icmp sge i32 %20, 0
br label %22
22: ; preds = %18, %15, %11
%23 = phi i1 [ false, %15 ], [ false, %11 ], [ %21, %18 ]
br i1 %23, label %24, label %38
24: ; preds = %22
%25 = load i32*, i32** %4
%26 = load i32, i32* %6
%27 = call i64 @lw_sock_peek_ex(i32* %25, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = load i32*, i32** %4
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = call i64 @lw_sock_recv_buffer_ex(i32* %30, i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 1, i32* %7
br label %36
36: ; preds = %35, %29
br label %37
37: ; preds = %36, %24
br label %11
38: ; preds = %22
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
define i32 @lw_sock_recv_buffer(i32* %0, i8* %1, i32 %2) {
%4 = tail call i32 (...) @get_ticker()
%5 = add nsw i32 %4, 15000
%6 = tail call i32 (...) @get_ticker()
%7 = icmp sgt i32 %5, %6
br i1 %7, label %8, label %24
8: ; preds = %3, %18
%9 = load i32, i32* %0
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = tail call i64 @lw_sock_peek_ex(i32* %0, i32 %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = tail call i64 @lw_sock_recv_buffer_ex(i32* %0, i8* %1, i32 %2)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %14, %11
%19 = phi i32 [ 0, %11 ], [ %17, %14 ]
%20 = tail call i32 (...) @get_ticker()
%21 = icmp sle i32 %5, %20
%22 = icmp ne i32 %19, 0
%23 = or i1 %22, %21
br i1 %23, label %24, label %8
24: ; preds = %8, %18, %3
%25 = phi i32 [ 0, %3 ], [ %19, %18 ], [ 0, %8 ]
ret i32 %25
}