#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 size_t uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
size_t ece_plaintext_max_length(uint32_t rs, size_t padSize,
                                size_t ciphertextLen) {
  assert(padSize <= 2);
  size_t overhead = padSize + 16;
  if (rs <= overhead) {
    return 0;
  }
  size_t numRecords = ciphertextLen / rs;
  if (ciphertextLen % rs) {
    numRecords++;
  }
  if (numRecords > ciphertextLen / 16) {
    return 0;
  }
  return ciphertextLen - (16 * numRecords);
}


x86 assembly (clang, -O0):
<ece_plaintext_max_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x2,-0x18(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
ja     115d <ece_plaintext_max_length+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <ece_plaintext_max_length+0xb4>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
cmp    $0x0,%rdx
je     118f <ece_plaintext_max_length+0x7f>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x4,%rcx
cmp    %rcx,%rax
jbe    11b1 <ece_plaintext_max_length+0xa1>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <ece_plaintext_max_length+0xb4>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x4,%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ece_plaintext_max_length>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edi,%edi
cmp    $0x3,%rsi
setb   %dil
call   1030 <assert@plt>
add    $0x10,%rbx
cmp    %r15,%rbx
jae    114c <ece_plaintext_max_length+0x3c>
mov    %r14,%rax
or     %r15,%rax
shr    $0x20,%rax
je     1150 <ece_plaintext_max_length+0x40>
mov    %r14,%rax
xor    %edx,%edx
div    %r15
jmp    1158 <ece_plaintext_max_length+0x48>
xor    %ecx,%ecx
jmp    117a <ece_plaintext_max_length+0x6a>
mov    %r14d,%eax
xor    %edx,%edx
div    %r15d
cmp    $0x1,%rdx
sbb    $0xffffffffffffffff,%rax
mov    %r14,%rdx
shr    $0x4,%rdx
mov    %rax,%rcx
shl    $0x4,%rcx
sub    %rcx,%r14
xor    %ecx,%ecx
cmp    %rdx,%rax
cmovbe %r14,%rcx
mov    %rcx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @ece_plaintext_max_length(i64 %0, i64 %1, i64 %2) {
%4 = icmp ult i64 %1, 3
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = add i64 %1, 16
%8 = icmp ult i64 %7, %0
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = udiv i64 %2, %0
%11 = urem i64 %2, %0
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i64
%14 = add i64 %10, %13
%15 = lshr i64 %2, 4
%16 = icmp ugt i64 %14, %15
%17 = mul i64 %14, -16
%18 = add i64 %17, %2
%19 = select i1 %16, i64 0, i64 %18
br label %20
20: ; preds = %3, %9
%21 = phi i64 [ %19, %9 ], [ 0, %3 ]
ret i64 %21
}