#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 WebbyConnection {
  int dummy;
};

/* Variables and functions */
scalar_t__ WebbyRead(struct WebbyConnection *, char *, size_t);
int discard_incoming_data(struct WebbyConnection *conn, int count) {
  while (count > 0) {
    char buffer[1024];
    int read_size = count > (int)sizeof buffer ? (int)sizeof buffer : count;
    if (0 != WebbyRead(conn, buffer, (size_t)read_size))
      return -1;
    count -= read_size;
  }
  return 0;
}


x86 assembly (clang, -O0):
<discard_incoming_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11a2 <discard_incoming_data+0x92>
cmpl   $0x400,-0x14(%rbp)
jle    1149 <discard_incoming_data+0x39>
mov    $0x400,%eax
mov    %eax,-0x428(%rbp)
jmp    1152 <discard_incoming_data+0x42>
mov    -0x14(%rbp),%eax
mov    %eax,-0x428(%rbp)
mov    -0x428(%rbp),%eax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
movslq -0x424(%rbp),%rdx
call   1030 <WebbyRead@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     118f <discard_incoming_data+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <discard_incoming_data+0x99>
mov    -0x424(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1122 <discard_incoming_data+0x12>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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    1161 <discard_incoming_data+0x51>
cmp    $0x400,%ebx
mov    $0x400,%r12d
cmovb  %ebx,%r12d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <WebbyRead@plt>
sub    %r12d,%ebx
test   %rax,%rax
je     1130 <discard_incoming_data+0x20>
mov    $0xffffffff,%eax
jmp    1163 <discard_incoming_data+0x53>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.WebbyConnection = type { i32 }
define i32 @discard_incoming_data(%struct.WebbyConnection* %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 i64 @WebbyRead(%struct.WebbyConnection* %0, i8* %4, i64 %11)
%13 = icmp eq i64 %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
}