#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int sock_recv(int, char *, int, int, char *, int);
int /*<<< orphan*/ stderr;
int sock_discard(int sock, int size, char *errbuf, int errbuflen) {
  char buffer[32768];
  while (size > 32768) {
    if (sock_recv(sock, buffer, 32768, 1, errbuf, errbuflen) == -1)
      return -1;
    size -= 32768;
  }
  if (size) {
    if (sock_recv(sock, buffer, size, 1, errbuf, errbuflen) == -1)
      return -1;
  }
  {
    fprintf(stderr, "%s\n", "I'm currently discarding data\n");
    assert(1);
  };
  return 0;
}


x86 assembly (clang, -O0):
<sock_discard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8020,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x8000,-0xc(%rbp)
jle    119b <sock_discard+0x6b>
mov    -0x8(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
mov    $0x8000,%edx
mov    $0x1,%ecx
call   1050 <sock_recv@plt>
cmp    $0xffffffff,%eax
jne    118b <sock_discard+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <sock_discard+0xdb>
mov    -0xc(%rbp),%eax
sub    $0x8000,%eax
mov    %eax,-0xc(%rbp)
jmp    1148 <sock_discard+0x18>
cmpl   $0x0,-0xc(%rbp)
je     11de <sock_discard+0xae>
mov    -0x8(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
mov    $0x1,%ecx
call   1050 <sock_recv@plt>
cmp    $0xffffffff,%eax
jne    11d9 <sock_discard+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <sock_discard+0xdb>
jmp    11de <sock_discard+0xae>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
lea    0xe0f(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_discard>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x8000,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
cmp    $0x8001,%esi
jl     1195 <sock_discard+0x65>
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x8000,%edx
mov    $0x1,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1050 <sock_recv@plt>
cmp    $0xffffffff,%eax
je     11df <sock_discard+0xaf>
lea    -0x8000(%rbx),%edx
cmp    $0x10000,%ebx
mov    %edx,%ebx
jg     1160 <sock_discard+0x30>
test   %edx,%edx
jne    119b <sock_discard+0x6b>
jmp    11b5 <sock_discard+0x85>
mov    %ebx,%edx
test   %edx,%edx
je     11b5 <sock_discard+0x85>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x1,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1050 <sock_recv@plt>
cmp    $0xffffffff,%eax
je     11df <sock_discard+0xaf>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
lea    0xe38(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
xor    %eax,%eax
jmp    11e4 <sock_discard+0xb4>
mov    $0xffffffff,%eax
add    $0x8000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [31 x i8] c"I'm currently discarding data\0A\00"
define i32 @sock_discard(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [32768 x i8]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
br label %11
11: ; preds = %22, %4
%12 = load i32, i32* %7
%13 = icmp sgt i32 %12, 32768
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32, i32* %6
%16 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = call i32 @sock_recv(i32 %15, i8* %16, i32 32768, i32 1, i8* %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %5
br label %42
22: ; preds = %14
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 32768
store i32 %24, i32* %7
br label %11
25: ; preds = %11
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* %6
%30 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%31 = load i32, i32* %7
%32 = load i8*, i8** %8
%33 = load i32, i32* %9
%34 = call i32 @sock_recv(i32 %29, i8* %30, i32 %31, i32 1, i8* %32, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %28
store i32 -1, i32* %5
br label %42
37: ; preds = %28
br label %38
38: ; preds = %37, %25
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @assert(i32 1)
store i32 0, i32* %5
br label %42
42: ; preds = %38, %36, %21
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [31 x i8] c"I'm currently discarding data\0A\00"
define i32 @sock_discard(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [32768 x i8]
%6 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%7 = icmp sgt i32 %1, 32768
br i1 %7, label %8, label %15
8: ; preds = %4, %12
%9 = phi i32 [ %13, %12 ], [ %1, %4 ]
%10 = call i32 @sock_recv(i32 %0, i8* %6, i32 32768, i32 1, i8* %2, i32 %3)
%11 = icmp eq i32 %10, -1
br i1 %11, label %25, label %12
12: ; preds = %8
%13 = add nsw i32 %9, -32768
%14 = icmp sgt i32 %9, 65536
br i1 %14, label %8, label %15
15: ; preds = %12, %4
%16 = phi i32 [ %1, %4 ], [ %13, %12 ]
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i32 @sock_recv(i32 %0, i8* %6, i32 %16, i32 1, i8* %2, i32 %3)
%20 = icmp eq i32 %19, -1
br i1 %20, label %25, label %21
21: ; preds = %18, %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @assert(i32 1)
br label %25
25: ; preds = %8, %18, %21
%26 = phi i32 [ 0, %21 ], [ -1, %18 ], [ -1, %8 ]
ret i32 %26
}