#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 INFINITY;
float fmax(float, float);
float fmin(float, float);
scalar_t__ isfinite(float);
void minmax(float *p, int N, float *vmin, float *vmax) {
  float imin = +INFINITY;
  float imax = -INFINITY;
  for (int i = 0; i < N; i++) {
    float pp = p[i];
    if (isfinite(pp)) {
      imin = fmin(imin, pp);
      imax = fmax(imax, pp);
    }
  }
  *vmin = imin;
  *vmax = imax;
}


x86 assembly (clang, -O0):
<minmax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e9a(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    0x2e8a(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e8 <minmax+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
call   1040 <isfinite@plt>
cmp    $0x0,%rax
je     11d5 <minmax+0xa5>
movss  -0x24(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
call   1030 <fmin@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x28(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
call   1050 <fmax@plt>
movss  %xmm0,-0x28(%rbp)
jmp    11da <minmax+0xaa>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117b <minmax+0x4b>
movss  -0x24(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minmax>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    0x2ebe(%rip),%rax
movss  (%rax),%xmm0
movaps 0xecb(%rip),%xmm1
movaps %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm1
movaps %xmm1,(%rsp)
test   %esi,%esi
jle    11b7 <minmax+0xa7>
mov    %rdi,%r12
mov    %esi,%r13d
xor    %ebx,%ebx
jmp    1159 <minmax+0x49>
nop
add    $0x1,%rbx
cmp    %rbx,%r13
je     11b7 <minmax+0xa7>
movss  (%r12,%rbx,4),%xmm0
movaps %xmm0,0x20(%rsp)
call   1030 <isfinite@plt>
test   %rax,%rax
je     1150 <minmax+0x40>
movaps 0x20(%rsp),%xmm3
movaps %xmm3,%xmm0
movaps 0x10(%rsp),%xmm2
minss  %xmm2,%xmm0
cmpunordss %xmm2,%xmm2
movaps %xmm2,%xmm1
andps  %xmm3,%xmm1
andnps %xmm0,%xmm2
orps   %xmm1,%xmm2
movaps %xmm2,0x10(%rsp)
movaps (%rsp),%xmm2
movaps %xmm2,%xmm0
cmpunordss %xmm2,%xmm0
movaps %xmm0,%xmm1
andps  %xmm3,%xmm1
maxss  %xmm2,%xmm3
andnps %xmm3,%xmm0
orps   %xmm1,%xmm0
movaps %xmm0,(%rsp)
jmp    1150 <minmax+0x40>
movaps 0x10(%rsp),%xmm0
movss  %xmm0,(%r15)
movaps (%rsp),%xmm0
movss  %xmm0,(%r14)
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@INFINITY = global float 0.000000e+00
define void @minmax(float* %0, i32 %1, float* %2, float* %3) {
%5 = alloca float*
%6 = alloca i32
%7 = alloca float*
%8 = alloca float*
%9 = alloca float
%10 = alloca float
%11 = alloca i32
%12 = alloca float
store float* %0, float** %5
store i32 %1, i32* %6
store float* %2, float** %7
store float* %3, float** %8
%13 = load float, float* @INFINITY
store float %13, float* %9
%14 = load float, float* @INFINITY
%15 = fneg float %14
store float %15, float* %10
store i32 0, i32* %11
br label %16
16: ; preds = %37, %4
%17 = load i32, i32* %11
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load float*, float** %5
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
%25 = load float, float* %24
store float %25, float* %12
%26 = load float, float* %12
%27 = call i64 @isfinite(float %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %20
%30 = load float, float* %9
%31 = load float, float* %12
%32 = call float @fmin(float %30, float %31)
store float %32, float* %9
%33 = load float, float* %10
%34 = load float, float* %12
%35 = call float @fmax(float %33, float %34)
store float %35, float* %10
br label %36
36: ; preds = %29, %20
br label %37
37: ; preds = %36
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
br label %16
40: ; preds = %16
%41 = load float, float* %9
%42 = load float*, float** %7
store float %41, float* %42
%43 = load float, float* %10
%44 = load float*, float** %8
store float %43, float* %44
ret void
}

LLVM IR (-O2):
@INFINITY = global float 0.000000e+00
define void @minmax(float* nocapture %0, i32 %1, float* nocapture writeonly %2, float* nocapture writeonly %3) {
%5 = load float, float* @INFINITY
%6 = fneg float %5
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = zext i32 %1 to i64
br label %13
10: ; preds = %24, %4
%11 = phi float [ %6, %4 ], [ %25, %24 ]
%12 = phi float [ %5, %4 ], [ %26, %24 ]
store float %12, float* %2
store float %11, float* %3
ret void
13: ; preds = %8, %24
%14 = phi i64 [ 0, %8 ], [ %27, %24 ]
%15 = phi float [ %5, %8 ], [ %26, %24 ]
%16 = phi float [ %6, %8 ], [ %25, %24 ]
%17 = getelementptr inbounds float, float* %0, i64 %14
%18 = load float, float* %17
%19 = tail call i64 @isfinite(float %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = tail call nsz float @llvm.minnum.f32(float %15, float %18)
%23 = tail call nsz float @llvm.maxnum.f32(float %16, float %18)
br label %24
24: ; preds = %21, %13
%25 = phi float [ %23, %21 ], [ %16, %13 ]
%26 = phi float [ %22, %21 ], [ %15, %13 ]
%27 = add nuw nsw i64 %14, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %10, label %13
}