#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 scalar_t__ int32_t;

/* Variables and functions */
int /*<<< orphan*/ mainserv_bytesin(scalar_t__);
int /*<<< orphan*/ mainserv_bytesout(scalar_t__);
scalar_t__ tcptoforward(int, int, int /*<<< orphan*/ *, scalar_t__, scalar_t__,
                        scalar_t__, scalar_t__);
int32_t mainserv_toforward(int sock1, int sock2, uint8_t *ptr, uint32_t leng,
                           uint32_t rskip, uint32_t wskip, uint32_t timeout) {
  int32_t r;
  r = tcptoforward(sock1, sock2, ptr, leng, rskip, wskip, timeout);
  if (r > 0) {
    if ((uint32_t)r > rskip) {
      mainserv_bytesin(r - rskip);
    }
    if ((uint32_t)r > wskip) {
      mainserv_bytesout(r - wskip);
    }
  }
  return r;
}


x86 assembly (clang, -O0):
<mainserv_toforward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    0x10(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <tcptoforward@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    11bf <mainserv_toforward+0x8f>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    119f <mainserv_toforward+0x6f>
mov    -0x30(%rbp),%rdi
sub    -0x20(%rbp),%rdi
call   1050 <mainserv_bytesin@plt>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    11ba <mainserv_toforward+0x8a>
mov    -0x30(%rbp),%rdi
sub    -0x28(%rbp),%rdi
call   1040 <mainserv_bytesout@plt>
jmp    11bf <mainserv_toforward+0x8f>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mainserv_toforward>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,%r12
mov    0x30(%rsp),%rax
mov    %rax,(%rsp)
call   1030 <tcptoforward@plt>
mov    %rax,%r14
test   %rax,%rax
jle    1171 <mainserv_toforward+0x41>
mov    %rax,%rbx
mov    %rax,%rdi
sub    %r12,%rdi
jle    1164 <mainserv_toforward+0x34>
call   1050 <mainserv_bytesin@plt>
sub    %r15,%rbx
jle    1171 <mainserv_toforward+0x41>
mov    %rbx,%rdi
call   1040 <mainserv_bytesout@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @mainserv_toforward(i32 %0, i32 %1, i32* %2, i64 %3, i64 %4, i64 %5, i64 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32* %2, i32** %10
store i64 %3, i64* %11
store i64 %4, i64* %12
store i64 %5, i64* %13
store i64 %6, i64* %14
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = load i32*, i32** %10
%19 = load i64, i64* %11
%20 = load i64, i64* %12
%21 = load i64, i64* %13
%22 = load i64, i64* %14
%23 = call i64 @tcptoforward(i32 %16, i32 %17, i32* %18, i64 %19, i64 %20, i64 %21, i64 %22)
store i64 %23, i64* %15
%24 = load i64, i64* %15
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %45
26: ; preds = %7
%27 = load i64, i64* %15
%28 = load i64, i64* %12
%29 = icmp sgt i64 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i64, i64* %15
%32 = load i64, i64* %12
%33 = sub nsw i64 %31, %32
%34 = call i32 @mainserv_bytesin(i64 %33)
br label %35
35: ; preds = %30, %26
%36 = load i64, i64* %15
%37 = load i64, i64* %13
%38 = icmp sgt i64 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i64, i64* %15
%41 = load i64, i64* %13
%42 = sub nsw i64 %40, %41
%43 = call i32 @mainserv_bytesout(i64 %42)
br label %44
44: ; preds = %39, %35
br label %45
45: ; preds = %44, %7
%46 = load i64, i64* %15
ret i64 %46
}

LLVM IR (-O2):
define i64 @mainserv_toforward(i32 %0, i32 %1, i32* %2, i64 %3, i64 %4, i64 %5, i64 %6) {
%8 = tail call i64 @tcptoforward(i32 %0, i32 %1, i32* %2, i64 %3, i64 %4, i64 %5, i64 %6)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = icmp sgt i64 %8, %4
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = sub nsw i64 %8, %4
%14 = tail call i32 @mainserv_bytesin(i64 %13)
br label %15
15: ; preds = %12, %10
%16 = icmp sgt i64 %8, %5
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = sub nsw i64 %8, %5
%19 = tail call i32 @mainserv_bytesout(i64 %18)
br label %20
20: ; preds = %15, %17, %7
ret i64 %8
}