#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 /*<<< orphan*/ almost_equal(double const, double const);
bool is_uniform_array_value(const double *const array, const size_t size,
                            const double value, int *unvalid_index) {
  size_t inv_ind = 0;
  for (size_t i = 0; i < size; ++i) {
    if (!almost_equal(array[i], value)) {
      unvalid_index[inv_ind++] = i;
    }
  };
  return inv_ind == 0;
}


x86 assembly (clang, -O0):
<is_uniform_array_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1199 <is_uniform_array_value+0x89>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <almost_equal@plt>
cmp    $0x0,%eax
jne    1183 <is_uniform_array_value+0x73>
mov    -0x30(%rbp),%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %edx,(%rax,%rcx,4)
jmp    1188 <is_uniform_array_value+0x78>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1139 <is_uniform_array_value+0x29>
cmpq   $0x0,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_uniform_array_value>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
test   %rsi,%rsi
je     1168 <is_uniform_array_value+0x58>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    1149 <is_uniform_array_value+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     116b <is_uniform_array_value+0x5b>
movsd  (%r15,%rbx,8),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <almost_equal@plt>
test   %eax,%eax
jne    1140 <is_uniform_array_value+0x30>
mov    %ebx,(%r14,%r13,4)
add    $0x1,%r13
jmp    1140 <is_uniform_array_value+0x30>
xor    %r13d,%r13d
xor    %eax,%eax
test   %r13,%r13
sete   %al
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @is_uniform_array_value(double* %0, i64 %1, double %2, i32* %3) {
%5 = alloca double*
%6 = alloca i64
%7 = alloca double
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store double* %0, double** %5
store i64 %1, i64* %6
store double %2, double* %7
store i32* %3, i32** %8
store i64 0, i64* %9
store i64 0, i64* %10
br label %11
11: ; preds = %31, %4
%12 = load i64, i64* %10
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load double*, double** %5
%17 = load i64, i64* %10
%18 = getelementptr inbounds double, double* %16, i64 %17
%19 = load double, double* %18
%20 = load double, double* %7
%21 = call i32 @almost_equal(double %19, double %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %15
%24 = load i64, i64* %10
%25 = trunc i64 %24 to i32
%26 = load i32*, i32** %8
%27 = load i64, i64* %9
%28 = add i64 %27, 1
store i64 %28, i64* %9
%29 = getelementptr inbounds i32, i32* %26, i64 %27
store i32 %25, i32* %29
br label %30
30: ; preds = %23, %15
br label %31
31: ; preds = %30
%32 = load i64, i64* %10
%33 = add i64 %32, 1
store i64 %33, i64* %10
br label %11
34: ; preds = %11
%35 = load i64, i64* %9
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
ret i32 %37
}

LLVM IR (-O2):
define i32 @is_uniform_array_value(double* nocapture %0, i64 %1, double %2, i32* nocapture writeonly %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %10
6: ; preds = %21, %4
%7 = phi i64 [ 0, %4 ], [ %22, %21 ]
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
ret i32 %9
10: ; preds = %4, %21
%11 = phi i64 [ %23, %21 ], [ 0, %4 ]
%12 = phi i64 [ %22, %21 ], [ 0, %4 ]
%13 = getelementptr inbounds double, double* %0, i64 %11
%14 = load double, double* %13
%15 = tail call i32 @almost_equal(double %14, double %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = trunc i64 %11 to i32
%19 = add i64 %12, 1
%20 = getelementptr inbounds i32, i32* %3, i64 %12
store i32 %18, i32* %20
br label %21
21: ; preds = %10, %17
%22 = phi i64 [ %12, %10 ], [ %19, %17 ]
%23 = add nuw i64 %11, 1
%24 = icmp eq i64 %23, %1
br i1 %24, label %6, label %10
}