#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
typedef int /*<<< orphan*/ u_int32_t;
typedef scalar_t__ u_int16_t;

/* Variables and functions */
scalar_t__ htonl(scalar_t__);
int /*<<< orphan*/ sendtcp(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__,
                           scalar_t__, unsigned char *, int, scalar_t__, int,
                           int /*<<< orphan*/);
int sendtcpdata(u_int32_t s_ip, u_int32_t d_ip, u_int16_t sport,
                u_int16_t dport, unsigned char *buf, u_int16_t buflen,
                int seqoffset, int acknumber, uint16_t id, int direction) {
  uint32_t i;
  int segsize = 512;
  for (i = 0; i < buflen; i = i + segsize) {
    if ((i + segsize) > buflen) {
      segsize = (buflen - i);
    }
    sendtcp(s_ip, d_ip, sport, dport, (buf + i), segsize,
            (seqoffset + htonl(i)), acknumber, id);
  }
  return (0);
}


x86 assembly (clang, -O0):
<sendtcpdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x200,-0x34(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    1213 <sendtcpdata+0xf3>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
cmp    -0x28(%rbp),%rax
jle    118a <sendtcpdata+0x6a>
mov    -0x28(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %eax,-0x34(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
movslq 0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <htonl@plt>
mov    -0x60(%rbp),%r11
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x38(%rbp),%r9d
add    %rax,%r11
mov    0x18(%rbp),%r10d
mov    0x20(%rbp),%eax
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <sendtcp@plt>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    115c <sendtcpdata+0x3c>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendtcpdata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %esi,0xc(%rsp)
mov    %edi,0x8(%rsp)
test   %r9,%r9
jle    11c0 <sendtcpdata+0xa0>
mov    %r9,%r13
mov    %r8,%rbp
movslq 0x60(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    $0x200,%r14d
xor    %r15d,%r15d
xchg   %ax,%ax
movslq %r14d,%r14
lea    (%r15,%r14,1),%rax
mov    %r13d,%ecx
sub    %r15d,%ecx
cmp    %r13,%rax
cmovg  %ecx,%r14d
lea    (%r15,%rbp,1),%r12
mov    %r15,%rdi
call   1030 <htonl@plt>
add    0x10(%rsp),%rax
sub    $0x8,%rsp
mov    0x10(%rsp),%edi
mov    0x14(%rsp),%esi
mov    0x20(%rsp),%rdx
mov    0x28(%rsp),%rcx
mov    %r12,%r8
mov    %r14d,%r9d
mov    0x78(%rsp),%ebx
push   %rbx
mov    0x78(%rsp),%ebx
push   %rbx
push   %rax
call   1040 <sendtcp@plt>
add    $0x20,%rsp
movslq %r14d,%rax
add    %rax,%r15
cmp    %r13,%r15
jl     1160 <sendtcpdata+0x40>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sendtcpdata(i32 %0, i32 %1, i64 %2, i64 %3, i8* %4, i64 %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i64
%22 = alloca i32
store i32 %0, i32* %11
store i32 %1, i32* %12
store i64 %2, i64* %13
store i64 %3, i64* %14
store i8* %4, i8** %15
store i64 %5, i64* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i32 %9, i32* %20
store i32 512, i32* %22
store i64 0, i64* %21
br label %23
23: ; preds = %56, %10
%24 = load i64, i64* %21
%25 = load i64, i64* %16
%26 = icmp slt i64 %24, %25
br i1 %26, label %27, label %61
27: ; preds = %23
%28 = load i64, i64* %21
%29 = load i32, i32* %22
%30 = sext i32 %29 to i64
%31 = add nsw i64 %28, %30
%32 = load i64, i64* %16
%33 = icmp sgt i64 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %27
%35 = load i64, i64* %16
%36 = load i64, i64* %21
%37 = sub nsw i64 %35, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %22
br label %39
39: ; preds = %34, %27
%40 = load i32, i32* %11
%41 = load i32, i32* %12
%42 = load i64, i64* %13
%43 = load i64, i64* %14
%44 = load i8*, i8** %15
%45 = load i64, i64* %21
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = load i32, i32* %22
%48 = load i32, i32* %17
%49 = sext i32 %48 to i64
%50 = load i64, i64* %21
%51 = call i64 @htonl(i64 %50)
%52 = add nsw i64 %49, %51
%53 = load i32, i32* %18
%54 = load i32, i32* %19
%55 = call i32 @sendtcp(i32 %40, i32 %41, i64 %42, i64 %43, i8* %46, i32 %47, i64 %52, i32 %53, i32 %54)
br label %56
56: ; preds = %39
%57 = load i64, i64* %21
%58 = load i32, i32* %22
%59 = sext i32 %58 to i64
%60 = add nsw i64 %57, %59
store i64 %60, i64* %21
br label %23
61: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
define i32 @sendtcpdata(i32 %0, i32 %1, i64 %2, i64 %3, i8* %4, i64 %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = icmp sgt i64 %5, 0
br i1 %11, label %12, label %30
12: ; preds = %10
%13 = sext i32 %6 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i32 [ 512, %12 ], [ %22, %14 ]
%16 = phi i64 [ 0, %12 ], [ %28, %14 ]
%17 = sext i32 %15 to i64
%18 = add nsw i64 %16, %17
%19 = icmp sgt i64 %18, %5
%20 = sub nsw i64 %5, %16
%21 = trunc i64 %20 to i32
%22 = select i1 %19, i32 %21, i32 %15
%23 = getelementptr inbounds i8, i8* %4, i64 %16
%24 = tail call i64 @htonl(i64 %16)
%25 = add nsw i64 %24, %13
%26 = tail call i32 @sendtcp(i32 %0, i32 %1, i64 %2, i64 %3, i8* %23, i32 %22, i64 %25, i32 %7, i32 %8)
%27 = sext i32 %22 to i64
%28 = add nsw i64 %16, %27
%29 = icmp slt i64 %28, %5
br i1 %29, label %14, label %30
30: ; preds = %14, %10
ret i32 0
}