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

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int recv(int, char **, int, int /*<<< orphan*/);
char *recv_str(int socket) {
  char buff[255];
  int buff_sz;
  char *ptr;
  buff_sz = recv(socket, &buff, 254, 0);
  buff[(buff_sz - 2)] = '\0';
  ptr = (char *)malloc(sizeof(char) * (buff_sz + 1));
  memcpy(ptr, buff, (buff_sz + 1));
  return ptr;
}


x86 assembly (clang, -O0):
<recv_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xfe,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
mov    -0x114(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x120(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_str>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsp,%r14
mov    %r14,%rsi
mov    $0xfe,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movslq %eax,%rbx
movb   $0x0,-0x2(%rbx,%r14,1)
add    $0x1,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %r15,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @recv_str(i32 %0) {
%2 = alloca i32
%3 = alloca [255 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = bitcast [255 x i8]* %3 to i8**
%8 = call i32 @recv(i32 %6, i8** %7, i32 254, i32 0)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 %11
store i8 0, i8* %12
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
%24 = call i32 @memcpy(i8* %20, i8* %21, i32 %23)
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
define i8* @recv_str(i32 %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = bitcast [255 x i8]* %2 to i8**
%5 = call i32 @recv(i32 %0, i8** %4, i32 254, i32 0)
%6 = add nsw i32 %5, -2
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %8
%9 = add nsw i32 %5, 1
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @memcpy(i8* %11, i8* %3, i32 %9)
ret i8* %11
}