#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 */
double GET_ELEM_E(int);
double GET_ELEM_I(int);
int GET_ELEM_N1(int);
int GET_ELEM_N2(int);
int /*<<< orphan*/ GET_ELEM_TYPE(int);
int /*<<< orphan*/ GET_ELEM_VA(int);
int /*<<< orphan*/ GET_ELEM_VB(int);
double GET_NODE_X(int);
double GET_NODE_Y(int);
double fabs(double);
double md_compute_e_def_y(int /*<<< orphan*/, double, int /*<<< orphan*/,
                          int /*<<< orphan*/, double);
double sqrt(double);
double get_max_def_res(int type, int epos, int div, int *ppos, double *x) {
  int i, n1, n2;
  double val, EI, L, x1, y1, x2, y2;
  double xx = 0.0;
  double max = 0.0;
  int pos = -1;
  n1 = GET_ELEM_N1(epos);
  n2 = GET_ELEM_N2(epos);
  x1 = (GET_NODE_X(n1));
  y1 = (GET_NODE_Y(n1));
  x2 = (GET_NODE_X(n2));
  y2 = (GET_NODE_Y(n2));
  L = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  for (i = 0; i <= div; i++) {
    EI = GET_ELEM_E(epos) * GET_ELEM_I(epos);
    xx = ((double)i / (double)div) * L;
    val = ((md_compute_e_def_y(GET_ELEM_TYPE(epos), L, GET_ELEM_VA(epos),
                               GET_ELEM_VB(epos), xx) /
            EI));
    if (fabs(val) > max) {
      max = val;
      pos = i;
    }
  }
  *ppos = pos;
  *x = ((double)pos / (double)div) * L;
  return (max);
}


x86 assembly (clang, -O0):
<get_max_def_res>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movl   $0xffffffff,-0x7c(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <GET_ELEM_N1@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <GET_ELEM_N2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
call   1080 <GET_NODE_X@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%edi
call   10c0 <GET_NODE_Y@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x2c(%rbp),%edi
call   1080 <GET_NODE_X@plt>
movsd  %xmm0,-0x60(%rbp)
mov    -0x2c(%rbp),%edi
call   10c0 <GET_NODE_Y@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
subsd  -0x50(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm3
subsd  -0x58(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   10b0 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1355 <get_max_def_res+0x1a5>
mov    -0x8(%rbp),%edi
call   1070 <GET_ELEM_E@plt>
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x8(%rbp),%edi
call   1040 <GET_ELEM_I@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x8(%rbp),%edi
call   10d0 <GET_ELEM_TYPE@plt>
mov    %eax,-0x8c(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x8(%rbp),%edi
call   10a0 <GET_ELEM_VA@plt>
mov    %eax,-0x80(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <GET_ELEM_VB@plt>
mov    -0x8c(%rbp),%edi
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x80(%rbp),%esi
mov    %eax,%edx
movsd  -0x70(%rbp),%xmm1
call   1060 <md_compute_e_def_y@plt>
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movaps 0xcdd(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x78(%rbp),%xmm0
jbe    1342 <get_max_def_res+0x192>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x7c(%rbp)
jmp    1347 <get_max_def_res+0x197>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1272 <get_max_def_res+0xc2>
mov    -0x7c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cvtsi2sdl -0x7c(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x78(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_max_def_res>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,0x48(%rsp)
mov    %rcx,0x40(%rsp)
mov    %edx,%r14d
mov    %esi,%r15d
mov    %esi,%edi
call   1030 <GET_ELEM_N1@plt>
mov    %eax,%r12d
mov    %r15d,%edi
call   1090 <GET_ELEM_N2@plt>
mov    %eax,%r13d
mov    %r12d,%edi
call   1080 <GET_NODE_X@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r12d,%edi
call   10c0 <GET_NODE_Y@plt>
movsd  %xmm0,(%rsp)
mov    %r13d,%edi
call   1080 <GET_NODE_X@plt>
movsd  %xmm0,0x30(%rsp)
mov    %r13d,%edi
call   10c0 <GET_NODE_Y@plt>
movsd  0x30(%rsp),%xmm1
subsd  0x10(%rsp),%xmm1
subsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1245 <get_max_def_res+0x95>
sqrtsd %xmm0,%xmm0
jmp    124e <get_max_def_res+0x9e>
call   10b0 <sqrt@plt>
xorpd  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm2
test   %r14d,%r14d
movsd  %xmm0,(%rsp)
movsd  %xmm2,0x28(%rsp)
js     134f <get_max_def_res+0x19f>
add    $0x1,%r14d
xor    %ebp,%ebp
xorpd  %xmm3,%xmm3
mov    $0xffffffff,%r13d
movapd %xmm3,%xmm1
nopl   0x0(%rax,%rax,1)
movapd %xmm3,0x30(%rsp)
movapd %xmm1,0x10(%rsp)
mov    %r15d,%edi
call   1070 <GET_ELEM_E@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
call   1040 <GET_ELEM_I@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  0x28(%rsp),%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x50(%rsp)
mov    %r15d,%edi
call   10d0 <GET_ELEM_TYPE@plt>
mov    %eax,%r12d
mov    %r15d,%edi
call   10a0 <GET_ELEM_VA@plt>
mov    %eax,%ebx
mov    %r15d,%edi
call   1050 <GET_ELEM_VB@plt>
mov    %r12d,%edi
movsd  (%rsp),%xmm0
mov    %ebx,%esi
mov    %eax,%edx
movsd  0x50(%rsp),%xmm1
call   1060 <md_compute_e_def_y@plt>
divsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm1
andpd  0xcf4(%rip),%xmm1
movapd 0x30(%rsp),%xmm3
ucomisd %xmm3,%xmm1
movapd 0x10(%rsp),%xmm2
cmpltsd %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
movapd 0x10(%rsp),%xmm1
andpd  %xmm1,%xmm0
cmova  %ebp,%r13d
andnpd %xmm3,%xmm1
orpd   %xmm0,%xmm1
add    $0x1,%ebp
movapd %xmm1,%xmm3
cmp    %ebp,%r14d
jne    1280 <get_max_def_res+0xd0>
jmp    1355 <get_max_def_res+0x1a5>
mov    $0xffffffff,%r13d
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mov    0x40(%rsp),%rax
mov    %r13d,(%rax)
divsd  0x28(%rsp),%xmm0
movsd  (%rsp),%xmm2
mulsd  %xmm0,%xmm2
mov    0x48(%rsp),%rax
movsd  %xmm2,(%rax)
movapd %xmm1,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @get_max_def_res(i32 %0, i32 %1, i32 %2, i32* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store double* %4, double** %10
store double 0.000000e+00, double* %21
store double 0.000000e+00, double* %22
store i32 -1, i32* %23
%24 = load i32, i32* %7
%25 = call i32 @GET_ELEM_N1(i32 %24)
store i32 %25, i32* %12
%26 = load i32, i32* %7
%27 = call i32 @GET_ELEM_N2(i32 %26)
store i32 %27, i32* %13
%28 = load i32, i32* %12
%29 = call double @GET_NODE_X(i32 %28)
store double %29, double* %17
%30 = load i32, i32* %12
%31 = call double @GET_NODE_Y(i32 %30)
store double %31, double* %18
%32 = load i32, i32* %13
%33 = call double @GET_NODE_X(i32 %32)
store double %33, double* %19
%34 = load i32, i32* %13
%35 = call double @GET_NODE_Y(i32 %34)
store double %35, double* %20
%36 = load double, double* %19
%37 = load double, double* %17
%38 = fsub double %36, %37
%39 = load double, double* %19
%40 = load double, double* %17
%41 = fsub double %39, %40
%42 = load double, double* %20
%43 = load double, double* %18
%44 = fsub double %42, %43
%45 = load double, double* %20
%46 = load double, double* %18
%47 = fsub double %45, %46
%48 = fmul double %44, %47
%49 = call double @llvm.fmuladd.f64(double %38, double %41, double %48)
%50 = call double @sqrt(double %49)
store double %50, double* %16
store i32 0, i32* %11
br label %51
51: ; preds = %87, %5
%52 = load i32, i32* %11
%53 = load i32, i32* %8
%54 = icmp sle i32 %52, %53
br i1 %54, label %55, label %90
55: ; preds = %51
%56 = load i32, i32* %7
%57 = call double @GET_ELEM_E(i32 %56)
%58 = load i32, i32* %7
%59 = call double @GET_ELEM_I(i32 %58)
%60 = fmul double %57, %59
store double %60, double* %15
%61 = load i32, i32* %11
%62 = sitofp i32 %61 to double
%63 = load i32, i32* %8
%64 = sitofp i32 %63 to double
%65 = fdiv double %62, %64
%66 = load double, double* %16
%67 = fmul double %65, %66
store double %67, double* %21
%68 = load i32, i32* %7
%69 = call i32 @GET_ELEM_TYPE(i32 %68)
%70 = load double, double* %16
%71 = load i32, i32* %7
%72 = call i32 @GET_ELEM_VA(i32 %71)
%73 = load i32, i32* %7
%74 = call i32 @GET_ELEM_VB(i32 %73)
%75 = load double, double* %21
%76 = call double @md_compute_e_def_y(i32 %69, double %70, i32 %72, i32 %74, double %75)
%77 = load double, double* %15
%78 = fdiv double %76, %77
store double %78, double* %14
%79 = load double, double* %14
%80 = call double @llvm.fabs.f64(double %79)
%81 = load double, double* %22
%82 = fcmp ogt double %80, %81
br i1 %82, label %83, label %86
83: ; preds = %55
%84 = load double, double* %14
store double %84, double* %22
%85 = load i32, i32* %11
store i32 %85, i32* %23
br label %86
86: ; preds = %83, %55
br label %87
87: ; preds = %86
%88 = load i32, i32* %11
%89 = add nsw i32 %88, 1
store i32 %89, i32* %11
br label %51
90: ; preds = %51
%91 = load i32, i32* %23
%92 = load i32*, i32** %9
store i32 %91, i32* %92
%93 = load i32, i32* %23
%94 = sitofp i32 %93 to double
%95 = load i32, i32* %8
%96 = sitofp i32 %95 to double
%97 = fdiv double %94, %96
%98 = load double, double* %16
%99 = fmul double %97, %98
%100 = load double*, double** %10
store double %99, double* %100
%101 = load double, double* %22
ret double %101
}

LLVM IR (-O2):
define double @get_max_def_res(i32 %0, i32 %1, i32 %2, i32* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = tail call i32 @GET_ELEM_N1(i32 %1)
%7 = tail call i32 @GET_ELEM_N2(i32 %1)
%8 = tail call double @GET_NODE_X(i32 %6)
%9 = tail call double @GET_NODE_Y(i32 %6)
%10 = tail call double @GET_NODE_X(i32 %7)
%11 = tail call double @GET_NODE_Y(i32 %7)
%12 = fsub double %10, %8
%13 = fsub double %11, %9
%14 = fmul double %13, %13
%15 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %14)
%16 = tail call double @sqrt(double %15)
%17 = icmp slt i32 %2, 0
%18 = sitofp i32 %2 to double
br i1 %17, label %40, label %19
19: ; preds = %5, %19
%20 = phi i32 [ %37, %19 ], [ -1, %5 ]
%21 = phi double [ %36, %19 ], [ 0.000000e+00, %5 ]
%22 = phi i32 [ %38, %19 ], [ 0, %5 ]
%23 = tail call double @GET_ELEM_E(i32 %1)
%24 = tail call double @GET_ELEM_I(i32 %1)
%25 = fmul double %23, %24
%26 = sitofp i32 %22 to double
%27 = fdiv double %26, %18
%28 = fmul double %16, %27
%29 = tail call i32 @GET_ELEM_TYPE(i32 %1)
%30 = tail call i32 @GET_ELEM_VA(i32 %1)
%31 = tail call i32 @GET_ELEM_VB(i32 %1)
%32 = tail call double @md_compute_e_def_y(i32 %29, double %16, i32 %30, i32 %31, double %28)
%33 = fdiv double %32, %25
%34 = tail call double @llvm.fabs.f64(double %33)
%35 = fcmp ogt double %34, %21
%36 = select i1 %35, double %33, double %21
%37 = select i1 %35, i32 %22, i32 %20
%38 = add nuw i32 %22, 1
%39 = icmp eq i32 %22, %2
br i1 %39, label %40, label %19
40: ; preds = %19, %5
%41 = phi double [ 0.000000e+00, %5 ], [ %36, %19 ]
%42 = phi i32 [ -1, %5 ], [ %37, %19 ]
store i32 %42, i32* %3
%43 = sitofp i32 %42 to double
%44 = fdiv double %43, %18
%45 = fmul double %16, %44
store double %45, double* %4
ret double %41
}