#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 */
float *array_append_f(int, float *, int, float *);
float *array_slice_f(int, int, float *);
float array_sum_f(int, float *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(float *);
float calc_icm_single(int players, float *player, int prizes, float *prize) {
  assert(prizes > 0);
  if (players > 1) {
    float value = (player[0] / array_sum_f(players, player)) * prize[0];
    if (prizes > 1) {
      float *rec_prize = array_slice_f(1, prizes, prize);
      float *rec_player;
      for (int i = 1; i < players; i++) {
        rec_player =
            array_append_f(i, array_slice_f(0, i, player), (players - (i + 1)),
                           array_slice_f((i + 1), players, player));
        value +=
            (player[i] / array_sum_f(players, player)) *
            calc_icm_single(players - 1, rec_player, prizes - 1, rec_prize);
        free(rec_player);
      }
    }
    return value;
  } else
    return prize[0];
}


x86 assembly (clang, -O0):
<calc_icm_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x1,-0x8(%rbp)
jle    12d0 <calc_icm_single+0x170>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <array_sum_f@plt>
movaps %xmm0,%xmm1
movss  -0x40(%rbp),%xmm0
divss  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    12c1 <calc_icm_single+0x161>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
call   1030 <array_slice_f@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12bc <calc_icm_single+0x15c>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
call   1030 <array_slice_f@plt>
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x3c(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <array_slice_f@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x4c(%rbp),%edx
mov    %rax,%rcx
call   1050 <array_append_f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <array_sum_f@plt>
movaps %xmm0,%xmm1
movss  -0x48(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x30(%rbp),%rcx
call   1080 <calc_icm_single@plt>
movaps %xmm0,%xmm2
movss  -0x44(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e9 <calc_icm_single+0x89>
jmp    12c1 <calc_icm_single+0x161>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12dd <calc_icm_single+0x17d>
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_icm_single>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbp
mov    %rsi,%r12
mov    %edi,%ebx
xor    %edi,%edi
mov    %edx,%r14d
test   %edx,%edx
setg   %dil
call   1070 <assert@plt>
mov    %rbx,0x8(%rsp)
cmp    $0x2,%ebx
jl     12b7 <calc_icm_single+0x157>
movss  (%r12),%xmm0
movss  %xmm0,(%rsp)
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
call   1060 <array_sum_f@plt>
movss  (%rsp),%xmm1
divss  %xmm0,%xmm1
mulss  0x0(%rbp),%xmm1
movss  %xmm1,(%rsp)
cmp    $0x2,%r14d
jl     12c1 <calc_icm_single+0x161>
mov    $0x1,%edi
mov    %r14d,%ebx
mov    %r14d,%esi
mov    %rbp,%rdx
call   1030 <array_slice_f@plt>
mov    %rax,0x20(%rsp)
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%ecx
mov    %ecx,0x10(%rsp)
add    $0xffffffff,%ebx
mov    %ebx,0x14(%rsp)
mov    %eax,%ecx
mov    %rcx,0x18(%rsp)
lea    -0x2(%rax),%ebp
mov    $0x1,%r15d
mov    0x8(%rsp),%r13
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r15d,%esi
mov    %r12,%rdx
call   1030 <array_slice_f@plt>
mov    %r12,%rbx
mov    %rax,%r12
lea    0x1(%r15),%r14
mov    %r14d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1030 <array_slice_f@plt>
lea    -0x1(%r14),%edi
mov    %r12,%rsi
mov    %rbx,%r12
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <array_append_f@plt>
mov    %rax,%rbx
movss  (%r12,%r15,4),%xmm0
movss  %xmm0,0x4(%rsp)
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <array_sum_f@plt>
movss  0x4(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    0x14(%rsp),%edx
mov    0x20(%rsp),%rcx
call   1080 <calc_icm_single@plt>
mulss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
mov    %rbx,%rdi
call   1040 <free@plt>
add    $0xffffffff,%ebp
mov    %r14,%r15
cmp    0x18(%rsp),%r14
jne    1210 <calc_icm_single+0xb0>
jmp    12c1 <calc_icm_single+0x161>
movss  0x0(%rbp),%xmm0
movss  %xmm0,(%rsp)
movss  (%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @calc_icm_single(i32 %0, float* %1, i32 %2, float* %3) {
%5 = alloca float
%6 = alloca i32
%7 = alloca float*
%8 = alloca i32
%9 = alloca float*
%10 = alloca float
%11 = alloca float*
%12 = alloca float*
%13 = alloca i32
store i32 %0, i32* %6
store float* %1, float** %7
store i32 %2, i32* %8
store float* %3, float** %9
%14 = load i32, i32* %8
%15 = icmp sgt i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %83
20: ; preds = %4
%21 = load float*, float** %7
%22 = getelementptr inbounds float, float* %21, i64 0
%23 = load float, float* %22
%24 = load i32, i32* %6
%25 = load float*, float** %7
%26 = call float @array_sum_f(i32 %24, float* %25)
%27 = fdiv float %23, %26
%28 = load float*, float** %9
%29 = getelementptr inbounds float, float* %28, i64 0
%30 = load float, float* %29
%31 = fmul float %27, %30
store float %31, float* %10
%32 = load i32, i32* %8
%33 = icmp sgt i32 %32, 1
br i1 %33, label %34, label %81
34: ; preds = %20
%35 = load i32, i32* %8
%36 = load float*, float** %9
%37 = call float* @array_slice_f(i32 1, i32 %35, float* %36)
store float* %37, float** %11
store i32 1, i32* %13
br label %38
38: ; preds = %77, %34
%39 = load i32, i32* %13
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %80
42: ; preds = %38
%43 = load i32, i32* %13
%44 = load i32, i32* %13
%45 = load float*, float** %7
%46 = call float* @array_slice_f(i32 0, i32 %44, float* %45)
%47 = load i32, i32* %6
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
%50 = sub nsw i32 %47, %49
%51 = load i32, i32* %13
%52 = add nsw i32 %51, 1
%53 = load i32, i32* %6
%54 = load float*, float** %7
%55 = call float* @array_slice_f(i32 %52, i32 %53, float* %54)
%56 = call float* @array_append_f(i32 %43, float* %46, i32 %50, float* %55)
store float* %56, float** %12
%57 = load float*, float** %7
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds float, float* %57, i64 %59
%61 = load float, float* %60
%62 = load i32, i32* %6
%63 = load float*, float** %7
%64 = call float @array_sum_f(i32 %62, float* %63)
%65 = fdiv float %61, %64
%66 = load i32, i32* %6
%67 = sub nsw i32 %66, 1
%68 = load float*, float** %12
%69 = load i32, i32* %8
%70 = sub nsw i32 %69, 1
%71 = load float*, float** %11
%72 = call float @calc_icm_single(i32 %67, float* %68, i32 %70, float* %71)
%73 = load float, float* %10
%74 = call float @llvm.fmuladd.f32(float %65, float %72, float %73)
store float %74, float* %10
%75 = load float*, float** %12
%76 = call i32 @free(float* %75)
br label %77
77: ; preds = %42
%78 = load i32, i32* %13
%79 = add nsw i32 %78, 1
store i32 %79, i32* %13
br label %38
80: ; preds = %38
br label %81
81: ; preds = %80, %20
%82 = load float, float* %10
store float %82, float* %5
br label %87
83: ; preds = %4
%84 = load float*, float** %9
%85 = getelementptr inbounds float, float* %84, i64 0
%86 = load float, float* %85
store float %86, float* %5
br label %87
87: ; preds = %83, %81
%88 = load float, float* %5
ret float %88
}

LLVM IR (-O2):
define float @calc_icm_single(i32 %0, float* %1, i32 %2, float* %3) {
%5 = icmp sgt i32 %2, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %39
9: ; preds = %4
%10 = load float, float* %1
%11 = tail call float @array_sum_f(i32 %0, float* %1)
%12 = fdiv float %10, %11
%13 = load float, float* %3
%14 = fmul float %12, %13
%15 = icmp sgt i32 %2, 1
br i1 %15, label %16, label %41
16: ; preds = %9
%17 = tail call float* @array_slice_f(i32 1, i32 %2, float* %3)
%18 = add nsw i32 %0, -1
%19 = add nsw i32 %2, -1
%20 = zext i32 %0 to i64
br label %21
21: ; preds = %16, %21
%22 = phi i64 [ 1, %16 ], [ %26, %21 ]
%23 = phi float [ %14, %16 ], [ %36, %21 ]
%24 = trunc i64 %22 to i32
%25 = tail call float* @array_slice_f(i32 0, i32 %24, float* %1)
%26 = add nuw nsw i64 %22, 1
%27 = trunc i64 %26 to i32
%28 = sub nsw i32 %0, %27
%29 = tail call float* @array_slice_f(i32 %27, i32 %0, float* %1)
%30 = tail call float* @array_append_f(i32 %24, float* %25, i32 %28, float* %29)
%31 = getelementptr inbounds float, float* %1, i64 %22
%32 = load float, float* %31
%33 = tail call float @array_sum_f(i32 %0, float* %1)
%34 = fdiv float %32, %33
%35 = tail call float @calc_icm_single(i32 %18, float* %30, i32 %19, float* %17)
%36 = tail call float @llvm.fmuladd.f32(float %34, float %35, float %23)
%37 = tail call i32 @free(float* %30)
%38 = icmp eq i64 %26, %20
br i1 %38, label %41, label %21
39: ; preds = %4
%40 = load float, float* %3
br label %41
41: ; preds = %21, %9, %39
%42 = phi float [ %40, %39 ], [ %14, %9 ], [ %36, %21 ]
ret float %42
}