#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 */
int /*<<< orphan*/ fillcrc32(unsigned char *, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int xorshift128plus();
int auth_simple_pack_data(char *data, int datalength, char *outdata) {
  unsigned char rand_len = (xorshift128plus() & 0xF) + 1;
  int out_size = rand_len + datalength + 6;
  outdata[0] = out_size >> 8;
  outdata[1] = out_size;
  outdata[2] = rand_len;
  memmove(outdata + rand_len + 2, data, datalength);
  fillcrc32((unsigned char *)outdata, out_size);
  return out_size;
}


x86 assembly (clang, -O0):
<auth_simple_pack_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <xorshift128plus@plt>
and    $0xf,%eax
add    $0x1,%eax
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
add    -0xc(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%rdi
movzbl -0x19(%rbp),%eax
cltq
add    %rax,%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memmove@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <fillcrc32@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<auth_simple_pack_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <xorshift128plus@plt>
mov    %eax,%ecx
and    $0xf,%cl
add    $0x1,%cl
movzbl %cl,%ecx
lea    (%r14,%rcx,1),%ebx
add    $0x6,%ebx
mov    %bh,0x0(%rbp)
mov    %bl,0x1(%rbp)
mov    %cl,0x2(%rbp)
and    $0xf,%eax
lea    (%rax,%rbp,1),%rdi
add    $0x3,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <memmove@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <fillcrc32@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @auth_simple_pack_data(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = call i32 (...) @xorshift128plus()
%10 = and i32 %9, 15
%11 = add nsw i32 %10, 1
%12 = trunc i32 %11 to i8
store i8 %12, i8* %7
%13 = load i8, i8* %7
%14 = zext i8 %13 to i32
%15 = load i32, i32* %5
%16 = add nsw i32 %14, %15
%17 = add nsw i32 %16, 6
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = ashr i32 %18, 8
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 %20, i8* %22
%23 = load i32, i32* %8
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %24, i8* %26
%27 = load i8, i8* %7
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 2
store i8 %27, i8* %29
%30 = load i8*, i8** %6
%31 = load i8, i8* %7
%32 = zext i8 %31 to i32
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = call i32 @memmove(i8* %35, i8* %36, i32 %37)
%39 = load i8*, i8** %6
%40 = load i32, i32* %8
%41 = call i32 @fillcrc32(i8* %39, i32 %40)
%42 = load i32, i32* %8
ret i32 %42
}

LLVM IR (-O2):
define i32 @auth_simple_pack_data(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 (...) @xorshift128plus()
%5 = trunc i32 %4 to i8
%6 = and i8 %5, 15
%7 = add nuw nsw i8 %6, 1
%8 = zext i8 %7 to i32
%9 = add i32 %1, 6
%10 = add i32 %9, %8
%11 = lshr i32 %10, 8
%12 = trunc i32 %11 to i8
store i8 %12, i8* %2
%13 = trunc i32 %10 to i8
%14 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %13, i8* %14
%15 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %7, i8* %15
%16 = zext i8 %7 to i64
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 2
%19 = tail call i32 @memmove(i8* %18, i8* %0, i32 %1)
%20 = tail call i32 @fillcrc32(i8* %2, i32 %10)
ret i32 %10
}