#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 /*<<< 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 /*<<< 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, uint8_t flags,
                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, flags);
  }
  return (0);
}


x86 assembly (clang, -O0):
<sendtcpdata>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x78,%rsp
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x200,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1215 <sendtcpdata+0xf5>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
cmp    -0x30(%rbp),%rax
jle    118b <sendtcpdata+0x6b>
mov    -0x30(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
movslq 0x10(%rbp),%rbx
mov    -0x38(%rbp),%rdi
call   1030 <htonl@plt>
mov    -0x60(%rbp),%edi
mov    -0x5c(%rbp),%esi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x40(%rbp),%r9d
add    %rax,%rbx
mov    0x18(%rbp),%r11d
mov    0x20(%rbp),%r10d
mov    0x28(%rbp),%eax
mov    %rbx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1040 <sendtcp@plt>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    115d <sendtcpdata+0x3d>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
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    11c1 <sendtcpdata+0xa1>
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
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x18(%rsp),%rdx
mov    0x20(%rsp),%rcx
mov    %r12,%r8
mov    %r14d,%r9d
mov    0x78(%rsp),%ebx
push   %rbx
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, i32 %10) {
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i64
%24 = alloca i32
store i32 %0, i32* %12
store i32 %1, i32* %13
store i64 %2, i64* %14
store i64 %3, i64* %15
store i8* %4, i8** %16
store i64 %5, i64* %17
store i32 %6, i32* %18
store i32 %7, i32* %19
store i32 %8, i32* %20
store i32 %9, i32* %21
store i32 %10, i32* %22
store i32 512, i32* %24
store i64 0, i64* %23
br label %25
25: ; preds = %59, %11
%26 = load i64, i64* %23
%27 = load i64, i64* %17
%28 = icmp slt i64 %26, %27
br i1 %28, label %29, label %64
29: ; preds = %25
%30 = load i64, i64* %23
%31 = load i32, i32* %24
%32 = sext i32 %31 to i64
%33 = add nsw i64 %30, %32
%34 = load i64, i64* %17
%35 = icmp sgt i64 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load i64, i64* %17
%38 = load i64, i64* %23
%39 = sub nsw i64 %37, %38
%40 = trunc i64 %39 to i32
store i32 %40, i32* %24
br label %41
41: ; preds = %36, %29
%42 = load i32, i32* %12
%43 = load i32, i32* %13
%44 = load i64, i64* %14
%45 = load i64, i64* %15
%46 = load i8*, i8** %16
%47 = load i64, i64* %23
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i32, i32* %24
%50 = load i32, i32* %18
%51 = sext i32 %50 to i64
%52 = load i64, i64* %23
%53 = call i64 @htonl(i64 %52)
%54 = add nsw i64 %51, %53
%55 = load i32, i32* %19
%56 = load i32, i32* %20
%57 = load i32, i32* %21
%58 = call i32 @sendtcp(i32 %42, i32 %43, i64 %44, i64 %45, i8* %48, i32 %49, i64 %54, i32 %55, i32 %56, i32 %57)
br label %59
59: ; preds = %41
%60 = load i64, i64* %23
%61 = load i32, i32* %24
%62 = sext i32 %61 to i64
%63 = add nsw i64 %60, %62
store i64 %63, i64* %23
br label %25
64: ; preds = %25
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, i32 %10) {
%12 = icmp sgt i64 %5, 0
br i1 %12, label %13, label %31
13: ; preds = %11
%14 = sext i32 %6 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 512, %13 ], [ %23, %15 ]
%17 = phi i64 [ 0, %13 ], [ %29, %15 ]
%18 = sext i32 %16 to i64
%19 = add nsw i64 %17, %18
%20 = icmp sgt i64 %19, %5
%21 = sub nsw i64 %5, %17
%22 = trunc i64 %21 to i32
%23 = select i1 %20, i32 %22, i32 %16
%24 = getelementptr inbounds i8, i8* %4, i64 %17
%25 = tail call i64 @htonl(i64 %17)
%26 = add nsw i64 %25, %14
%27 = tail call i32 @sendtcp(i32 %0, i32 %1, i64 %2, i64 %3, i8* %24, i32 %23, i64 %26, i32 %7, i32 %8, i32 %9)
%28 = sext i32 %23 to i64
%29 = add nsw i64 %17, %28
%30 = icmp slt i64 %29, %5
br i1 %30, label %15, label %31
31: ; preds = %15, %11
ret i32 0
}