#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 */
struct client_socket {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int client_socket_send(struct client_socket *, void const *, size_t);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
ssize_t client_socket_sendall(struct client_socket *socket, const void *buf,
                              size_t len) {
  size_t numsent = 0;
  do {
    ssize_t newsent = client_socket_send(socket, buf + numsent, len - numsent);
    if (!(newsent != -1)) {
      fprintf(stderr,
              "[ERROR] (%s:%d: errno: %s) "
              "Error sending data"
              "\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/BellerophonMobile/xmp3/refs/heads/"
              "master/src/client_socket.c",
              159, (errno == 0 ? "None" : strerror(errno)));
      errno = 0;
      goto error;
    };
    numsent += newsent;
  } while (numsent < len);
  return numsent;
error:
  return -1;
}


x86 assembly (clang, -O0):
<client_socket_sendall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    -0x28(%rbp),%rdx
call   1050 <client_socket_send@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11e4 <client_socket_sendall+0xb4>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e53(%rip),%rax
cmpq   $0x0,(%rax)
jne    119f <client_socket_sendall+0x6f>
lea    0xf30(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11b2 <client_socket_sendall+0x82>
mov    0x2e32(%rip),%rax
mov    (%rax),%rdi
call   1040 <strerror@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x38(%rbp),%r8
lea    0xe40(%rip),%rsi
lea    0xe68(%rip),%rdx
mov    $0x9f,%ecx
call   1030 <fprintf@plt>
mov    0x2e00(%rip),%rax
movq   $0x0,(%rax)
jmp    120a <client_socket_sendall+0xda>
movslq -0x2c(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     114c <client_socket_sendall+0x1c>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1211 <client_socket_sendall+0xe1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_socket_sendall>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r15,%rbx,1),%rsi
mov    %r14,%rdx
sub    %rbx,%rdx
mov    %r12,%rdi
call   1050 <client_socket_send@plt>
cmp    $0xffffffff,%eax
je     1173 <client_socket_sendall+0x43>
cltq
add    %rax,%rbx
cmp    %r14,%rbx
jb     1150 <client_socket_sendall+0x20>
jmp    11c2 <client_socket_sendall+0x92>
mov    0x2e66(%rip),%rax
mov    (%rax),%ebx
mov    0x2e55(%rip),%r14
mov    (%r14),%rdi
test   %rdi,%rdi
je     1195 <client_socket_sendall+0x65>
call   1040 <strerror@plt>
mov    %rax,%r8
jmp    119c <client_socket_sendall+0x6c>
lea    0xf2a(%rip),%r8
lea    0xe5d(%rip),%rsi
lea    0xe85(%rip),%rdx
mov    %ebx,%edi
mov    $0x9f,%ecx
call   1030 <fprintf@plt>
movq   $0x0,(%r14)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.client_socket = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"[ERROR] (%s:%d: errno: %s) Error sending data\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BellerophonMobile/xmp3/refs/heads/master/src/client_socket.c\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"None\00"
define i32 @client_socket_sendall(%struct.client_socket* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.client_socket*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store %struct.client_socket* %0, %struct.client_socket** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %8
br label %10
10: ; preds = %37, %3
%11 = load %struct.client_socket*, %struct.client_socket** %5
%12 = load i8*, i8** %6
%13 = load i64, i64* %8
%14 = getelementptr i8, i8* %12, i64 %13
%15 = load i64, i64* %7
%16 = load i64, i64* %8
%17 = sub i64 %15, %16
%18 = call i32 @client_socket_send(%struct.client_socket* %11, i8* %14, i64 %17)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, -1
br i1 %20, label %32, label %21
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = load i64, i64* @errno
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
br label %29
26: ; preds = %21
%27 = load i64, i64* @errno
%28 = call i8* @strerror(i64 %27)
br label %29
29: ; preds = %26, %25
%30 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %25 ], [ %28, %26 ]
%31 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 159, i8* %30)
store i64 0, i64* @errno
br label %44
32: ; preds = %10
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = load i64, i64* %8
%36 = add i64 %35, %34
store i64 %36, i64* %8
br label %37
37: ; preds = %32
%38 = load i64, i64* %8
%39 = load i64, i64* %7
%40 = icmp ult i64 %38, %39
br i1 %40, label %10, label %41
41: ; preds = %37
%42 = load i64, i64* %8
%43 = trunc i64 %42 to i32
store i32 %43, i32* %4
br label %45
44: ; preds = %29
store i32 -1, i32* %4
br label %45
45: ; preds = %44, %41
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
%struct.client_socket = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"[ERROR] (%s:%d: errno: %s) Error sending data\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BellerophonMobile/xmp3/refs/heads/master/src/client_socket.c\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"None\00"
define i32 @client_socket_sendall(%struct.client_socket* %0, i8* %1, i64 %2) {
br label %4
4: ; preds = %19, %3
%5 = phi i64 [ 0, %3 ], [ %21, %19 ]
%6 = getelementptr i8, i8* %1, i64 %5
%7 = sub i64 %2, %5
%8 = tail call i32 @client_socket_send(%struct.client_socket* %0, i8* %6, i64 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i8* @strerror(i64 %12)
br label %16
16: ; preds = %14, %10
%17 = phi i8* [ %15, %14 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %10 ]
%18 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 159, i8* %17)
store i64 0, i64* @errno
br label %25
19: ; preds = %4
%20 = sext i32 %8 to i64
%21 = add i64 %5, %20
%22 = icmp ult i64 %21, %2
br i1 %22, label %4, label %23
23: ; preds = %19
%24 = trunc i64 %21 to i32
br label %25
25: ; preds = %16, %23
%26 = phi i32 [ %24, %23 ], [ -1, %16 ]
ret i32 %26
}