#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*/ filladler32(unsigned char *, unsigned int);
int /*<<< orphan*/ memmove(char *, char *, int);
int xorshift128plus();
int auth_sha1_v2_pack_data(char *data, int datalength, char *outdata) {
  unsigned int rand_len = (datalength > 1300  ? 0
                           : datalength > 400 ? (xorshift128plus() & 0x7F)
                                              : (xorshift128plus() & 0x3FF)) +
                          1;
  int out_size = (int)rand_len + datalength + 6;
  outdata[0] = (char)(out_size >> 8);
  outdata[1] = (char)out_size;
  if (rand_len < 128) {
    outdata[2] = (char)rand_len;
  } else {
    outdata[2] = (char)0xFF;
    outdata[3] = (char)(rand_len >> 8);
    outdata[4] = (char)rand_len;
  }
  memmove(outdata + rand_len + 2, data, datalength);
  filladler32((unsigned char *)outdata, (unsigned int)out_size);
  return out_size;
}


x86 assembly (clang, -O0):
<auth_sha1_v2_pack_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x514,-0xc(%rbp)
jle    115a <auth_sha1_v2_pack_data+0x2a>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    118e <auth_sha1_v2_pack_data+0x5e>
cmpl   $0x190,-0xc(%rbp)
jle    1179 <auth_sha1_v2_pack_data+0x49>
mov    $0x0,%al
call   1030 <xorshift128plus@plt>
and    $0x7f,%eax
mov    %eax,-0x28(%rbp)
jmp    1188 <auth_sha1_v2_pack_data+0x58>
mov    $0x0,%al
call   1030 <xorshift128plus@plt>
and    $0x3ff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%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)
cmpl   $0x80,-0x1c(%rbp)
jae    11db <auth_sha1_v2_pack_data+0xab>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
jmp    11fe <auth_sha1_v2_pack_data+0xce>
mov    -0x18(%rbp),%rax
movb   $0xff,0x2(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
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 <filladler32@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<auth_sha1_v2_pack_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
cmp    $0x514,%esi
jg     1164 <auth_sha1_v2_pack_data+0x34>
xor    %eax,%eax
call   1030 <xorshift128plus@plt>
cmp    $0x191,%r14d
jl     115f <auth_sha1_v2_pack_data+0x2f>
and    $0x7f,%eax
jmp    1164 <auth_sha1_v2_pack_data+0x34>
and    $0x3ff,%eax
lea    0x1(%rax),%ecx
lea    (%r14,%rax,1),%ebp
add    $0x7,%ebp
mov    %ebp,%edx
rol    $0x8,%dx
mov    %dx,(%rbx)
cmp    $0x7e,%eax
ja     1180 <auth_sha1_v2_pack_data+0x50>
mov    %ecx,%eax
jmp    118c <auth_sha1_v2_pack_data+0x5c>
mov    %ecx,%eax
rol    $0x8,%ax
mov    %ax,0x3(%rbx)
mov    $0xff,%al
mov    %al,0x2(%rbx)
mov    %ecx,%eax
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <memmove@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <filladler32@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @auth_sha1_v2_pack_data(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 1300
br i1 %10, label %11, label %12
11: ; preds = %3
br label %23
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 400
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 (...) @xorshift128plus()
%17 = and i32 %16, 127
br label %21
18: ; preds = %12
%19 = call i32 (...) @xorshift128plus()
%20 = and i32 %19, 1023
br label %21
21: ; preds = %18, %15
%22 = phi i32 [ %17, %15 ], [ %20, %18 ]
br label %23
23: ; preds = %21, %11
%24 = phi i32 [ 0, %11 ], [ %22, %21 ]
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = load i32, i32* %5
%28 = add nsw i32 %26, %27
%29 = add nsw i32 %28, 6
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = ashr i32 %30, 8
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 %32, i8* %34
%35 = load i32, i32* %8
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8 %36, i8* %38
%39 = load i32, i32* %7
%40 = icmp ult i32 %39, 128
br i1 %40, label %41, label %46
41: ; preds = %23
%42 = load i32, i32* %7
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 2
store i8 %43, i8* %45
br label %58
46: ; preds = %23
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 2
store i8 -1, i8* %48
%49 = load i32, i32* %7
%50 = lshr i32 %49, 8
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i64 3
store i8 %51, i8* %53
%54 = load i32, i32* %7
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 4
store i8 %55, i8* %57
br label %58
58: ; preds = %46, %41
%59 = load i8*, i8** %6
%60 = load i32, i32* %7
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = getelementptr inbounds i8, i8* %62, i64 2
%64 = load i8*, i8** %4
%65 = load i32, i32* %5
%66 = call i32 @memmove(i8* %63, i8* %64, i32 %65)
%67 = load i8*, i8** %6
%68 = load i32, i32* %8
%69 = call i32 @filladler32(i8* %67, i32 %68)
%70 = load i32, i32* %8
ret i32 %70
}

LLVM IR (-O2):
define i32 @auth_sha1_v2_pack_data(i8* %0, i32 %1, i8* %2) {
%4 = icmp sgt i32 %1, 1300
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = icmp sgt i32 %1, 400
%7 = tail call i32 (...) @xorshift128plus()
br i1 %6, label %8, label %10
8: ; preds = %5
%9 = and i32 %7, 127
br label %12
10: ; preds = %5
%11 = and i32 %7, 1023
br label %12
12: ; preds = %8, %10, %3
%13 = phi i32 [ 0, %3 ], [ %9, %8 ], [ %11, %10 ]
%14 = add nuw nsw i32 %13, 1
%15 = add i32 %1, 6
%16 = add i32 %15, %14
%17 = lshr i32 %16, 8
%18 = trunc i32 %17 to i8
store i8 %18, i8* %2
%19 = trunc i32 %16 to i8
%20 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %19, i8* %20
%21 = icmp ult i32 %13, 127
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = trunc i32 %14 to i8
br label %30
24: ; preds = %12
%25 = lshr i32 %14, 8
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %26, i8* %27
%28 = trunc i32 %14 to i8
%29 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %28, i8* %29
br label %30
30: ; preds = %24, %22
%31 = phi i8 [ %23, %22 ], [ -1, %24 ]
%32 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %31, i8* %32
%33 = zext i32 %14 to i64
%34 = getelementptr inbounds i8, i8* %2, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = tail call i32 @memmove(i8* %35, i8* %0, i32 %1)
%37 = tail call i32 @filladler32(i8* %2, i32 %16)
ret i32 %16
}