#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 */
long roundUpDiv(long, long);
long chunkSize(long cC, long iC, long cN) {
  long r;
  if (cN < 1 || cN > cC)
    r = 0;
  else if (cN > iC / roundUpDiv(iC, cC))
    r = iC - (cN - 1) * roundUpDiv(iC, cC);
  else
    r = roundUpDiv(iC, cC);
  return r;
}


x86 assembly (clang, -O0):
<chunkSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jl     113d <chunkSize+0x2d>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jle    114a <chunkSize+0x3a>
movq   $0x0,-0x20(%rbp)
jmp    11d5 <chunkSize+0xc5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <roundUpDiv@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jle    11bf <chunkSize+0xaf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <roundUpDiv@plt>
mov    -0x40(%rbp),%rcx
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
imul   %rdx,%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11d0 <chunkSize+0xc0>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <roundUpDiv@plt>
mov    %rax,-0x20(%rbp)
jmp    11d5 <chunkSize+0xc5>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chunkSize>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
test   %rdx,%rdx
jle    1167 <chunkSize+0x57>
mov    %rdx,%rbx
mov    %rdi,%r15
cmp    %rdi,%rdx
jg     1167 <chunkSize+0x57>
mov    %rsi,%r14
mov    %rsi,%rdi
mov    %r15,%rsi
call   1030 <roundUpDiv@plt>
mov    %rax,%rcx
or     %r14,%rax
shr    $0x20,%rax
je     116d <chunkSize+0x5d>
mov    %r14,%rax
cqto
idiv   %rcx
cmp    %rbx,%rax
jge    1179 <chunkSize+0x69>
add    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <roundUpDiv@plt>
imul   %rbx,%rax
sub    %rax,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14d,%eax
xor    %edx,%edx
div    %ecx
cmp    %rbx,%rax
jl     114e <chunkSize+0x3e>
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <roundUpDiv@plt>

LLVM IR (-O0):
define i64 @chunkSize(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = icmp slt i64 %8, 1
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = load i64, i64* %6
%12 = load i64, i64* %4
%13 = icmp sgt i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10, %3
store i64 0, i64* %7
br label %37
15: ; preds = %10
%16 = load i64, i64* %6
%17 = load i64, i64* %5
%18 = load i64, i64* %5
%19 = load i64, i64* %4
%20 = call i64 @roundUpDiv(i64 %18, i64 %19)
%21 = sdiv i64 %17, %20
%22 = icmp sgt i64 %16, %21
br i1 %22, label %23, label %32
23: ; preds = %15
%24 = load i64, i64* %5
%25 = load i64, i64* %6
%26 = sub nsw i64 %25, 1
%27 = load i64, i64* %5
%28 = load i64, i64* %4
%29 = call i64 @roundUpDiv(i64 %27, i64 %28)
%30 = mul nsw i64 %26, %29
%31 = sub nsw i64 %24, %30
store i64 %31, i64* %7
br label %36
32: ; preds = %15
%33 = load i64, i64* %5
%34 = load i64, i64* %4
%35 = call i64 @roundUpDiv(i64 %33, i64 %34)
store i64 %35, i64* %7
br label %36
36: ; preds = %32, %23
br label %37
37: ; preds = %36, %14
%38 = load i64, i64* %7
ret i64 %38
}

LLVM IR (-O2):
define i64 @chunkSize(i64 %0, i64 %1, i64 %2) {
%4 = icmp slt i64 %2, 1
%5 = icmp sgt i64 %2, %0
%6 = or i1 %4, %5
br i1 %6, label %18, label %7
7: ; preds = %3
%8 = tail call i64 @roundUpDiv(i64 %1, i64 %0)
%9 = sdiv i64 %1, %8
%10 = icmp slt i64 %9, %2
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = add nsw i64 %2, -1
%13 = tail call i64 @roundUpDiv(i64 %1, i64 %0)
%14 = mul nsw i64 %13, %12
%15 = sub nsw i64 %1, %14
br label %18
16: ; preds = %7
%17 = tail call i64 @roundUpDiv(i64 %1, i64 %0)
br label %18
18: ; preds = %3, %11, %16
%19 = phi i64 [ %15, %11 ], [ %17, %16 ], [ 0, %3 ]
ret i64 %19
}