#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*/ exit(int);
double fmin(double, double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double, double,
                           double, double, double, double, double);
double max_abs_value(double **, int, int);
int /*<<< orphan*/ stderr;
double select_time_step(double tau, double re, double dx, double dy, int nx,
                        int ny, double **U, double **V) {
  double t_diff, t_adv_u, t_adv_v;
  double u_max, v_max;
  double dt;
  u_max = max_abs_value(U, nx, ny);
  v_max = max_abs_value(V, nx, ny);
  t_diff = re / 2.0 * (1.0 / (1.0 / (dx * dx) + (1.0 / (dy * dy))));
  t_adv_u = dx / (u_max + 1.0e-12);
  t_adv_v = dx / (v_max + 1.0e-12);
  dt = fmin(t_diff, fmin(t_adv_u, t_adv_v));
  if (dt < 1.0e-12) {
    fprintf(stderr,
            "select_time_step: Error, the time step is too small: "
            "%f s.\n"
            "tau = %f, Re = %f, u_max = %f, v_max = %f\n"
            "t_diff = %f s, t_adv_u = %f s, t_adv_v = %f s\n",
            dt, tau, re, u_max, v_max, t_diff, t_adv_u, t_adv_v);
    exit(1);
  }
  return dt;
}


x86 assembly (clang, -O0):
<select_time_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
mov    %esi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1040 <max_abs_value@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1040 <max_abs_value@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe81(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  0xe63(%rip),%xmm2
divsd  %xmm1,%xmm2
movsd  -0x20(%rbp),%xmm3
mulsd  -0x20(%rbp),%xmm3
movsd  0xe4d(%rip),%xmm1
divsd  %xmm3,%xmm1
addsd  %xmm1,%xmm2
movsd  0xe3d(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
addsd  -0x58(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe00(%rip),%xmm1
addsd  -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm3
movsd  -0x48(%rbp),%xmm4
movsd  -0x50(%rbp),%xmm1
movaps %xmm1,%xmm5
movaps %xmm4,%xmm2
cmpunordsd %xmm2,%xmm2
movaps %xmm2,%xmm0
pand   %xmm5,%xmm0
minsd  %xmm4,%xmm1
pandn  %xmm1,%xmm2
por    %xmm0,%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
minsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xd9a(%rip),%xmm0
ucomisd -0x68(%rbp),%xmm0
jbe    12b8 <select_time_step+0x188>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
movsd  -0x68(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm3
movsd  -0x60(%rbp),%xmm4
movsd  -0x40(%rbp),%xmm5
movsd  -0x48(%rbp),%xmm6
movsd  -0x50(%rbp),%xmm7
lea    0xd6f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movsd  -0x68(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_time_step>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
movaps %xmm3,0x30(%rsp)
movaps %xmm2,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdx,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <max_abs_value@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <max_abs_value@plt>
movsd  0x10(%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movapd 0x20(%rsp),%xmm7
movapd %xmm0,%xmm8
movsd  0xe6e(%rip),%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm7,%xmm1
unpcklpd 0x30(%rsp),%xmm1
mulpd  %xmm1,%xmm1
movapd 0xe74(%rip),%xmm4
divpd  %xmm1,%xmm4
movapd %xmm4,%xmm1
unpckhpd %xmm4,%xmm1
addsd  %xmm4,%xmm1
movsd  0xe44(%rip),%xmm5
divsd  %xmm1,%xmm5
mulsd  %xmm0,%xmm5
movsd  0xe3b(%rip),%xmm9
movapd %xmm3,%xmm0
addsd  %xmm9,%xmm0
movapd %xmm7,%xmm6
divsd  %xmm0,%xmm6
movapd %xmm8,%xmm0
addsd  %xmm9,%xmm0
divsd  %xmm0,%xmm7
movapd %xmm6,%xmm4
cmpunordsd %xmm6,%xmm4
movapd %xmm4,%xmm0
andpd  %xmm7,%xmm0
movapd %xmm7,%xmm1
minsd  %xmm6,%xmm1
andnpd %xmm1,%xmm4
orpd   %xmm0,%xmm4
movapd %xmm5,%xmm0
cmpunordsd %xmm5,%xmm0
movapd %xmm0,%xmm1
andpd  %xmm4,%xmm1
minsd  %xmm5,%xmm4
andnpd %xmm4,%xmm0
orpd   %xmm1,%xmm0
ucomisd %xmm0,%xmm9
ja     1242 <select_time_step+0x112>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
movsd  0x8(%rsp),%xmm1
movapd %xmm8,%xmm4
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [148 x i8] c"select_time_step: Error, the time step is too small: %f s.\0Atau = %f, Re = %f, u_max = %f, v_max = %f\0At_diff = %f s, t_adv_u = %f s, t_adv_v = %f s\0A\00"
define double @select_time_step(double %0, double %1, double %2, double %3, i32 %4, i32 %5, double** %6, double** %7) {
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca double**
%16 = alloca double**
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
store double %0, double* %9
store double %1, double* %10
store double %2, double* %11
store double %3, double* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store double** %6, double*** %15
store double** %7, double*** %16
%23 = load double**, double*** %15
%24 = load i32, i32* %13
%25 = load i32, i32* %14
%26 = call double @max_abs_value(double** %23, i32 %24, i32 %25)
store double %26, double* %20
%27 = load double**, double*** %16
%28 = load i32, i32* %13
%29 = load i32, i32* %14
%30 = call double @max_abs_value(double** %27, i32 %28, i32 %29)
store double %30, double* %21
%31 = load double, double* %10
%32 = fdiv double %31, 2.000000e+00
%33 = load double, double* %11
%34 = load double, double* %11
%35 = fmul double %33, %34
%36 = fdiv double 1.000000e+00, %35
%37 = load double, double* %12
%38 = load double, double* %12
%39 = fmul double %37, %38
%40 = fdiv double 1.000000e+00, %39
%41 = fadd double %36, %40
%42 = fdiv double 1.000000e+00, %41
%43 = fmul double %32, %42
store double %43, double* %17
%44 = load double, double* %11
%45 = load double, double* %20
%46 = fadd double %45, 0x3D719799812DEA11
%47 = fdiv double %44, %46
store double %47, double* %18
%48 = load double, double* %11
%49 = load double, double* %21
%50 = fadd double %49, 0x3D719799812DEA11
%51 = fdiv double %48, %50
store double %51, double* %19
%52 = load double, double* %17
%53 = load double, double* %18
%54 = load double, double* %19
%55 = call double @llvm.minnum.f64(double %53, double %54)
%56 = call double @llvm.minnum.f64(double %52, double %55)
store double %56, double* %22
%57 = load double, double* %22
%58 = fcmp olt double %57, 0x3D719799812DEA11
br i1 %58, label %59, label %71
59: ; preds = %8
%60 = load i32, i32* @stderr
%61 = load double, double* %22
%62 = load double, double* %9
%63 = load double, double* %10
%64 = load double, double* %20
%65 = load double, double* %21
%66 = load double, double* %17
%67 = load double, double* %18
%68 = load double, double* %19
%69 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0), double %61, double %62, double %63, double %64, double %65, double %66, double %67, double %68)
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %8
%72 = load double, double* %22
ret double %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [148 x i8] c"select_time_step: Error, the time step is too small: %f s.\0Atau = %f, Re = %f, u_max = %f, v_max = %f\0At_diff = %f s, t_adv_u = %f s, t_adv_v = %f s\0A\00"
define double @select_time_step(double %0, double %1, double %2, double %3, i32 %4, i32 %5, double** %6, double** %7) {
%9 = tail call double @max_abs_value(double** %6, i32 %4, i32 %5)
%10 = tail call double @max_abs_value(double** %7, i32 %4, i32 %5)
%11 = fmul double %1, 5.000000e-01
%12 = insertelement <2 x double> poison, double %2, i64 0
%13 = insertelement <2 x double> %12, double %3, i64 1
%14 = fmul <2 x double> %13, %13
%15 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %14
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%17 = fadd <2 x double> %15, %16
%18 = extractelement <2 x double> %17, i64 0
%19 = fdiv double 1.000000e+00, %18
%20 = fmul double %11, %19
%21 = fadd double %9, 0x3D719799812DEA11
%22 = fdiv double %2, %21
%23 = fadd double %10, 0x3D719799812DEA11
%24 = fdiv double %2, %23
%25 = tail call double @llvm.minnum.f64(double %22, double %24)
%26 = tail call double @llvm.minnum.f64(double %20, double %25)
%27 = fcmp olt double %26, 0x3D719799812DEA11
br i1 %27, label %28, label %32
28: ; preds = %8
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0), double %26, double %0, double %1, double %9, double %10, double %20, double %22, double %24)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %8
ret double %26
}