#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*/ ave_dmatrix(double **, long, int, double *);
int /*<<< orphan*/ max_dmatrix(double **, long, int, double *);
double max_dvector(double *, int);
int /*<<< orphan*/ min_dmatrix(double **, long, int, double *);
double min_dvector(double *, int);
int /*<<< orphan*/ move_position(double **, long, int, double *);
void reset_xyz(long num, double **xyz, char *fmt) {
  double ave_xyz[4], max_xyz[4], min_xyz[4];
  max_dmatrix(xyz, num, 3, max_xyz);
  min_dmatrix(xyz, num, 3, min_xyz);
  ave_dmatrix(xyz, num, 3, ave_xyz);
  if (max_dvector(max_xyz, 3) > 9999.99) {
    move_position(xyz, num, 3, ave_xyz);
  } else if (min_dvector(min_xyz, 3) < -999.99) {
    move_position(xyz, num, 3, min_xyz);
  }
}


x86 assembly (clang, -O0):
<reset_xyz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x60(%rbp),%rcx
mov    $0x3,%edx
call   1030 <max_dmatrix@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x80(%rbp),%rcx
mov    $0x3,%edx
call   1050 <min_dmatrix@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%rcx
mov    $0x3,%edx
call   1080 <ave_dmatrix@plt>
lea    -0x60(%rbp),%rdi
mov    $0x3,%esi
call   1060 <max_dvector@plt>
movsd  0xe31(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f4 <reset_xyz+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%rcx
mov    $0x3,%edx
call   1040 <move_position@plt>
jmp    1232 <reset_xyz+0xd2>
lea    -0x80(%rbp),%rdi
mov    $0x3,%esi
call   1070 <min_dvector@plt>
movaps %xmm0,%xmm1
movsd  0xdfb(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    122d <reset_xyz+0xcd>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x80(%rbp),%rcx
mov    $0x3,%edx
call   1040 <move_position@plt>
jmp    1232 <reset_xyz+0xd2>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_xyz>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x20(%rsp),%r13
mov    %rsi,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
mov    %r13,%rcx
call   1030 <max_dmatrix@plt>
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
mov    %r15,%rcx
call   1050 <min_dmatrix@plt>
lea    0x40(%rsp),%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1080 <ave_dmatrix@plt>
mov    %r13,%rdi
mov    $0x3,%esi
call   1060 <max_dvector@plt>
ucomisd 0xe32(%rip),%xmm0
ja     11ee <reset_xyz+0x8e>
mov    %r15,%rdi
mov    $0x3,%esi
call   1070 <min_dvector@plt>
movsd  0xe23(%rip),%xmm1
ucomisd %xmm0,%xmm1
mov    %r15,%rbx
jbe    1201 <reset_xyz+0xa1>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1040 <move_position@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @reset_xyz(i64 %0, double** %1, i8* %2) {
%4 = alloca i64
%5 = alloca double**
%6 = alloca i8*
%7 = alloca [4 x double]
%8 = alloca [4 x double]
%9 = alloca [4 x double]
store i64 %0, i64* %4
store double** %1, double*** %5
store i8* %2, i8** %6
%10 = load double**, double*** %5
%11 = load i64, i64* %4
%12 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%13 = call i32 @max_dmatrix(double** %10, i64 %11, i32 3, double* %12)
%14 = load double**, double*** %5
%15 = load i64, i64* %4
%16 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%17 = call i32 @min_dmatrix(double** %14, i64 %15, i32 3, double* %16)
%18 = load double**, double*** %5
%19 = load i64, i64* %4
%20 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%21 = call i32 @ave_dmatrix(double** %18, i64 %19, i32 3, double* %20)
%22 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%23 = call double @max_dvector(double* %22, i32 3)
%24 = fcmp ogt double %23, 0x40C387FEB851EB85
br i1 %24, label %25, label %30
25: ; preds = %3
%26 = load double**, double*** %5
%27 = load i64, i64* %4
%28 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%29 = call i32 @move_position(double** %26, i64 %27, i32 3, double* %28)
br label %40
30: ; preds = %3
%31 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%32 = call double @min_dvector(double* %31, i32 3)
%33 = fcmp olt double %32, -9.999900e+02
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load double**, double*** %5
%36 = load i64, i64* %4
%37 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%38 = call i32 @move_position(double** %35, i64 %36, i32 3, double* %37)
br label %39
39: ; preds = %34, %30
br label %40
40: ; preds = %39, %25
ret void
}

LLVM IR (-O2):
define void @reset_xyz(i64 %0, double** %1, i8* nocapture readnone %2) {
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = bitcast [4 x double]* %4 to i8*
%8 = bitcast [4 x double]* %5 to i8*
%9 = bitcast [4 x double]* %6 to i8*
%10 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%11 = call i32 @max_dmatrix(double** %1, i64 %0, i32 3, double* %10)
%12 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%13 = call i32 @min_dmatrix(double** %1, i64 %0, i32 3, double* %12)
%14 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%15 = call i32 @ave_dmatrix(double** %1, i64 %0, i32 3, double* %14)
%16 = call double @max_dvector(double* %10, i32 3)
%17 = fcmp ogt double %16, 0x40C387FEB851EB85
br i1 %17, label %21, label %18
18: ; preds = %3
%19 = call double @min_dvector(double* %12, i32 3)
%20 = fcmp olt double %19, -9.999900e+02
br i1 %20, label %21, label %24
21: ; preds = %18, %3
%22 = phi double* [ %14, %3 ], [ %12, %18 ]
%23 = call i32 @move_position(double** %1, i64 %0, i32 3, double* %22)
br label %24
24: ; preds = %21, %18
ret void
}