#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 CHY_I64_C(int);
size_t Memory_oversize(size_t minimum, size_t width) {
  size_t extra = minimum / 8;
  if (extra < 3) {
    extra = 3;
  }
  size_t amount = minimum + extra;
  if (amount + 7 < minimum) {
    return ((size_t)-1);
  }
  if (sizeof(size_t) == 8) {
    switch (width) {
    case 1:
      amount = (amount + 7) & CHY_I64_C(0xFFFFFFFFFFFFFFF8);
      break;
    case 2:
      amount = (amount + 3) & CHY_I64_C(0xFFFFFFFFFFFFFFFC);
      break;
    case 4:
      amount = (amount + 1) & CHY_I64_C(0xFFFFFFFFFFFFFFFE);
      break;
    default:
      break;
    }
  } else {
    switch (width) {
    case 1:
      amount = (amount + 3) & ((size_t)0xFFFFFFFC);
      break;
    case 2:
      amount = (amount + 1) & ((size_t)0xFFFFFFFE);
      break;
    default:
      break;
    }
  }
  return amount;
}


x86 assembly (clang, -O0):
<Memory_oversize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x3,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x3,-0x20(%rbp)
jae    113f <Memory_oversize+0x2f>
movq   $0x3,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x7,%rax
cmp    -0x10(%rbp),%rax
jae    116a <Memory_oversize+0x5a>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    122f <Memory_oversize+0x11f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
sub    $0x1,%rax
je     11a7 <Memory_oversize+0x97>
jmp    1181 <Memory_oversize+0x71>
mov    -0x30(%rbp),%rax
sub    $0x2,%rax
je     11d0 <Memory_oversize+0xc0>
jmp    1194 <Memory_oversize+0x84>
mov    -0x30(%rbp),%rax
sub    $0x4,%rax
je     11f9 <Memory_oversize+0xe9>
jmp    1222 <Memory_oversize+0x112>
mov    -0x28(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x38(%rbp)
mov    $0xfffffff8,%edi
call   1030 <CHY_I64_C@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1227 <Memory_oversize+0x117>
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    $0xfffffffc,%edi
call   1030 <CHY_I64_C@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1227 <Memory_oversize+0x117>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    $0xfffffffe,%edi
call   1030 <CHY_I64_C@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1227 <Memory_oversize+0x117>
jmp    1227 <Memory_oversize+0x117>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Memory_oversize>:
push   %rbx
mov    %rdi,%rax
shr    $0x3,%rax
cmp    $0x4,%rax
mov    $0x3,%ecx
cmovae %rax,%rcx
lea    (%rcx,%rdi,1),%rbx
add    $0x7,%rbx
mov    $0xffffffffffffffff,%rax
cmp    %rdi,%rbx
jb     1174 <Memory_oversize+0x64>
cmp    $0x1,%rsi
je     1159 <Memory_oversize+0x49>
add    %rdi,%rcx
cmp    $0x4,%rsi
je     1160 <Memory_oversize+0x50>
cmp    $0x2,%rsi
jne    1176 <Memory_oversize+0x66>
add    $0x3,%rcx
mov    $0xfffffffc,%edi
jmp    1169 <Memory_oversize+0x59>
mov    $0xfffffff8,%edi
jmp    116c <Memory_oversize+0x5c>
add    $0x1,%rcx
mov    $0xfffffffe,%edi
mov    %rcx,%rbx
call   1030 <CHY_I64_C@plt>
and    %rbx,%rax
pop    %rbx
ret
mov    %rcx,%rax
pop    %rbx
ret

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

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