#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*/ buffer;

/* Variables and functions */
scalar_t__ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int sendDataInChunks(int CSock, char *data) {
  char buffer[1024 + 1];
  int bytecount = 0;
  int w = 0;
  int p, i, c;
  bytecount = strlen(data);
  while (data && bytecount > 0) {
    memset(buffer, 0, sizeof(buffer));
    strncpy(buffer, data, 1024);
    0 && fprintf(stderr, "Library sending data chunk |%s|\n", buffer);
    send(CSock, buffer, strlen(buffer), 0);
    bytecount -= strlen(buffer);
    data += strlen(buffer);
  }
  return (bytecount);
}


x86 assembly (clang, -O0):
<sendDataInChunks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x424(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x435(%rbp)
je     1198 <sendDataInChunks+0x58>
cmpl   $0x0,-0x424(%rbp)
setg   %al
mov    %al,-0x435(%rbp)
mov    -0x435(%rbp),%al
test   $0x1,%al
jne    11ab <sendDataInChunks+0x6b>
jmp    1249 <sendDataInChunks+0x109>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1060 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x424(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1175 <sendDataInChunks+0x35>
mov    -0x424(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendDataInChunks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11c6 <sendDataInChunks+0x86>
test   %ebp,%ebp
jle    11c6 <sendDataInChunks+0x86>
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rbx,%rbx
je     11c6 <sendDataInChunks+0x86>
cltq
add    %rax,%rbx
test   %ebp,%ebp
jg     1170 <sendDataInChunks+0x30>
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
define i32 @sendDataInChunks(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1025 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %7
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %6
br label %13
13: ; preds = %21, %2
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 0
br label %19
19: ; preds = %16, %13
%20 = phi i1 [ false, %13 ], [ %18, %16 ]
br i1 %20, label %21, label %41
21: ; preds = %19
%22 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 1025)
%24 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%25 = load i8*, i8** %4
%26 = call i32 @strncpy(i8* %24, i8* %25, i32 1024)
%27 = load i32, i32* %3
%28 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @send(i32 %27, i8* %28, i32 %30, i32 0)
%32 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, %33
store i32 %35, i32* %6
%36 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = load i8*, i8** %4
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %4
br label %13
41: ; preds = %19
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
define i32 @sendDataInChunks(i32 %0, i8* %1) {
%3 = alloca [1025 x i8]
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp ne i8* %1, null
%7 = icmp sgt i32 %5, 0
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %9, label %24
9: ; preds = %2, %9
%10 = phi i8* [ %20, %9 ], [ %1, %2 ]
%11 = phi i32 [ %17, %9 ], [ %5, %2 ]
%12 = call i32 @memset(i8* %4, i32 0, i32 1025)
%13 = call i32 @strncpy(i8* %4, i8* %10, i32 1024)
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @send(i32 %0, i8* %4, i32 %14, i32 0)
%16 = call i32 @strlen(i8* %4)
%17 = sub nsw i32 %11, %16
%18 = call i32 @strlen(i8* %4)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %10, i64 %19
%21 = icmp ne i8* %10, null
%22 = icmp sgt i32 %17, 0
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %9, label %24
24: ; preds = %9, %2
%25 = phi i32 [ %5, %2 ], [ %17, %9 ]
ret i32 %25
}