#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 */
struct mq_attr {
  int mq_msgsize;
};
typedef int /*<<< orphan*/ mqd_t;

/* Variables and functions */
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
unsigned char *malloc(int);
int /*<<< orphan*/ mq_getattr(int /*<<< orphan*/, struct mq_attr *);
int /*<<< orphan*/ my_mq_send(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ perror(char *);
int recv(int, unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void text_sock2mq(int socket, mqd_t mq) {
  int len;
  unsigned char *buffer;
  struct mq_attr attr;
  mq_getattr(mq, &attr);
  buffer = malloc(attr.mq_msgsize);
  do {
    len = recv(socket, buffer, attr.mq_msgsize, MSG_WAITALL);
    if (len < 0) {
      perror("recv");
      fprintf(stderr, "File %s line %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/luebbers/reconos/refs/heads/master/"
              "demos/huffman_demo/sw/network_io.c",
              30);
      break;
    }
    my_mq_send(mq, buffer, len);
  } while (len == attr.mq_msgsize);
}


x86 assembly (clang, -O0):
<text_sock2mq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <mq_getattr@plt>
mov    -0x20(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    0x2e39(%rip),%rax
mov    (%rax),%ecx
call   1040 <recv@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11dd <text_sock2mq+0x7d>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
lea    0xe48(%rip),%rdx
mov    $0x1e,%ecx
call   1050 <fprintf@plt>
jmp    11f8 <text_sock2mq+0x98>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <my_mq_send@plt>
mov    -0xc(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1186 <text_sock2mq+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_sock2mq>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
call   1080 <mq_getattr@plt>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x2e3c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%ecx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <recv@plt>
test   %eax,%eax
js     11d7 <text_sock2mq+0x77>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <my_mq_send@plt>
cmp    0x8(%rsp),%ebp
je     11a0 <text_sock2mq+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe22(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
lea    0xe1c(%rip),%rdx
mov    $0x1e,%ecx
call   1050 <fprintf@plt>
jmp    11ca <text_sock2mq+0x6a>

LLVM IR (-O0):
%struct.mq_attr = type { i32 }
@MSG_WAITALL = global i32 0
@.str = [5 x i8] c"recv\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"File %s line %d\0A\00"
@.str.2 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/luebbers/reconos/refs/heads/master/demos/huffman_demo/sw/network_io.c\00"
define void @text_sock2mq(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.mq_attr
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = call i32 @mq_getattr(i32 %8, %struct.mq_attr* %7)
%10 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %6
br label %13
13: ; preds = %31, %2
%14 = load i32, i32* %3
%15 = load i8*, i8** %6
%16 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @MSG_WAITALL
%19 = call i32 @recv(i32 %14, i8* %15, i32 %17, i32 %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 30)
br label %36
26: ; preds = %13
%27 = load i32, i32* %4
%28 = load i8*, i8** %6
%29 = load i32, i32* %5
%30 = call i32 @my_mq_send(i32 %27, i8* %28, i32 %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %5
%33 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
%34 = load i32, i32* %33
%35 = icmp eq i32 %32, %34
br i1 %35, label %13, label %36
36: ; preds = %31, %22
ret void
}

LLVM IR (-O2):
%struct.mq_attr = type { i32 }
@MSG_WAITALL = global i32 0
@.str = [5 x i8] c"recv\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"File %s line %d\0A\00"
@.str.2 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/luebbers/reconos/refs/heads/master/demos/huffman_demo/sw/network_io.c\00"
define void @text_sock2mq(i32 %0, i32 %1) {
%3 = alloca %struct.mq_attr
%4 = bitcast %struct.mq_attr* %3 to i8*
%5 = call i32 @mq_getattr(i32 %1, %struct.mq_attr* %3)
%6 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = call i8* @malloc(i32 %7)
br label %9
9: ; preds = %18, %2
%10 = phi i32 [ %12, %18 ], [ %7, %2 ]
%11 = load i32, i32* @MSG_WAITALL
%12 = call i32 @recv(i32 %0, i8* %8, i32 %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 30)
br label %22
18: ; preds = %9
%19 = call i32 @my_mq_send(i32 %1, i8* %8, i32 %12)
%20 = load i32, i32* %6
%21 = icmp eq i32 %12, %20
br i1 %21, label %9, label %22
22: ; preds = %18, %14
ret void
}