#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 */
struct where {
  int dummy;
};
struct sample {
  int dummy;
};

/* Variables and functions */
double info_gain(struct sample const *, int, int);
int /*<<< orphan*/ is_field_clausule(struct where *, int);
int best_field_where(const struct sample *samples, int count,
                     struct where *where) {
  double bestval = -1000000;
  int best = -1;
  for (int i = 0; i < 4; i++) {
    if (i == 3)
      continue;
    if (!is_field_clausule(where, i)) {
      double ig = info_gain(samples, count, i);
      if (ig > bestval) {
        bestval = ig;
        best = i;
      }
    }
  }
  return best;
}


x86 assembly (clang, -O0):
<best_field_where>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11c8 <best_field_where+0xa8>
cmpl   $0x3,-0x28(%rbp)
jne    1167 <best_field_where+0x47>
jmp    11ba <best_field_where+0x9a>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <is_field_clausule@plt>
cmp    $0x0,%eax
jne    11b5 <best_field_where+0x95>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1030 <info_gain@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11b0 <best_field_where+0x90>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11b5 <best_field_where+0x95>
jmp    11ba <best_field_where+0x9a>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114e <best_field_where+0x2e>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<best_field_where>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rdx,%rdi
xor    %esi,%esi
call   1040 <is_field_clausule@plt>
test   %eax,%eax
je     1158 <best_field_where+0x38>
movsd  0xeb5(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xffffffff,%ebx
jmp    1182 <best_field_where+0x62>
mov    %r15,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1030 <info_gain@plt>
movsd  0xe93(%rip),%xmm1
xor    %ebx,%ebx
ucomisd %xmm1,%xmm0
setbe  %bl
neg    %ebx
maxsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%r12d
mov    %rbp,%rdi
mov    $0x1,%esi
call   1040 <is_field_clausule@plt>
test   %eax,%eax
jne    11c1 <best_field_where+0xa1>
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
call   1030 <info_gain@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
cmova  %r12d,%ebx
maxsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%r12d
mov    %rbp,%rdi
mov    $0x2,%esi
call   1040 <is_field_clausule@plt>
test   %eax,%eax
jne    11f2 <best_field_where+0xd2>
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x2,%edx
call   1030 <info_gain@plt>
ucomisd 0x8(%rsp),%xmm0
cmova  %r12d,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sample = type { i32 }
%struct.where = type { i32 }
define i32 @best_field_where(%struct.sample* %0, i32 %1, %struct.where* %2) {
%4 = alloca %struct.sample*
%5 = alloca i32
%6 = alloca %struct.where*
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store %struct.sample* %0, %struct.sample** %4
store i32 %1, i32* %5
store %struct.where* %2, %struct.where** %6
store double -1.000000e+06, double* %7
store i32 -1, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %36, %3
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %39
14: ; preds = %11
%15 = load i32, i32* %9
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %18
17: ; preds = %14
br label %36
18: ; preds = %14
%19 = load %struct.where*, %struct.where** %6
%20 = load i32, i32* %9
%21 = call i32 @is_field_clausule(%struct.where* %19, i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %18
%24 = load %struct.sample*, %struct.sample** %4
%25 = load i32, i32* %5
%26 = load i32, i32* %9
%27 = call double @info_gain(%struct.sample* %24, i32 %25, i32 %26)
store double %27, double* %10
%28 = load double, double* %10
%29 = load double, double* %7
%30 = fcmp ogt double %28, %29
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = load double, double* %10
store double %32, double* %7
%33 = load i32, i32* %9
store i32 %33, i32* %8
br label %34
34: ; preds = %31, %23
br label %35
35: ; preds = %34, %18
br label %36
36: ; preds = %35, %17
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %11
39: ; preds = %11
%40 = load i32, i32* %8
ret i32 %40
}

LLVM IR (-O2):
%struct.sample = type { i32 }
%struct.where = type { i32 }
define i32 @best_field_where(%struct.sample* %0, i32 %1, %struct.where* %2) {
%4 = tail call i32 @is_field_clausule(%struct.where* %2, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call double @info_gain(%struct.sample* %0, i32 %1, i32 0)
%8 = fcmp ogt double %7, -1.000000e+06
%9 = xor i1 %8, true
%10 = sext i1 %9 to i32
%11 = select i1 %8, double %7, double -1.000000e+06
br label %12
12: ; preds = %6, %3
%13 = phi i32 [ -1, %3 ], [ %10, %6 ]
%14 = phi double [ -1.000000e+06, %3 ], [ %11, %6 ]
%15 = tail call i32 @is_field_clausule(%struct.where* %2, i32 1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = tail call double @info_gain(%struct.sample* %0, i32 %1, i32 1)
%19 = fcmp ogt double %18, %14
%20 = select i1 %19, i32 1, i32 %13
%21 = select i1 %19, double %18, double %14
br label %22
22: ; preds = %12, %17
%23 = phi i32 [ %13, %12 ], [ %20, %17 ]
%24 = phi double [ %14, %12 ], [ %21, %17 ]
%25 = tail call i32 @is_field_clausule(%struct.where* %2, i32 2)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = tail call double @info_gain(%struct.sample* %0, i32 %1, i32 2)
%29 = fcmp ogt double %28, %24
%30 = select i1 %29, i32 2, i32 %23
br label %31
31: ; preds = %22, %27
%32 = phi i32 [ %23, %22 ], [ %30, %27 ]
ret i32 %32
}