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

/* Variables and functions */
int /*<<< orphan*/ MSG_NOSIGNAL;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int send(int, ...);
int /*<<< orphan*/ stderr;
int SendStringTo(int clientsock, char *message, unsigned int length) {
  fprintf(stderr, "SendStringTo Trying to send length %u to peer socket %d \n",
          length, clientsock);
  int opres1 = send(clientsock, &length, sizeof(length), MSG_NOSIGNAL);
  if (opres1 < 0) {
    fprintf(stderr, "Error %u while SendStringTo the length packet\n", errno);
    return opres1;
  } else if (opres1 < sizeof(length)) {
    fprintf(stderr,
            "Did not send the whole length packet ( only %u bytes ) while "
            "SendStringTo\n",
            opres1);
    return opres1;
  }
  fprintf(stderr, "SendStringTo Trying to send `%s` to peer socket %d \n",
          message, clientsock);
  int opres2 = send(clientsock, message, length, MSG_NOSIGNAL);
  if (opres2 < 0) {
    fprintf(stderr, "Error %u while SendStringTo the length packet\n", errno);
    return opres2;
  } else if (opres2 < sizeof(length)) {
    fprintf(stderr,
            "Did not send the whole length packet ( only %u bytes ) while "
            "SendStringTo\n",
            opres2);
    return opres2;
  }
  return opres2;
}


x86 assembly (clang, -O0):
<SendStringTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11a3 <SendStringTo+0x83>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
lea    0xea9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1289 <SendStringTo+0x169>
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
jae    11d6 <SendStringTo+0xb6>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1289 <SendStringTo+0x169>
jmp    11db <SendStringTo+0xbb>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%ecx
lea    0xec2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    0x2dc6(%rip),%rax
mov    (%rax),%ecx
mov    $0x0,%al
call   1030 <send@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    124b <SendStringTo+0x12b>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1289 <SendStringTo+0x169>
movslq -0x1c(%rbp),%rax
cmp    $0x4,%rax
jae    127e <SendStringTo+0x15e>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1289 <SendStringTo+0x169>
jmp    1283 <SendStringTo+0x163>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendStringTo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    %edx,0xc(%rsp)
mov    0x2ea4(%rip),%r15
mov    (%r15),%edi
lea    0xeba(%rip),%rsi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e7a(%rip),%r12
mov    (%r12),%ecx
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <send@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11bb <SendStringTo+0x9b>
mov    (%r15),%edi
cmp    $0x3,%ebx
jbe    11b0 <SendStringTo+0x90>
lea    0xf32(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0xc(%rsp),%edx
mov    (%r12),%ecx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <send@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11bb <SendStringTo+0x9b>
cmp    $0x3,%ebx
ja     11d5 <SendStringTo+0xb5>
mov    (%r15),%edi
lea    0xeb2(%rip),%rsi
mov    %ebx,%edx
jmp    11ce <SendStringTo+0xae>
mov    (%r15),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [58 x i8] c"SendStringTo Trying to send length %u to peer socket %d \0A\00"
@MSG_NOSIGNAL = global i32 0
@.str.1 = [47 x i8] c"Error %u while SendStringTo the length packet\0A\00"
@errno = global i32 0
@.str.2 = [75 x i8] c"Did not send the whole length packet ( only %u bytes ) while SendStringTo\0A\00"
@.str.3 = [53 x i8] c"SendStringTo Trying to send `%s` to peer socket %d \0A\00"
define i32 @SendStringTo(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* @stderr
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %5
%15 = load i32, i32* @MSG_NOSIGNAL
%16 = call i32 (i32, ...) @send(i32 %14, i32* %7, i64 4, i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %8
store i32 %23, i32* %4
br label %63
24: ; preds = %3
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = icmp ult i64 %26, 4
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i32, i32* %8
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %63
33: ; preds = %24
br label %34
34: ; preds = %33
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %6
%37 = load i32, i32* %5
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %36, i32 %37)
%39 = load i32, i32* %5
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = load i32, i32* @MSG_NOSIGNAL
%43 = call i32 (i32, ...) @send(i32 %39, i8* %40, i32 %41, i32 %42)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %34
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %9
store i32 %50, i32* %4
br label %63
51: ; preds = %34
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = icmp ult i64 %53, 4
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = load i32, i32* %9
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %9
store i32 %59, i32* %4
br label %63
60: ; preds = %51
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
store i32 %62, i32* %4
br label %63
63: ; preds = %61, %55, %46, %28, %19
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [58 x i8] c"SendStringTo Trying to send length %u to peer socket %d \0A\00"
@MSG_NOSIGNAL = global i32 0
@.str.1 = [47 x i8] c"Error %u while SendStringTo the length packet\0A\00"
@errno = global i32 0
@.str.2 = [75 x i8] c"Did not send the whole length packet ( only %u bytes ) while SendStringTo\0A\00"
@.str.3 = [53 x i8] c"SendStringTo Trying to send `%s` to peer socket %d \0A\00"
define i32 @SendStringTo(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
store i32 %2, i32* %4
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %0)
%7 = load i32, i32* @MSG_NOSIGNAL
%8 = call i32 (i32, ...) @send(i32 %0, i32* %4, i64 4, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %34
14: ; preds = %3
%15 = icmp ult i32 %8, 4
%16 = load i32, i32* @stderr
br i1 %15, label %17, label %19
17: ; preds = %14
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %34
19: ; preds = %14
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %0)
%21 = load i32, i32* %4
%22 = load i32, i32* @MSG_NOSIGNAL
%23 = call i32 (i32, ...) @send(i32 %0, i8* %1, i32 %21, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %34
29: ; preds = %19
%30 = icmp ult i32 %23, 4
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %34
34: ; preds = %25, %31, %29, %17, %10
%35 = phi i32 [ %8, %10 ], [ %8, %17 ], [ %23, %29 ], [ %23, %31 ], [ %23, %25 ]
ret i32 %35
}