#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*/ memcpy(unsigned char *, unsigned char const *, int);
size_t last_blocks_correction_nist(const unsigned char *in, unsigned char *out,
                                   size_t len) {
  size_t tail;
  if ((tail = len % 16) == 0)
    tail = 16;
  len -= 16 + tail;
  memcpy(out, in, len);
  memcpy(out + len, in + len + 16, tail);
  memcpy(out + len + tail, in + len, 16);
  len += 16 + tail;
  tail = 16;
  return tail;
}


x86 assembly (clang, -O0):
<last_blocks_correction_nist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
and    $0xf,%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1142 <last_blocks_correction_nist+0x32>
movq   $0x10,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
add    $0x10,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
add    $0x10,%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x10,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_blocks_correction_nist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %r14d,%r13d
and    $0xf,%r13d
test   %r13,%r13
mov    $0x10,%eax
cmove  %rax,%r13
lea    -0x10(%rdx),%rbx
sub    %r13,%rbx
mov    %rsi,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
lea    (%r15,%rbx,1),%rdi
lea    (%r12,%rbx,1),%rbp
lea    (%r12,%rbx,1),%rsi
add    $0x10,%rsi
mov    %r13d,%edx
call   1030 <memcpy@plt>
lea    (%r15,%r14,1),%rdi
add    $0xfffffffffffffff0,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    $0x10,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @last_blocks_correction_nist(i8* %0, i8* %1, i64 %2) {
%4 = and i64 %2, 15
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i64 16, i64 %4
%7 = add i64 %2, -16
%8 = sub i64 %7, %6
%9 = trunc i64 %8 to i32
%10 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %9)
%11 = getelementptr inbounds i8, i8* %1, i64 %8
%12 = getelementptr inbounds i8, i8* %0, i64 %8
%13 = getelementptr inbounds i8, i8* %12, i64 16
%14 = trunc i64 %6 to i32
%15 = tail call i32 @memcpy(i8* %11, i8* %13, i32 %14)
%16 = getelementptr inbounds i8, i8* %1, i64 %7
%17 = tail call i32 @memcpy(i8* %16, i8* %12, i32 16)
ret i64 16
}