#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 */
size_t SIZE_MAX;
bool _try_load_flex_struct_size(size_t struct_size, size_t fam_type_size,
                                size_t fam_offset, size_t fam_length,
                                size_t *size_handle) {
  if (SIZE_MAX / fam_type_size < fam_length)
    return false;
  if ((SIZE_MAX - fam_offset) < (fam_type_size * fam_length))
    return false;
  const size_t fam_size = fam_type_size * fam_length;
  *size_handle = ((fam_offset + fam_size) < struct_size)
                     ? struct_size
                     : fam_offset + fam_size;
  return true;
}


x86 assembly (clang, -O0):
<_try_load_flex_struct_size>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    0x2eb9(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    -0x28(%rbp),%rax
jae    1140 <_try_load_flex_struct_size+0x40>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <_try_load_flex_struct_size+0xb6>
mov    0x2e91(%rip),%rax
mov    (%rax),%rax
sub    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
imul   -0x28(%rbp),%rcx
cmp    %rcx,%rax
jae    116c <_try_load_flex_struct_size+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <_try_load_flex_struct_size+0xb6>
mov    -0x18(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1198 <_try_load_flex_struct_size+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11a4 <_try_load_flex_struct_size+0xa4>
mov    -0x20(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_try_load_flex_struct_size>:
mov    %rdx,%r9
mov    0x2ece(%rip),%rax
mov    (%rax),%r10
mov    %r10,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1126 <_try_load_flex_struct_size+0x26>
mov    %r10,%rax
xor    %edx,%edx
div    %rsi
mov    %rax,%rdx
jmp    112f <_try_load_flex_struct_size+0x2f>
mov    %r10d,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%edx
xor    %eax,%eax
cmp    %rcx,%rdx
jb     1154 <_try_load_flex_struct_size+0x54>
sub    %r9,%r10
imul   %rsi,%rcx
cmp    %rcx,%r10
jb     1154 <_try_load_flex_struct_size+0x54>
add    %r9,%rcx
cmp    %rdi,%rcx
cmovb  %rdi,%rcx
mov    %rcx,(%r8)
mov    $0x1,%eax
ret

LLVM IR (-O0):
@SIZE_MAX = global i64 0
define i32 @_try_load_flex_struct_size(i64 %0, i64 %1, i64 %2, i64 %3, i64* %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64*
%12 = alloca i64
store i64 %0, i64* %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64* %4, i64** %11
%13 = load i64, i64* @SIZE_MAX
%14 = load i64, i64* %8
%15 = udiv i64 %13, %14
%16 = load i64, i64* %10
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %5
store i32 0, i32* %6
br label %46
19: ; preds = %5
%20 = load i64, i64* @SIZE_MAX
%21 = load i64, i64* %9
%22 = sub i64 %20, %21
%23 = load i64, i64* %8
%24 = load i64, i64* %10
%25 = mul i64 %23, %24
%26 = icmp ult i64 %22, %25
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 0, i32* %6
br label %46
28: ; preds = %19
%29 = load i64, i64* %8
%30 = load i64, i64* %10
%31 = mul i64 %29, %30
store i64 %31, i64* %12
%32 = load i64, i64* %9
%33 = load i64, i64* %12
%34 = add i64 %32, %33
%35 = load i64, i64* %7
%36 = icmp ult i64 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = load i64, i64* %7
br label %43
39: ; preds = %28
%40 = load i64, i64* %9
%41 = load i64, i64* %12
%42 = add i64 %40, %41
br label %43
43: ; preds = %39, %37
%44 = phi i64 [ %38, %37 ], [ %42, %39 ]
%45 = load i64*, i64** %11
store i64 %44, i64* %45
store i32 1, i32* %6
br label %46
46: ; preds = %43, %27, %18
%47 = load i32, i32* %6
ret i32 %47
}

LLVM IR (-O2):
@SIZE_MAX = global i64 0
define i32 @_try_load_flex_struct_size(i64 %0, i64 %1, i64 %2, i64 %3, i64* nocapture writeonly %4) {
%6 = load i64, i64* @SIZE_MAX
%7 = udiv i64 %6, %1
%8 = icmp ult i64 %7, %3
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = sub i64 %6, %2
%11 = mul i64 %3, %1
%12 = icmp ult i64 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = add i64 %11, %2
%15 = icmp ult i64 %14, %0
%16 = select i1 %15, i64 %0, i64 %14
store i64 %16, i64* %4
br label %17
17: ; preds = %9, %5, %13
%18 = phi i32 [ 1, %13 ], [ 0, %5 ], [ 0, %9 ]
ret i32 %18
}