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

/* Variables and functions */
size_t ece_aes128gcm_payload_max_length(uint32_t rs, size_t padLen,
                                        size_t plaintextLen) {
  if (rs < 18) {
    return 0;
  }
  size_t overhead = 18 - 1;
  size_t dataLen = plaintextLen + padLen;
  size_t dataPerBlock = rs - overhead;
  size_t numRecords = (dataLen / dataPerBlock) + 1;
  return 21 + 255 + dataLen + (overhead * numRecords);
}


x86 assembly (clang, -O0):
<ece_aes128gcm_payload_max_length>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x12,-0xc(%rbp)
jge    1126 <ece_aes128gcm_payload_max_length+0x26>
movq   $0x0,-0x8(%rbp)
jmp    1174 <ece_aes128gcm_payload_max_length+0x74>
movq   $0x11,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movslq -0xc(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x38(%rbp)
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
add    $0x114,%rax
mov    -0x28(%rbp),%rcx
imul   -0x40(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ece_aes128gcm_payload_max_length>:
cmp    $0x12,%edi
jge    1108 <ece_aes128gcm_payload_max_length+0x8>
xor    %eax,%eax
ret
mov    %rdx,%rcx
add    %rsi,%rcx
mov    %edi,%esi
add    $0xffffffffffffffef,%rsi
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     112a <ece_aes128gcm_payload_max_length+0x2a>
mov    %rcx,%rax
xor    %edx,%edx
div    %rsi
jmp    1130 <ece_aes128gcm_payload_max_length+0x30>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %rax,%rdx
shl    $0x4,%rdx
add    %rax,%rdx
lea    (%rcx,%rdx,1),%rax
add    $0x125,%rax
ret

LLVM IR (-O0):
define i64 @ece_aes128gcm_payload_max_length(i32 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 %0, i32* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 18
br i1 %13, label %14, label %15
14: ; preds = %3
store i64 0, i64* %4
br label %33
15: ; preds = %3
store i64 17, i64* %8
%16 = load i64, i64* %7
%17 = load i64, i64* %6
%18 = add i64 %16, %17
store i64 %18, i64* %9
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = load i64, i64* %8
%22 = sub i64 %20, %21
store i64 %22, i64* %10
%23 = load i64, i64* %9
%24 = load i64, i64* %10
%25 = udiv i64 %23, %24
%26 = add i64 %25, 1
store i64 %26, i64* %11
%27 = load i64, i64* %9
%28 = add i64 276, %27
%29 = load i64, i64* %8
%30 = load i64, i64* %11
%31 = mul i64 %29, %30
%32 = add i64 %28, %31
store i64 %32, i64* %4
br label %33
33: ; preds = %15, %14
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
define i64 @ece_aes128gcm_payload_max_length(i32 %0, i64 %1, i64 %2) {
%4 = icmp slt i32 %0, 18
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = add i64 %2, %1
%7 = zext i32 %0 to i64
%8 = add nsw i64 %7, -17
%9 = udiv i64 %6, %8
%10 = mul i64 %9, 17
%11 = add i64 %6, 293
%12 = add i64 %11, %10
br label %13
13: ; preds = %3, %5
%14 = phi i64 [ %12, %5 ], [ 0, %3 ]
ret i64 %14
}