#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 */
scalar_t__ ceil(double);
int calculateTrucks(int loadSize, int numCrate) {
  int count = 0;
  if (numCrate <= loadSize)
    return 1;
  count += calculateTrucks(loadSize, (int)ceil((double)numCrate / 2));
  count +=
      calculateTrucks(loadSize, numCrate - (int)ceil((double)numCrate / 2));
  return count;
}


x86 assembly (clang, -O0):
<calculateTrucks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     114d <calculateTrucks+0x2d>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <calculateTrucks+0x94>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xea0(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <ceil@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1030 <calculateTrucks@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <ceil@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edi
sub    %eax,%esi
call   1030 <calculateTrucks@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateTrucks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    %edi,%esi
jle    117d <calculateTrucks+0x5d>
mov    %esi,%ebp
mov    %edi,%r14d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xeb1(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1040 <ceil@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1030 <calculateTrucks@plt>
mov    %eax,%r15d
movsd  (%rsp),%xmm0
call   1040 <ceil@plt>
sub    %eax,%ebp
add    %r15d,%ebx
cmp    %r14d,%ebp
jg     1140 <calculateTrucks+0x20>
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calculateTrucks(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp sle i32 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %33
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 2.000000e+00
%16 = call i64 @ceil(double %15)
%17 = trunc i64 %16 to i32
%18 = call i32 @calculateTrucks(i32 %12, i32 %17)
%19 = load i32, i32* %6
%20 = add nsw i32 %19, %18
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, 2.000000e+00
%26 = call i64 @ceil(double %25)
%27 = trunc i64 %26 to i32
%28 = sub nsw i32 %22, %27
%29 = call i32 @calculateTrucks(i32 %21, i32 %28)
%30 = load i32, i32* %6
%31 = add nsw i32 %30, %29
store i32 %31, i32* %6
%32 = load i32, i32* %6
store i32 %32, i32* %3
br label %33
33: ; preds = %11, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @calculateTrucks(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, %0
br i1 %3, label %4, label %19
4: ; preds = %2, %4
%5 = phi i32 [ %14, %4 ], [ %1, %2 ]
%6 = phi i32 [ %15, %4 ], [ 0, %2 ]
%7 = sitofp i32 %5 to double
%8 = fmul double %7, 5.000000e-01
%9 = tail call i64 @ceil(double %8)
%10 = trunc i64 %9 to i32
%11 = tail call i32 @calculateTrucks(i32 %0, i32 %10)
%12 = tail call i64 @ceil(double %8)
%13 = trunc i64 %12 to i32
%14 = sub nsw i32 %5, %13
%15 = add nsw i32 %11, %6
%16 = icmp sgt i32 %14, %0
br i1 %16, label %4, label %17
17: ; preds = %4
%18 = add i32 %15, 1
br label %19
19: ; preds = %17, %2
%20 = phi i32 [ 1, %2 ], [ %18, %17 ]
ret i32 %20
}