#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void lwe_crossround2(unsigned char *out, const uint16_t *in) {
  int i;
  memset((unsigned char *)out, 0, (((8 * 8) + (8) - 1) / 8));
  uint16_t whole = 1 << (15 - 4);
  uint16_t half = whole >> 1;
  uint16_t mask = whole - 1;
  for (i = 0; i < 8 * 8; i++) {
    uint16_t remainder = in[i] & mask;
    out[i / 8] += (remainder >= half) << (i % 8);
  }
}


x86 assembly (clang, -O0):
<lwe_crossround2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
movl   $0x800,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x40,-0x14(%rbp)
jge    11bb <lwe_crossround2+0xab>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setge  %al
and    $0x1,%al
movzbl %al,%esi
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
shl    %cl,%esi
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
add    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <lwe_crossround2+0x40>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lwe_crossround2>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
nopl   0x0(%rax)
mov    (%r14,%rbx,4),%eax
shr    $0xa,%eax
and    $0x1,%eax
mov    %ebx,%ecx
and    $0x6,%cl
shl    %cl,%eax
mov    %ebx,%edx
shr    $0x3,%edx
add    (%r15,%rdx,1),%al
mov    %al,(%r15,%rdx,1)
mov    0x4(%r14,%rbx,4),%esi
shr    $0xa,%esi
and    $0x1,%esi
lea    0x1(%rbx),%ecx
and    $0x7,%cl
shl    %cl,%esi
add    %al,%sil
mov    %sil,(%r15,%rdx,1)
add    $0x2,%rbx
cmp    $0x40,%rbx
jne    1130 <lwe_crossround2+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @lwe_crossround2(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%10 = load i8*, i8** %3
%11 = call i32 @memset(i8* %10, i32 0, i32 8)
store i32 2048, i32* %6
%12 = load i32, i32* %6
%13 = ashr i32 %12, 1
store i32 %13, i32* %7
%14 = load i32, i32* %6
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %8
store i32 0, i32* %5
br label %16
16: ; preds = %43, %2
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 64
br i1 %18, label %19, label %46
19: ; preds = %16
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32, i32* %8
%26 = and i32 %24, %25
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = load i32, i32* %7
%29 = icmp sge i32 %27, %28
%30 = zext i1 %29 to i32
%31 = load i32, i32* %5
%32 = srem i32 %31, 8
%33 = shl i32 %30, %32
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = sdiv i32 %35, 8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = add nsw i32 %40, %33
%42 = trunc i32 %41 to i8
store i8 %42, i8* %38
br label %43
43: ; preds = %19
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %16
46: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @lwe_crossround2(i8* %0, i32* nocapture %1) {
%3 = tail call i32 @memset(i8* %0, i32 0, i32 8)
br label %4
4: ; preds = %4, %2
%5 = phi i64 [ 0, %2 ], [ %33, %4 ]
%6 = getelementptr inbounds i32, i32* %1, i64 %5
%7 = load i32, i32* %6
%8 = lshr i32 %7, 10
%9 = and i32 %8, 1
%10 = trunc i64 %5 to i32
%11 = and i32 %10, 6
%12 = shl nuw nsw i32 %9, %11
%13 = lshr i64 %5, 3
%14 = and i64 %13, 536870911
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = trunc i32 %12 to i8
%18 = add i8 %16, %17
store i8 %18, i8* %15
%19 = or i64 %5, 1
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = lshr i32 %21, 10
%23 = and i32 %22, 1
%24 = trunc i64 %19 to i32
%25 = and i32 %24, 7
%26 = shl nuw nsw i32 %23, %25
%27 = lshr i64 %5, 3
%28 = and i64 %27, 536870911
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = trunc i32 %26 to i8
%32 = add i8 %30, %31
store i8 %32, i8* %29
%33 = add nuw nsw i64 %5, 2
%34 = icmp eq i64 %33, 64
br i1 %34, label %35, label %4
35: ; preds = %4
ret void
}