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

/* Variables and functions */
int /*<<< orphan*/ MSG_WAITALL;
char *calloc(int, int);
int /*<<< orphan*/ recv(int, ...);
int /*<<< orphan*/ sendpacked(int, int, int, int, char *, char *);
char *strdup(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int cmc_collectionsforuser(int sock, char *_user, char **_collections) {
  char user[512];
  int n;
  char *collections;
  strncpy(user, _user, sizeof(user));
  sendpacked(sock, 6, 1, sizeof(user), user, "");
  recv(sock, &n, sizeof(n), MSG_WAITALL);
  if (n == 0) {
    collections = strdup("");
  } else {
    collections = calloc(n, 512 + 1);
    recv(sock, collections, (512 + 1) * n, MSG_WAITALL);
  }
  *_collections = collections;
  return n;
}


x86 assembly (clang, -O0):
<cmc_collectionsforuser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1040 <strncpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x220(%rbp),%r8
mov    $0x6,%esi
mov    $0x1,%edx
mov    $0x200,%ecx
lea    0xe65(%rip),%r9
call   1060 <sendpacked@plt>
mov    -0x4(%rbp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%ecx
lea    -0x224(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <recv@plt>
cmpl   $0x0,-0x224(%rbp)
jne    11e4 <cmc_collectionsforuser+0x94>
lea    0xe2d(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x230(%rbp)
jmp    121f <cmc_collectionsforuser+0xcf>
mov    -0x224(%rbp),%edi
mov    $0x201,%esi
call   1050 <calloc@plt>
mov    %rax,-0x230(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x230(%rbp),%rsi
imul   $0x201,-0x224(%rbp),%edx
mov    0x2dc2(%rip),%rax
mov    (%rax),%ecx
mov    $0x0,%al
call   1030 <recv@plt>
mov    -0x230(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x224(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmc_collectionsforuser>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%r14
mov    %edi,%r15d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%edx
call   1040 <strncpy@plt>
lea    0xe80(%rip),%r9
mov    %r15d,%edi
mov    $0x6,%esi
mov    $0x1,%edx
mov    $0x200,%ecx
mov    %rbx,%r8
call   1060 <sendpacked@plt>
mov    0x2e37(%rip),%r13
mov    0x0(%r13),%ecx
xor    %r12d,%r12d
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <recv@plt>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
je     11f2 <cmc_collectionsforuser+0xa2>
mov    %ebx,%edi
mov    $0x201,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
mov    %ebx,%edx
shl    $0x9,%edx
add    %ebx,%edx
mov    0x0(%r13),%ecx
mov    %r15d,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <recv@plt>
mov    0xc(%rsp),%r12d
jmp    1201 <cmc_collectionsforuser+0xb1>
lea    0xe07(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rbp
mov    %rbp,(%r14)
mov    %r12d,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@MSG_WAITALL = global i32 0
define i32 @cmc_collectionsforuser(i32 %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 512)
%13 = load i32, i32* %4
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%15 = call i32 @sendpacked(i32 %13, i32 6, i32 1, i32 512, i8* %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = load i32, i32* @MSG_WAITALL
%18 = call i32 (i32, ...) @recv(i32 %16, i32* %8, i64 4, i32 %17)
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %9
br label %32
23: ; preds = %3
%24 = load i32, i32* %8
%25 = call i8* @calloc(i32 %24, i32 513)
store i8* %25, i8** %9
%26 = load i32, i32* %4
%27 = load i8*, i8** %9
%28 = load i32, i32* %8
%29 = mul nsw i32 513, %28
%30 = load i32, i32* @MSG_WAITALL
%31 = call i32 (i32, ...) @recv(i32 %26, i8* %27, i32 %29, i32 %30)
br label %32
32: ; preds = %23, %21
%33 = load i8*, i8** %9
%34 = load i8**, i8*** %6
store i8* %33, i8** %34
%35 = load i32, i32* %8
ret i32 %35
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@MSG_WAITALL = global i32 0
define i32 @cmc_collectionsforuser(i32 %0, i8* %1, i8** nocapture writeonly %2) {
%4 = alloca [512 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = call i32 @strncpy(i8* %6, i8* %1, i32 512)
%9 = call i32 @sendpacked(i32 %0, i32 6, i32 1, i32 512, i8* %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @MSG_WAITALL
%11 = call i32 (i32, ...) @recv(i32 %0, i32* %5, i64 4, i32 %10)
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %22
16: ; preds = %3
%17 = call i8* @calloc(i32 %12, i32 513)
%18 = mul nsw i32 %12, 513
%19 = load i32, i32* @MSG_WAITALL
%20 = call i32 (i32, ...) @recv(i32 %0, i8* %17, i32 %18, i32 %19)
%21 = load i32, i32* %5
br label %22
22: ; preds = %16, %14
%23 = phi i32 [ 0, %14 ], [ %21, %16 ]
%24 = phi i8* [ %15, %14 ], [ %17, %16 ]
store i8* %24, i8** %2
ret i32 %23
}