#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;
typedef int /*<<< orphan*/ incoming_string_length;

/* Variables and functions */
int /*<<< orphan*/ MSG_WAITALL;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int);
int recv(int, char *, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int RecvStringFrom(int clientsock, char *message, unsigned int length) {
  fprintf(stderr, "Trying RecvStringFrom\n");
  memset(message, 0, length);
  unsigned int incoming_string_length = 0;
  int opres1 = recv(clientsock, (char *)&incoming_string_length,
                    sizeof(incoming_string_length), MSG_WAITALL);
  if (opres1 < 0) {
    fprintf(stderr, "Error %u while RecvStringFrom the length packet\n", errno);
    return opres1;
  } else if (opres1 < sizeof(length)) {
    fprintf(stderr,
            "Did not receive the whole length packet ( only %u bytes ) while "
            "RecvStringFrom\n",
            opres1);
    return opres1;
  }
  fprintf(stderr, "Incoming string is %u bytes long ( from peer socket %d ) \n",
          incoming_string_length, clientsock);
  if (length < incoming_string_length) {
    fprintf(stderr,
            "Incoming string will overflow .. clipping it to our buffer size ( "
            "%u ).. \n",
            length);
    incoming_string_length = length;
  }
  int opres2 = recv(clientsock, message, incoming_string_length, MSG_WAITALL);
  if (opres2 < 0) {
    fprintf(stderr, "Error %u while RecvStringFrom the length packet\n", errno);
    return opres2;
  } else if (opres2 < incoming_string_length) {
    fprintf(stderr,
            "Did not receive the whole length packet ( only %u bytes ) while "
            "RecvStringFrom\n",
            opres2);
    return opres2;
  }
  fprintf(stderr, "Incoming string is `%s` ( from peer socket %d ) \n", message,
          clientsock);
  return opres2;
}


x86 assembly (clang, -O0):
<RecvStringFrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    0x2e4c(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c0 <RecvStringFrom+0x90>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12eb <RecvStringFrom+0x1bb>
movslq -0x1c(%rbp),%rax
cmp    $0x4,%rax
jae    11f3 <RecvStringFrom+0xc3>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12eb <RecvStringFrom+0x1bb>
jmp    11f8 <RecvStringFrom+0xc8>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1241 <RecvStringFrom+0x111>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    0x2d76(%rip),%rax
mov    (%rax),%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1291 <RecvStringFrom+0x161>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x2d62(%rip),%rax
mov    (%rax),%edx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12eb <RecvStringFrom+0x1bb>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    12c2 <RecvStringFrom+0x192>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12eb <RecvStringFrom+0x1bb>
jmp    12c7 <RecvStringFrom+0x197>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%ecx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RecvStringFrom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e96(%rip),%r12
mov    (%r12),%edi
lea    0xeab(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
movl   $0x0,0x4(%rsp)
mov    0x2e51(%rip),%r13
mov    0x0(%r13),%ecx
lea    0x4(%rsp),%rsi
mov    %r15d,%edi
mov    $0x4,%edx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11fd <RecvStringFrom+0xcd>
mov    (%r12),%edi
cmp    $0x3,%ebp
jbe    11f2 <RecvStringFrom+0xc2>
mov    0x4(%rsp),%edx
lea    0xef1(%rip),%rsi
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x4(%rsp),%edx
cmp    %ebx,%edx
jbe    11d3 <RecvStringFrom+0xa3>
mov    (%r12),%edi
lea    0xf0f(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,0x4(%rsp)
mov    %ebx,%edx
mov    0x0(%r13),%ecx
mov    %r15d,%edi
mov    %r14,%rsi
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11fd <RecvStringFrom+0xcd>
mov    (%r12),%edi
cmp    0x4(%rsp),%ebp
jae    1229 <RecvStringFrom+0xf9>
lea    0xe4f(%rip),%rsi
mov    %ebp,%edx
jmp    1211 <RecvStringFrom+0xe1>
mov    (%r12),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeee(%rip),%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1218 <RecvStringFrom+0xe8>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Trying RecvStringFrom\0A\00"
@MSG_WAITALL = global i32 0
@.str.1 = [49 x i8] c"Error %u while RecvStringFrom the length packet\0A\00"
@errno = global i32 0
@.str.2 = [80 x i8] c"Did not receive the whole length packet ( only %u bytes ) while RecvStringFrom\0A\00"
@.str.3 = [59 x i8] c"Incoming string is %u bytes long ( from peer socket %d ) \0A\00"
@.str.4 = [75 x i8] c"Incoming string will overflow .. clipping it to our buffer size ( %u ).. \0A\00"
@.str.5 = [50 x i8] c"Incoming string is `%s` ( from peer socket %d ) \0A\00"
define i32 @RecvStringFrom(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
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i32 @memset(i8* %13, i32 0, i32 %14)
store i32 0, i32* %8
%16 = load i32, i32* %5
%17 = bitcast i32* %8 to i8*
%18 = load i32, i32* @MSG_WAITALL
%19 = call i32 @recv(i32 %16, i8* %17, i32 4, i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %9
store i32 %26, i32* %4
br label %79
27: ; preds = %3
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = icmp ult i64 %29, 4
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i32, i32* %9
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %9
store i32 %35, i32* %4
br label %79
36: ; preds = %27
br label %37
37: ; preds = %36
%38 = load i32, i32* @stderr
%39 = load i32, i32* %8
%40 = load i32, i32* %5
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %40)
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = icmp ult i32 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = load i32, i32* %7
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %7
store i32 %49, i32* %8
br label %50
50: ; preds = %45, %37
%51 = load i32, i32* %5
%52 = load i8*, i8** %6
%53 = load i32, i32* %8
%54 = load i32, i32* @MSG_WAITALL
%55 = call i32 @recv(i32 %51, i8* %52, i32 %53, i32 %54)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %50
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %10
store i32 %62, i32* %4
br label %79
63: ; preds = %50
%64 = load i32, i32* %10
%65 = load i32, i32* %8
%66 = icmp ult i32 %64, %65
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = load i32, i32* %10
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0), i32 %69)
%71 = load i32, i32* %10
store i32 %71, i32* %4
br label %79
72: ; preds = %63
br label %73
73: ; preds = %72
%74 = load i32, i32* @stderr
%75 = load i8*, i8** %6
%76 = load i32, i32* %5
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %75, i32 %76)
%78 = load i32, i32* %10
store i32 %78, i32* %4
br label %79
79: ; preds = %73, %67, %58, %31, %22
%80 = load i32, i32* %4
ret i32 %80
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Trying RecvStringFrom\0A\00"
@MSG_WAITALL = global i32 0
@.str.1 = [49 x i8] c"Error %u while RecvStringFrom the length packet\0A\00"
@errno = global i32 0
@.str.2 = [80 x i8] c"Did not receive the whole length packet ( only %u bytes ) while RecvStringFrom\0A\00"
@.str.3 = [59 x i8] c"Incoming string is %u bytes long ( from peer socket %d ) \0A\00"
@.str.4 = [75 x i8] c"Incoming string will overflow .. clipping it to our buffer size ( %u ).. \0A\00"
@.str.5 = [50 x i8] c"Incoming string is `%s` ( from peer socket %d ) \0A\00"
define i32 @RecvStringFrom(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = load i32, i32* @MSG_WAITALL
%10 = call i32 @recv(i32 %0, i8* %8, i32 4, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %46
16: ; preds = %3
%17 = icmp ult i32 %10, 4
%18 = load i32, i32* @stderr
br i1 %17, label %19, label %21
19: ; preds = %16
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %46
21: ; preds = %16
%22 = load i32, i32* %4
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %0)
%24 = load i32, i32* %4
%25 = icmp ugt i32 %24, %2
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 %2)
store i32 %2, i32* %4
br label %29
29: ; preds = %26, %21
%30 = phi i32 [ %2, %26 ], [ %24, %21 ]
%31 = load i32, i32* @MSG_WAITALL
%32 = call i32 @recv(i32 %0, i8* %1, i32 %30, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %46
38: ; preds = %29
%39 = load i32, i32* %4
%40 = icmp ult i32 %32, %39
%41 = load i32, i32* @stderr
br i1 %40, label %42, label %44
42: ; preds = %38
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %46
44: ; preds = %38
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %1, i32 %0)
br label %46
46: ; preds = %34, %42, %44, %19, %12
%47 = phi i32 [ %10, %12 ], [ %10, %19 ], [ %32, %44 ], [ %32, %42 ], [ %32, %34 ]
ret i32 %47
}