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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, int);
int send(int, void *, int, int /*<<< orphan*/);
int sendall(int s, void *buf, int len) {
  int total = 0;
  int bytesleft = len;
  int n;
  int tosend;
  while (total < len) {
    if (bytesleft > 16392) {
      tosend = 16392;
    } else {
      tosend = bytesleft;
    }
    if ((n = send(s, buf + total, tosend, 0)) == -1) {
      return 0;
    }
    if (n == -1) {
      printf("dident manage to send all the data as %s:%d.\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/bowlofstew/enterprise-search/refs/"
             "heads/master/src/boithoadClientLib/daemon.c",
             154);
      return 0;
    }
    total += n;
    bytesleft -= n;
  }
  return total;
}


x86 assembly (clang, -O0):
<sendall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e1 <sendall+0xc1>
cmpl   $0x4008,-0x1c(%rbp)
jle    1164 <sendall+0x44>
movl   $0x4008,-0x24(%rbp)
jmp    116a <sendall+0x4a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    119a <sendall+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <sendall+0xc7>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11c8 <sendall+0xa8>
lea    0xe55(%rip),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x9a,%edx
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <sendall+0xc7>
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <sendall+0x1f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendall>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    115e <sendall+0x4e>
mov    %edx,%r12d
mov    %rsi,%r14
mov    %edi,%r15d
mov    %edx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
cmp    $0x4008,%ebx
mov    $0x4008,%edx
cmovl  %ebx,%edx
movslq %ebp,%rsi
add    %r14,%rsi
mov    %r15d,%edi
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    $0xffffffff,%eax
je     115e <sendall+0x4e>
add    %eax,%ebp
sub    %eax,%ebx
cmp    %r12d,%ebp
jl     1130 <sendall+0x20>
jmp    1160 <sendall+0x50>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"dident manage to send all the data as %s:%d.\0A\00"
@.str.1 = [168 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bowlofstew/enterprise-search/refs/heads/master/src/boithoadClientLib/daemon.c\00"
define i32 @sendall(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%12 = load i32, i32* %7
store i32 %12, i32* %9
br label %13
13: ; preds = %38, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %45
17: ; preds = %13
%18 = load i32, i32* %9
%19 = icmp sgt i32 %18, 16392
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 16392, i32* %11
br label %23
21: ; preds = %17
%22 = load i32, i32* %9
store i32 %22, i32* %11
br label %23
23: ; preds = %21, %20
%24 = load i32, i32* %5
%25 = load i8*, i8** %6
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr i8, i8* %25, i64 %27
%29 = load i32, i32* %11
%30 = call i32 @send(i32 %24, i8* %28, i32 %29, i32 0)
store i32 %30, i32* %10
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 0, i32* %4
br label %47
33: ; preds = %23
%34 = load i32, i32* %10
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0), i32 154)
store i32 0, i32* %4
br label %47
38: ; preds = %33
%39 = load i32, i32* %10
%40 = load i32, i32* %8
%41 = add nsw i32 %40, %39
store i32 %41, i32* %8
%42 = load i32, i32* %10
%43 = load i32, i32* %9
%44 = sub nsw i32 %43, %42
store i32 %44, i32* %9
br label %13
45: ; preds = %13
%46 = load i32, i32* %8
store i32 %46, i32* %4
br label %47
47: ; preds = %45, %36, %32
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
define i32 @sendall(i32 %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %18
5: ; preds = %3, %14
%6 = phi i32 [ %16, %14 ], [ %2, %3 ]
%7 = phi i32 [ %15, %14 ], [ 0, %3 ]
%8 = icmp slt i32 %6, 16392
%9 = select i1 %8, i32 %6, i32 16392
%10 = sext i32 %7 to i64
%11 = getelementptr i8, i8* %1, i64 %10
%12 = tail call i32 @send(i32 %0, i8* %11, i32 %9, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %18, label %14
14: ; preds = %5
%15 = add nsw i32 %12, %7
%16 = sub nsw i32 %6, %12
%17 = icmp slt i32 %15, %2
br i1 %17, label %5, label %18
18: ; preds = %5, %14, %3
%19 = phi i32 [ 0, %3 ], [ %15, %14 ], [ 0, %5 ]
ret i32 %19
}