#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*/ u_char;
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ err(int, char *, char const *);
int errno;
int /*<<< orphan*/ errx(int, char *, char const *);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ packet_fill(int /*<<< orphan*/ *);
scalar_t__ send(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void my_send(int sock, const char *who, pid_t pid) {
  u_char packet[16 * (1024 * 1024)];
  ssize_t len;
  size_t totlen;
  int error;
  totlen = 0;
  packet_fill(packet);
  while (totlen < 16 * (1024 * 1024)) {
    len = send(sock, packet + totlen, 16 * (1024 * 1024) - totlen, 0);
    if (len < 0) {
      error = errno;
      (void)kill(pid, SIGTERM);
      errno = error;
      err(-1, "%s: send()", who);
    }
    if (len == 0) {
      (void)kill(pid, SIGTERM);
      errx(-1, "%s: send(): EOF", who);
    }
    totlen += len;
  }
}


x86 assembly (clang, -O0):
<my_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4000040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x4000030(%rbp)
lea    -0x4000020(%rbp),%rdi
call   1070 <packet_fill@plt>
cmpq   $0x1000000,-0x4000030(%rbp)
jae    1261 <my_send+0x111>
mov    -0x4(%rbp),%edi
lea    -0x4000020(%rbp),%rsi
mov    -0x4000030(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x1000000,%eax
sub    -0x4000030(%rbp),%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,-0x4000028(%rbp)
cmpq   $0x0,-0x4000028(%rbp)
jge    1213 <my_send+0xc3>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4000034(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    -0x4000034(%rbp),%ecx
mov    0x2ddc(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xdf2(%rip),%rsi
call   1060 <err@plt>
cmpq   $0x0,-0x4000028(%rbp)
jne    1247 <my_send+0xf7>
mov    -0x14(%rbp),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    -0x10(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xdc9(%rip),%rsi
call   1030 <errx@plt>
mov    -0x4000028(%rbp),%rax
add    -0x4000030(%rbp),%rax
mov    %rax,-0x4000030(%rbp)
jmp    117c <my_send+0x2c>
add    $0x4000040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4000018,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,%r13
mov    %edi,%ebp
lea    0x10(%rsp),%rdi
call   1070 <packet_fill@plt>
xor    %r12d,%r12d
jmp    11bf <my_send+0x6f>
nopl   0x0(%rax)
mov    0x2e51(%rip),%r14
mov    (%r14),%r15d
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
call   1050 <kill@plt>
mov    %r15d,(%r14)
mov    $0xffffffff,%edi
lea    0xe55(%rip),%rsi
mov    %r13,%rdx
call   1060 <err@plt>
add    %rbx,%r12
cmp    $0x1000000,%r12
jae    120a <my_send+0xba>
lea    (%rsp,%r12,4),%rsi
add    $0x10,%rsi
mov    $0x1000000,%edx
sub    %r12d,%edx
mov    %ebp,%edi
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1180 <my_send+0x30>
jne    11b3 <my_send+0x63>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
call   1050 <kill@plt>
mov    $0xffffffff,%edi
lea    0xe0b(%rip),%rsi
mov    %r13,%rdx
call   1030 <errx@plt>
jmp    11b3 <my_send+0x63>
add    $0x4000018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@SIGTERM = global i32 0
@.str = [11 x i8] c"%s: send()\00"
@.str.1 = [16 x i8] c"%s: send(): EOF\00"
define void @my_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [16777216 x i32]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i64 0, i64* %9
%11 = getelementptr inbounds [16777216 x i32], [16777216 x i32]* %7, i64 0, i64 0
%12 = call i32 @packet_fill(i32* %11)
br label %13
13: ; preds = %44, %3
%14 = load i64, i64* %9
%15 = icmp ult i64 %14, 16777216
br i1 %15, label %16, label %48
16: ; preds = %13
%17 = load i32, i32* %4
%18 = getelementptr inbounds [16777216 x i32], [16777216 x i32]* %7, i64 0, i64 0
%19 = load i64, i64* %9
%20 = getelementptr inbounds i32, i32* %18, i64 %19
%21 = load i64, i64* %9
%22 = sub i64 16777216, %21
%23 = trunc i64 %22 to i32
%24 = call i64 @send(i32 %17, i32* %20, i32 %23, i32 0)
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %16
%28 = load i32, i32* @errno
store i32 %28, i32* %10
%29 = load i32, i32* %6
%30 = load i32, i32* @SIGTERM
%31 = call i32 @kill(i32 %29, i32 %30)
%32 = load i32, i32* %10
store i32 %32, i32* @errno
%33 = load i8*, i8** %5
%34 = call i32 @err(i32 -1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %27, %16
%36 = load i64, i64* %8
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* %6
%40 = load i32, i32* @SIGTERM
%41 = call i32 @kill(i32 %39, i32 %40)
%42 = load i8*, i8** %5
%43 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %38, %35
%45 = load i64, i64* %8
%46 = load i64, i64* %9
%47 = add i64 %46, %45
store i64 %47, i64* %9
br label %13
48: ; preds = %13
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@SIGTERM = global i32 0
@.str = [11 x i8] c"%s: send()\00"
@.str.1 = [16 x i8] c"%s: send(): EOF\00"
define void @my_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca [16777216 x i32]
%5 = bitcast [16777216 x i32]* %4 to i8*
%6 = getelementptr inbounds [16777216 x i32], [16777216 x i32]* %4, i64 0, i64 0
%7 = call i32 @packet_fill(i32* %6)
br label %8
8: ; preds = %3, %26
%9 = phi i64 [ 0, %3 ], [ %27, %26 ]
%10 = getelementptr inbounds [16777216 x i32], [16777216 x i32]* %4, i64 0, i64 %9
%11 = trunc i64 %9 to i32
%12 = sub nuw nsw i32 16777216, %11
%13 = call i64 @send(i32 %0, i32* %10, i32 %12, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = load i32, i32* @errno
%17 = load i32, i32* @SIGTERM
%18 = call i32 @kill(i32 %2, i32 %17)
store i32 %16, i32* @errno
%19 = call i32 @err(i32 -1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %26
20: ; preds = %8
%21 = icmp eq i64 %13, 0
br i1 %21, label %22, label %26
22: ; preds = %20
%23 = load i32, i32* @SIGTERM
%24 = call i32 @kill(i32 %2, i32 %23)
%25 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %26
26: ; preds = %15, %22, %20
%27 = add i64 %13, %9
%28 = icmp ult i64 %27, 16777216
br i1 %28, label %8, label %29
29: ; preds = %26
ret void
}