#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 */
struct sockaddr_in {
  int dummy;
};
struct ringbuffer {
  int dummy;
};
typedef scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ drain_cached_bytes(struct ringbuffer *, int /*<<< orphan*/ *,
                              scalar_t__, int, struct sockaddr_in *);
int32_t rb_sendto(int fd, struct ringbuffer *rb, int32_t size,
                  struct sockaddr_in *peer) {
  if (!rb || size <= 0 || !peer) {
    return -1;
  }
  return drain_cached_bytes(rb, NULL, size, fd, peer);
}


x86 assembly (clang, -O0):
<rb_sendto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1148 <rb_sendto+0x38>
cmpq   $0x0,-0x20(%rbp)
jle    1148 <rb_sendto+0x38>
cmpq   $0x0,-0x28(%rbp)
jne    1155 <rb_sendto+0x45>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1171 <rb_sendto+0x61>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%r8
xor    %eax,%eax
mov    %eax,%esi
call   1030 <drain_cached_bytes@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rb_sendto>:
test   %rsi,%rsi
je     112e <rb_sendto+0x1e>
test   %rdx,%rdx
jle    112e <rb_sendto+0x1e>
mov    %rcx,%r8
test   %rcx,%rcx
je     112e <rb_sendto+0x1e>
mov    %edi,%ecx
mov    %rsi,%rdi
xor    %esi,%esi
jmp    1030 <drain_cached_bytes@plt>
mov    $0xffffffffffffffff,%rax
ret

LLVM IR (-O0):
%struct.ringbuffer = type { i32 }
%struct.sockaddr_in = type { i32 }
define i64 @rb_sendto(i32 %0, %struct.ringbuffer* %1, i64 %2, %struct.sockaddr_in* %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.ringbuffer*
%8 = alloca i64
%9 = alloca %struct.sockaddr_in*
store i32 %0, i32* %6
store %struct.ringbuffer* %1, %struct.ringbuffer** %7
store i64 %2, i64* %8
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %9
%10 = load %struct.ringbuffer*, %struct.ringbuffer** %7
%11 = icmp ne %struct.ringbuffer* %10, null
br i1 %11, label %12, label %18
12: ; preds = %4
%13 = load i64, i64* %8
%14 = icmp sle i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%17 = icmp ne %struct.sockaddr_in* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15, %12, %4
store i64 -1, i64* %5
br label %25
19: ; preds = %15
%20 = load %struct.ringbuffer*, %struct.ringbuffer** %7
%21 = load i64, i64* %8
%22 = load i32, i32* %6
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%24 = call i64 @drain_cached_bytes(%struct.ringbuffer* %20, i32* null, i64 %21, i32 %22, %struct.sockaddr_in* %23)
store i64 %24, i64* %5
br label %25
25: ; preds = %19, %18
%26 = load i64, i64* %5
ret i64 %26
}

LLVM IR (-O2):
%struct.ringbuffer = type { i32 }
%struct.sockaddr_in = type { i32 }
define i64 @rb_sendto(i32 %0, %struct.ringbuffer* %1, i64 %2, %struct.sockaddr_in* %3) {
%5 = icmp ne %struct.ringbuffer* %1, null
%6 = icmp sgt i64 %2, 0
%7 = and i1 %5, %6
%8 = icmp ne %struct.sockaddr_in* %3, null
%9 = and i1 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i64 @drain_cached_bytes(%struct.ringbuffer* %1, i32* null, i64 %2, i32 %0, %struct.sockaddr_in* %3)
br label %12
12: ; preds = %4, %10
%13 = phi i64 [ %11, %10 ], [ -1, %4 ]
ret i64 %13
}