#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_send_buffer_ex(int *, char *, int);
int lw_sock_send_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_send_buffer_ex(sock, buffer, len)) {
      result = 1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<lw_sock_send_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   1040 <get_ticker@plt>
add    $0x3a98,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <get_ticker@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1d(%rbp)
jle    1184 <lw_sock_send_buffer+0x64>
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jne    1184 <lw_sock_send_buffer+0x64>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
setge  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1194 <lw_sock_send_buffer+0x74>
jmp    11ba <lw_sock_send_buffer+0x9a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <lw_sock_send_buffer_ex@plt>
cmp    $0x0,%rax
je     11b5 <lw_sock_send_buffer+0x95>
movl   $0x1,-0x18(%rbp)
jmp    1149 <lw_sock_send_buffer+0x29>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lw_sock_send_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <get_ticker@plt>
mov    %eax,%r13d
add    $0x3a98,%r13d
xor    %eax,%eax
call   1040 <get_ticker@plt>
cmp    %eax,%r13d
jle    1192 <lw_sock_send_buffer+0x72>
cmpl   $0x0,0x0(%rbp)
js     1192 <lw_sock_send_buffer+0x72>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <lw_sock_send_buffer_ex@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <get_ticker@plt>
test   %rbx,%rbx
jne    1188 <lw_sock_send_buffer+0x68>
cmp    %eax,%r13d
jle    1188 <lw_sock_send_buffer+0x68>
cmpl   $0x0,0x0(%rbp)
jns    1160 <lw_sock_send_buffer+0x40>
xor    %r12d,%r12d
test   %rbx,%rbx
setne  %r12b
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lw_sock_send_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 = %31, %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 %32
24: ; preds = %22
%25 = load i32*, i32** %4
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = call i64 @lw_sock_send_buffer_ex(i32* %25, i8* %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 1, i32* %7
br label %31
31: ; preds = %30, %24
br label %11
32: ; preds = %22
%33 = load i32, i32* %7
ret i32 %33
}

LLVM IR (-O2):
define i32 @lw_sock_send_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 %22
8: ; preds = %3
%9 = load i32, i32* %0
%10 = icmp sgt i32 %9, -1
br i1 %10, label %14, label %22
11: ; preds = %14
%12 = load i32, i32* %0
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %8, %11
%15 = tail call i64 @lw_sock_send_buffer_ex(i32* %0, i8* %1, i32 %2)
%16 = icmp ne i64 %15, 0
%17 = tail call i32 (...) @get_ticker()
%18 = icmp sle i32 %5, %17
%19 = or i1 %16, %18
br i1 %19, label %20, label %11
20: ; preds = %14, %11
%21 = zext i1 %16 to i32
br label %22
22: ; preds = %8, %20, %3
%23 = phi i32 [ 0, %3 ], [ 0, %8 ], [ %21, %20 ]
ret i32 %23
}