#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 */
int getSumFromBitmask(int, int *, int);
int retrieveSubsetFromBitmask(int, int *, int, int *);
int chooseSubsetToFillTapeBest(int totalDuration, int durationArr[],
                               int numTrack, int subsetDurationArr[]) {
  int bitmask = 0, minNotFill = totalDuration, bestBitmask, notFill,
      bestSubsetSize;
  for (bitmask = 1; bitmask < (1 << numTrack); bitmask++) {
    notFill = totalDuration - getSumFromBitmask(bitmask, durationArr, numTrack);
    if (notFill >= 0 && notFill < minNotFill) {
      bestBitmask = bitmask;
      minNotFill = notFill;
    }
  }
  bestSubsetSize = retrieveSubsetFromBitmask(bestBitmask, durationArr, numTrack,
                                             subsetDurationArr);
  return bestSubsetSize;
}


x86 assembly (clang, -O0):
<chooseSubsetToFillTapeBest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    11b5 <chooseSubsetToFillTapeBest+0x95>
mov    -0x4(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <getSumFromBitmask@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     11a2 <chooseSubsetToFillTapeBest+0x82>
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11a2 <chooseSubsetToFillTapeBest+0x82>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11a7 <chooseSubsetToFillTapeBest+0x87>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <chooseSubsetToFillTapeBest+0x2a>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1040 <retrieveSubsetFromBitmask@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chooseSubsetToFillTapeBest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %edx,%r12d
mov    %rsi,0x8(%rsp)
mov    %edi,%r14d
mov    $0x1,%ebp
mov    $0x1,%ebx
mov    %r12d,%ecx
shl    %cl,%ebx
mov    %edi,%r13d
jmp    116d <chooseSubsetToFillTapeBest+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %ecx,%r13d
mov    %edi,%r15d
cmp    %ebp,%ebx
je     1198 <chooseSubsetToFillTapeBest+0x78>
mov    %ebp,%edi
mov    0x8(%rsp),%rsi
mov    %r12d,%edx
call   1030 <getSumFromBitmask@plt>
mov    %r14d,%ecx
sub    %eax,%ecx
setns  %al
cmp    %r13d,%ecx
setl   %dl
mov    %ebp,%edi
test   %dl,%al
jne    1160 <chooseSubsetToFillTapeBest+0x40>
mov    %r15d,%edi
mov    %r13d,%ecx
jmp    1160 <chooseSubsetToFillTapeBest+0x40>
mov    0x8(%rsp),%rsi
mov    %r12d,%edx
mov    0x10(%rsp),%rcx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <retrieveSubsetFromBitmask@plt>

LLVM IR (-O0):
define i32 @chooseSubsetToFillTapeBest(i32 %0, i32* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
%14 = load i32, i32* %5
store i32 %14, i32* %10
store i32 1, i32* %9
br label %15
15: ; preds = %37, %4
%16 = load i32, i32* %9
%17 = load i32, i32* %7
%18 = shl i32 1, %17
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %40
20: ; preds = %15
%21 = load i32, i32* %5
%22 = load i32, i32* %9
%23 = load i32*, i32** %6
%24 = load i32, i32* %7
%25 = call i32 @getSumFromBitmask(i32 %22, i32* %23, i32 %24)
%26 = sub nsw i32 %21, %25
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %20
%30 = load i32, i32* %12
%31 = load i32, i32* %10
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %9
store i32 %34, i32* %11
%35 = load i32, i32* %12
store i32 %35, i32* %10
br label %36
36: ; preds = %33, %29, %20
br label %37
37: ; preds = %36
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %15
40: ; preds = %15
%41 = load i32, i32* %11
%42 = load i32*, i32** %6
%43 = load i32, i32* %7
%44 = load i32*, i32** %8
%45 = call i32 @retrieveSubsetFromBitmask(i32 %41, i32* %42, i32 %43, i32* %44)
store i32 %45, i32* %13
%46 = load i32, i32* %13
ret i32 %46
}

LLVM IR (-O2):
define i32 @chooseSubsetToFillTapeBest(i32 %0, i32* %1, i32 %2, i32* %3) {
%5 = shl nuw i32 1, %2
%6 = icmp sgt i32 %5, 1
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ %18, %7 ], [ 1, %4 ]
%9 = phi i32 [ %17, %7 ], [ %0, %4 ]
%10 = phi i32 [ %16, %7 ], [ undef, %4 ]
%11 = tail call i32 @getSumFromBitmask(i32 %8, i32* %1, i32 %2)
%12 = sub nsw i32 %0, %11
%13 = icmp sgt i32 %12, -1
%14 = icmp slt i32 %12, %9
%15 = select i1 %13, i1 %14, i1 false
%16 = select i1 %15, i32 %8, i32 %10
%17 = select i1 %15, i32 %12, i32 %9
%18 = add nuw nsw i32 %8, 1
%19 = icmp eq i32 %18, %5
br i1 %19, label %20, label %7
20: ; preds = %7
%21 = tail call i32 @retrieveSubsetFromBitmask(i32 %16, i32* %1, i32 %2, i32* %3)
ret i32 %21
}