#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int get_message_size(int);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *recv_all(int, int);
char *get_message_body(int connected_socket, uint32_t *message_size) {
  uint32_t size = get_message_size(connected_socket);
  if (message_size) {
    *message_size = size;
  }
  char *buff = malloc(size + 1);
  char *msg_body = recv_all(connected_socket, size);
  memcpy(buff, msg_body, size);
  free(msg_body);
  buff[size] = '\0';
  return buff;
}


x86 assembly (clang, -O0):
<get_message_body>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <get_message_size@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117e <get_message_body+0x2e>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <recv_all@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_message_body>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %edi,%r14d
call   1070 <get_message_size@plt>
mov    %eax,%ebx
test   %rbp,%rbp
je     1169 <get_message_body+0x19>
mov    %ebx,0x0(%rbp)
lea    0x1(%rbx),%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %r14d,%edi
mov    %ebx,%esi
call   1040 <recv_all@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
movslq %ebx,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @get_message_body(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = load i32, i32* %3
%9 = call i32 @get_message_size(i32 %8)
store i32 %9, i32* %5
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %5
%14 = load i32*, i32** %4
store i32 %13, i32* %14
br label %15
15: ; preds = %12, %2
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %6
%19 = load i32, i32* %3
%20 = load i32, i32* %5
%21 = call i8* @recv_all(i32 %19, i32 %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = load i32, i32* %5
%25 = call i32 @memcpy(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %7
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %6
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %6
ret i8* %32
}

LLVM IR (-O2):
define i8* @get_message_body(i32 %0, i32* writeonly %1) {
%3 = tail call i32 @get_message_size(i32 %0)
%4 = icmp eq i32* %1, null
br i1 %4, label %6, label %5
5: ; preds = %2
store i32 %3, i32* %1
br label %6
6: ; preds = %5, %2
%7 = add nsw i32 %3, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i8* @recv_all(i32 %0, i32 %3)
%10 = tail call i32 @memcpy(i8* %8, i8* %9, i32 %3)
%11 = tail call i32 @free(i8* %9)
%12 = sext i32 %3 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
store i8 0, i8* %13
ret i8* %8
}