#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 wby_con {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ wby_read(struct wby_con *, char *, unsigned long);
int wby_con_discard_incoming_data(struct wby_con *conn, int count) {
  while (count > 0) {
    char buffer[1024];
    int read_size =
        (int)(((unsigned long)count > sizeof(buffer)) ? sizeof(buffer)
                                                      : (unsigned long)count);
    if (wby_read(conn, buffer, (unsigned long)read_size) != (0))
      return -1;
    count -= read_size;
  }
  return 0;
}


x86 assembly (clang, -O0):
<wby_con_discard_incoming_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11a4 <wby_con_discard_incoming_data+0x94>
movslq -0x14(%rbp),%rax
cmp    $0x400,%rax
jbe    114d <wby_con_discard_incoming_data+0x3d>
mov    $0x400,%eax
mov    %rax,-0x430(%rbp)
jmp    1158 <wby_con_discard_incoming_data+0x48>
movslq -0x14(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
movslq -0x424(%rbp),%rdx
call   1030 <wby_read@plt>
cmp    $0x0,%eax
je     1191 <wby_con_discard_incoming_data+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <wby_con_discard_incoming_data+0x9b>
mov    -0x424(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1122 <wby_con_discard_incoming_data+0x12>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wby_con_discard_incoming_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
test   %ebx,%ebx
jle    1160 <wby_con_discard_incoming_data+0x50>
cmp    $0x400,%ebx
mov    $0x400,%r12d
cmovb  %ebx,%r12d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <wby_read@plt>
sub    %r12d,%ebx
test   %eax,%eax
je     1130 <wby_con_discard_incoming_data+0x20>
mov    $0xffffffff,%eax
jmp    1162 <wby_con_discard_incoming_data+0x52>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.wby_con = type { i32 }
define i32 @wby_con_discard_incoming_data(%struct.wby_con* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.wby_con*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
store %struct.wby_con* %0, %struct.wby_con** %4
store i32 %1, i32* %5
br label %8
8: ; preds = %29, %2
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = icmp ugt i64 %13, 1024
br i1 %14, label %15, label %16
15: ; preds = %11
br label %19
16: ; preds = %11
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
br label %19
19: ; preds = %16, %15
%20 = phi i64 [ 1024, %15 ], [ %18, %16 ]
%21 = trunc i64 %20 to i32
store i32 %21, i32* %7
%22 = load %struct.wby_con*, %struct.wby_con** %4
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = call i32 @wby_read(%struct.wby_con* %22, i8* %23, i64 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %19
store i32 -1, i32* %3
br label %34
29: ; preds = %19
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, %30
store i32 %32, i32* %5
br label %8
33: ; preds = %8
store i32 0, i32* %3
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.wby_con = type { i32 }
define i32 @wby_con_discard_incoming_data(%struct.wby_con* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %8, %2
%6 = phi i32 [ %1, %2 ], [ %14, %8 ]
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = icmp ult i32 %6, 1024
%10 = select i1 %9, i32 %6, i32 1024
%11 = zext i32 %10 to i64
%12 = call i32 @wby_read(%struct.wby_con* %0, i8* %4, i64 %11)
%13 = icmp eq i32 %12, 0
%14 = sub nsw i32 %6, %10
br i1 %13, label %5, label %15
15: ; preds = %8, %5
%16 = phi i32 [ -1, %8 ], [ 0, %5 ]
ret i32 %16
}