#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 *, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int xorshift128plus();
int auth_sha1_v2_pack_data(char *data, int datalength, char *outdata) {
  unsigned char rand_len = datalength > 1300  ? 1
                           : datalength > 400 ? (xorshift128plus() & 0x7F) + 1
                                              : (xorshift128plus() & 0x3FF) + 1;
  if (datalength > 1400)
    rand_len = 1;
  int out_size = rand_len + datalength + 6;
  outdata[0] = out_size >> 8;
  outdata[1] = out_size;
  if (rand_len < 128) {
    outdata[2] = rand_len;
  } else {
    outdata[2] = 0xFF;
    outdata[3] = rand_len >> 8;
    outdata[4] = rand_len;
  }
  memmove(outdata + rand_len + 2, data, datalength);
  filladler32((unsigned char *)outdata, 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    115d <auth_sha1_v2_pack_data+0x2d>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1197 <auth_sha1_v2_pack_data+0x67>
cmpl   $0x190,-0xc(%rbp)
jle    117f <auth_sha1_v2_pack_data+0x4f>
mov    $0x0,%al
call   1030 <xorshift128plus@plt>
and    $0x7f,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1191 <auth_sha1_v2_pack_data+0x61>
mov    $0x0,%al
call   1030 <xorshift128plus@plt>
and    $0x3ff,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,-0x19(%rbp)
cmpl   $0x578,-0xc(%rbp)
jle    11ae <auth_sha1_v2_pack_data+0x7e>
movb   $0x1,-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)
movzbl -0x19(%rbp),%eax
cmp    $0x80,%eax
jge    11f3 <auth_sha1_v2_pack_data+0xc3>
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
jmp    1215 <auth_sha1_v2_pack_data+0xe5>
mov    -0x18(%rbp),%rax
movb   $0xff,0x2(%rax)
movzbl -0x19(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x4(%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 <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,%r14
mov    %esi,%ebx
mov    %rdi,%r15
mov    $0x1,%ebp
mov    $0x1,%eax
cmp    $0x514,%esi
jg     116d <auth_sha1_v2_pack_data+0x3d>
xor    %eax,%eax
call   1030 <xorshift128plus@plt>
cmp    $0x191,%ebx
jl     1165 <auth_sha1_v2_pack_data+0x35>
and    $0x7f,%eax
jmp    116a <auth_sha1_v2_pack_data+0x3a>
and    $0x3ff,%eax
add    $0x1,%eax
cmp    $0x579,%ebx
cmovge %ebp,%eax
movzbl %al,%ecx
lea    (%rbx,%rcx,1),%ebp
add    $0x6,%ebp
mov    %ebp,%edx
rol    $0x8,%dx
mov    %dx,(%r14)
test   %cl,%cl
jns    1198 <auth_sha1_v2_pack_data+0x68>
movb   $0x0,0x3(%r14)
mov    %al,0x4(%r14)
mov    $0xff,%al
mov    %al,0x2(%r14)
lea    (%r14,%rcx,1),%rdi
add    $0x2,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memmove@plt>
mov    %r14,%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 i8
%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 %25
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 400
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = call i32 (...) @xorshift128plus()
%17 = and i32 %16, 127
%18 = add nsw i32 %17, 1
br label %23
19: ; preds = %12
%20 = call i32 (...) @xorshift128plus()
%21 = and i32 %20, 1023
%22 = add nsw i32 %21, 1
br label %23
23: ; preds = %19, %15
%24 = phi i32 [ %18, %15 ], [ %22, %19 ]
br label %25
25: ; preds = %23, %11
%26 = phi i32 [ 1, %11 ], [ %24, %23 ]
%27 = trunc i32 %26 to i8
store i8 %27, i8* %7
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 1400
br i1 %29, label %30, label %31
30: ; preds = %25
store i8 1, i8* %7
br label %31
31: ; preds = %30, %25
%32 = load i8, i8* %7
%33 = zext i8 %32 to i32
%34 = load i32, i32* %5
%35 = add nsw i32 %33, %34
%36 = add nsw i32 %35, 6
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = ashr i32 %37, 8
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 0
store i8 %39, i8* %41
%42 = load i32, i32* %8
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8 %43, i8* %45
%46 = load i8, i8* %7
%47 = zext i8 %46 to i32
%48 = icmp slt i32 %47, 128
br i1 %48, label %49, label %53
49: ; preds = %31
%50 = load i8, i8* %7
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i64 2
store i8 %50, i8* %52
br label %65
53: ; preds = %31
%54 = load i8*, i8** %6
%55 = getelementptr inbounds i8, i8* %54, i64 2
store i8 -1, i8* %55
%56 = load i8, i8* %7
%57 = zext i8 %56 to i32
%58 = ashr i32 %57, 8
%59 = trunc i32 %58 to i8
%60 = load i8*, i8** %6
%61 = getelementptr inbounds i8, i8* %60, i64 3
store i8 %59, i8* %61
%62 = load i8, i8* %7
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i64 4
store i8 %62, i8* %64
br label %65
65: ; preds = %53, %49
%66 = load i8*, i8** %6
%67 = load i8, i8* %7
%68 = zext i8 %67 to i32
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %66, i64 %69
%71 = getelementptr inbounds i8, i8* %70, i64 2
%72 = load i8*, i8** %4
%73 = load i32, i32* %5
%74 = call i32 @memmove(i8* %71, i8* %72, i32 %73)
%75 = load i8*, i8** %6
%76 = load i32, i32* %8
%77 = call i32 @filladler32(i8* %75, i32 %76)
%78 = load i32, i32* %8
ret i32 %78
}

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 %14, label %5
5: ; preds = %3
%6 = icmp sgt i32 %1, 400
%7 = tail call i32 (...) @xorshift128plus()
br i1 %6, label %8, label %11
8: ; preds = %5
%9 = and i32 %7, 127
%10 = add nuw nsw i32 %9, 1
br label %14
11: ; preds = %5
%12 = and i32 %7, 1023
%13 = add nuw nsw i32 %12, 1
br label %14
14: ; preds = %8, %11, %3
%15 = phi i32 [ 1, %3 ], [ %10, %8 ], [ %13, %11 ]
%16 = trunc i32 %15 to i8
%17 = icmp sgt i32 %1, 1400
%18 = select i1 %17, i8 1, i8 %16
%19 = zext i8 %18 to i32
%20 = add i32 %1, 6
%21 = add i32 %20, %19
%22 = lshr i32 %21, 8
%23 = trunc i32 %22 to i8
store i8 %23, i8* %2
%24 = trunc i32 %21 to i8
%25 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %24, i8* %25
%26 = icmp sgt i8 %18, -1
br i1 %26, label %30, label %27
27: ; preds = %14
%28 = getelementptr inbounds i8, i8* %2, i64 3
store i8 0, i8* %28
%29 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %18, i8* %29
br label %30
30: ; preds = %14, %27
%31 = phi i8 [ -1, %27 ], [ %18, %14 ]
%32 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %31, i8* %32
%33 = zext i8 %18 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 %21)
ret i32 %21
}