#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint32_t;
typedef int int32_t;

/* Variables and functions */
int read(int, int /*<<< orphan*/ *, scalar_t__);
int32_t skipall(int sock, uint32_t leng) {
  static uint8_t skipbuff[16384];
  uint32_t brecv;
  int res;
  brecv = 0;
  while (brecv < leng) {
    if (leng - brecv > 16384) {
      res = read(sock, skipbuff, 16384);
    } else {
      res = read(sock, skipbuff, leng - brecv);
    }
    if (res <= 0) {
      return -1;
    }
    brecv += res;
  }
  return brecv;
}


x86 assembly (clang, -O0):
<skipall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11a6 <skipall+0x96>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
cmp    $0x4000,%rax
jle    1165 <skipall+0x55>
mov    -0x8(%rbp),%edi
lea    0x2eed(%rip),%rsi
mov    $0x4000,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
jmp    117f <skipall+0x6f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
sub    -0x18(%rbp),%rdx
lea    0x2ec9(%rip),%rsi
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1195 <skipall+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <skipall+0x9d>
movslq -0x1c(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1127 <skipall+0x17>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skipall>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rsi,%rsi
jle    116b <skipall+0x5b>
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x4000,%r12d
lea    0x2f0f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdx
sub    %rbx,%rdx
cmp    $0x4000,%rdx
cmovge %r12,%rdx
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <read@plt>
test   %eax,%eax
jle    116f <skipall+0x5f>
mov    %eax,%eax
add    %rax,%rbx
cmp    %r14,%rbx
jl     1140 <skipall+0x30>
jmp    1174 <skipall+0x64>
xor    %ebx,%ebx
jmp    1174 <skipall+0x64>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@skipall.skipbuff = internal global [16384 x i32] zeroinitializer
define i32 @skipall(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 0, i64* %6
br label %8
8: ; preds = %30, %2
%9 = load i64, i64* %6
%10 = load i64, i64* %5
%11 = icmp slt i64 %9, %10
br i1 %11, label %12, label %35
12: ; preds = %8
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = sub nsw i64 %13, %14
%16 = icmp sgt i64 %15, 16384
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* %4
%19 = call i32 @read(i32 %18, i32* getelementptr inbounds ([16384 x i32], [16384 x i32]* @skipall.skipbuff, i64 0, i64 0), i64 16384)
store i32 %19, i32* %7
br label %26
20: ; preds = %12
%21 = load i32, i32* %4
%22 = load i64, i64* %5
%23 = load i64, i64* %6
%24 = sub nsw i64 %22, %23
%25 = call i32 @read(i32 %21, i32* getelementptr inbounds ([16384 x i32], [16384 x i32]* @skipall.skipbuff, i64 0, i64 0), i64 %24)
store i32 %25, i32* %7
br label %26
26: ; preds = %20, %17
%27 = load i32, i32* %7
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %3
br label %38
30: ; preds = %26
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = load i64, i64* %6
%34 = add nsw i64 %33, %32
store i64 %34, i64* %6
br label %8
35: ; preds = %8
%36 = load i64, i64* %6
%37 = trunc i64 %36 to i32
store i32 %37, i32* %3
br label %38
38: ; preds = %35, %29
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@skipall.skipbuff = internal global [16384 x i32] zeroinitializer
define i32 @skipall(i32 %0, i64 %1) {
%3 = icmp sgt i64 %1, 0
br i1 %3, label %6, label %17
4: ; preds = %6
%5 = icmp slt i64 %14, %1
br i1 %5, label %6, label %15
6: ; preds = %2, %4
%7 = phi i64 [ %14, %4 ], [ 0, %2 ]
%8 = sub nsw i64 %1, %7
%9 = icmp slt i64 %8, 16384
%10 = select i1 %9, i64 %8, i64 16384
%11 = tail call i32 @read(i32 %0, i32* getelementptr inbounds ([16384 x i32], [16384 x i32]* @skipall.skipbuff, i64 0, i64 0), i64 %10)
%12 = icmp slt i32 %11, 1
%13 = zext i32 %11 to i64
%14 = add nuw nsw i64 %7, %13
br i1 %12, label %17, label %4
15: ; preds = %4
%16 = trunc i64 %14 to i32
br label %17
17: ; preds = %6, %2, %15
%18 = phi i32 [ 0, %2 ], [ %16, %15 ], [ -1, %6 ]
ret i32 %18
}