#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__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ internal_logit(char *, int, char *, char *,
                                  int /*<<< orphan*/);
scalar_t__ send(int, char const *, size_t const, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int send_all(int sock, const char *buf, const size_t size) {
  ssize_t sent;
  size_t send_pos = 0;
  while (send_pos < size) {
    sent = send(sock, buf + send_pos, size - send_pos, 0);
    if (sent < 0) {
      internal_logit("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                     "outputs/2022-01-22/02-19-57/repos/ecthiender/mocp-git/"
                     "refs/heads/master/protocol.c",
                     318, "UNKNOWN_FUNC", "Error while sending data: %s",
                     strerror(errno));
      return 0;
    }
    send_pos += sent;
  }
  return 1;
}


x86 assembly (clang, -O0):
<send_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11cf <send_all+0x9f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    -0x28(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11be <send_all+0x8e>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    %eax,%r8d
lea    0xe66(%rip),%rdi
mov    $0x13e,%esi
lea    0xee5(%rip),%rdx
lea    0xeeb(%rip),%rcx
call   1050 <internal_logit@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <send_all+0xa6>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    114b <send_all+0x1b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_all>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%r14d
test   %rdx,%rdx
je     11a6 <send_all+0x76>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%r12d
xor    %ebp,%ebp
xchg   %ax,%ax
lea    (%r15,%rbp,1),%rsi
mov    %rbx,%rdx
sub    %rbp,%rdx
mov    %r12d,%edi
xor    %ecx,%ecx
call   1030 <send@plt>
test   %rax,%rax
js     1173 <send_all+0x43>
add    %rax,%rbp
cmp    %rbx,%rbp
jb     1150 <send_all+0x20>
jmp    11a6 <send_all+0x76>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xe78(%rip),%rdi
lea    0xefc(%rip),%rdx
lea    0xf02(%rip),%rcx
mov    $0x13e,%esi
mov    %eax,%r8d
call   1050 <internal_logit@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ecthiender/mocp-git/refs/heads/master/protocol.c\00"
@.str.1 = [13 x i8] c"UNKNOWN_FUNC\00"
@.str.2 = [29 x i8] c"Error while sending data: %s\00"
@errno = global i32 0
define i32 @send_all(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %9
br label %10
10: ; preds = %29, %3
%11 = load i64, i64* %9
%12 = load i64, i64* %7
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i8*, i8** %6
%17 = load i64, i64* %9
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i64, i64* %7
%20 = load i64, i64* %9
%21 = sub i64 %19, %20
%22 = call i64 @send(i32 %15, i8* %18, i64 %21, i32 0)
store i64 %22, i64* %8
%23 = load i64, i64* %8
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = load i32, i32* @errno
%27 = call i32 @strerror(i32 %26)
%28 = call i32 @internal_logit(i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str, i64 0, i64 0), i32 318, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 0, i32* %4
br label %34
29: ; preds = %14
%30 = load i64, i64* %8
%31 = load i64, i64* %9
%32 = add i64 %31, %30
store i64 %32, i64* %9
br label %10
33: ; preds = %10
store i32 1, i32* %4
br label %34
34: ; preds = %33, %25
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@.str = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ecthiender/mocp-git/refs/heads/master/protocol.c\00"
@.str.1 = [13 x i8] c"UNKNOWN_FUNC\00"
@.str.2 = [29 x i8] c"Error while sending data: %s\00"
@errno = global i32 0
define i32 @send_all(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %18, label %7
5: ; preds = %7
%6 = icmp ult i64 %13, %2
br i1 %6, label %7, label %18
7: ; preds = %3, %5
%8 = phi i64 [ %13, %5 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = sub i64 %2, %8
%11 = tail call i64 @send(i32 %0, i8* %9, i64 %10, i32 0)
%12 = icmp slt i64 %11, 0
%13 = add i64 %11, %8
br i1 %12, label %14, label %5
14: ; preds = %7
%15 = load i32, i32* @errno
%16 = tail call i32 @strerror(i32 %15)
%17 = tail call i32 @internal_logit(i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str, i64 0, i64 0), i32 318, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %5, %3, %14
%19 = phi i32 [ 0, %14 ], [ 1, %3 ], [ 1, %5 ]
ret i32 %19
}