#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 array_max_abs(double *, int);
double fabs(double);
int /*<<< orphan*/ free(double *);
double l2norm(double *, int);
scalar_t__ malloc(int);
int stopcheck3_mt(double *xi, double *xf, double fx, int N, double fo,
                  double *jac, double *dx, double eps, double stoptol,
                  double functol, int retval) {
  int rcode, i;
  double nrm, nrmnx, relfit, num, den, stop0;
  double *scheck;
  rcode = 0;
  scheck = (double *)malloc(sizeof(double) * N);
  if (retval == 3) {
    rcode = 4;
    return rcode;
  }
  if (retval == 15) {
    rcode = 15;
    return rcode;
  }
  nrm = l2norm(jac, N);
  nrmnx = nrm / (double)N;
  if (fabs(fo) < eps) {
    relfit = fabs(fx - fo);
  } else {
    relfit = fabs((fx - fo) / fo);
  }
  if (nrmnx < stoptol) {
    rcode = 1;
  } else if (relfit < functol) {
    rcode = 6;
  } else {
    for (i = 0; i < N; ++i) {
      den = 1.0 + fabs(xf[i]);
      num = fabs(xf[i] - xi[i]);
      scheck[i] = num / den;
    }
    stop0 = array_max_abs(scheck, N);
    if (stop0 <= stoptol) {
      rcode = 2;
    }
  }
  free(scheck);
  return rcode;
}


x86 assembly (clang, -O0):
<stopcheck3_mt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
movsd  %xmm2,-0x48(%rbp)
movsd  %xmm3,-0x50(%rbp)
movsd  %xmm4,-0x58(%rbp)
mov    %r9d,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0xa0(%rbp)
cmpl   $0x3,-0x5c(%rbp)
jne    11b4 <stopcheck3_mt+0x74>
movl   $0x4,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    137c <stopcheck3_mt+0x23c>
cmpl   $0xf,-0x5c(%rbp)
jne    11d0 <stopcheck3_mt+0x90>
movl   $0xf,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    137c <stopcheck3_mt+0x23c>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <l2norm@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x30(%rbp),%xmm1
movaps 0xe00(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1232 <stopcheck3_mt+0xf2>
movsd  -0x20(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xddc(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    1251 <stopcheck3_mt+0x111>
movsd  -0x20(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movaps 0xdb8(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x78(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1271 <stopcheck3_mt+0x131>
movl   $0x1,-0x60(%rbp)
jmp    136a <stopcheck3_mt+0x22a>
movsd  -0x80(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1291 <stopcheck3_mt+0x151>
movl   $0x6,-0x60(%rbp)
jmp    1365 <stopcheck3_mt+0x225>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    132b <stopcheck3_mt+0x1eb>
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movaps 0xd48(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xd4c(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xd0f(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
divsd  -0x90(%rbp),%xmm0
ff
mov    -0xa0(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1298 <stopcheck3_mt+0x158>
mov    -0xa0(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <array_max_abs@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x98(%rbp),%xmm1
ff
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1360 <stopcheck3_mt+0x220>
movl   $0x2,-0x60(%rbp)
jmp    1365 <stopcheck3_mt+0x225>
jmp    136a <stopcheck3_mt+0x22a>
mov    -0xa0(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stopcheck3_mt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,%ebx
movsd  %xmm4,0x18(%rsp)
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
mov    %rcx,%rbp
movapd %xmm1,0x20(%rsp)
mov    %edx,%r14d
movapd %xmm0,0x30(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
cmp    $0x3,%ebx
je     119c <stopcheck3_mt+0x5c>
cmp    $0xf,%ebx
jne    11a6 <stopcheck3_mt+0x66>
mov    $0xf,%ebp
jmp    1346 <stopcheck3_mt+0x206>
mov    $0x4,%ebp
jmp    1346 <stopcheck3_mt+0x206>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %r14d,%esi
call   1040 <l2norm@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
mov    $0x1,%ebp
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     133e <stopcheck3_mt+0x1fe>
movapd 0x30(%rsp),%xmm3
movapd 0x20(%rsp),%xmm4
subsd  %xmm4,%xmm3
movapd 0xe13(%rip),%xmm0
movapd %xmm4,%xmm1
andpd  %xmm0,%xmm1
cmpltsd 0x10(%rsp),%xmm1
movsd  0xe1c(%rip),%xmm2
andpd  %xmm1,%xmm2
andnpd %xmm4,%xmm1
orpd   %xmm2,%xmm1
divsd  %xmm1,%xmm3
andpd  %xmm0,%xmm3
mov    $0x6,%ebp
movsd  0x18(%rsp),%xmm1
ucomisd %xmm3,%xmm1
ja     133e <stopcheck3_mt+0x1fe>
test   %r14d,%r14d
jle    1320 <stopcheck3_mt+0x1e0>
mov    %r14d,%eax
cmp    $0x1,%r14d
jne    1246 <stopcheck3_mt+0x106>
xor    %ecx,%ecx
jmp    12d9 <stopcheck3_mt+0x199>
lea    0x0(,%rax,8),%rcx
add    %r13,%rcx
lea    (%r15,%rax,8),%rdx
cmp    %rdx,%r13
setb   %dil
cmp    %r15,%rcx
seta   %bl
lea    (%r12,%rax,8),%rdx
cmp    %rdx,%r13
setb   %dl
cmp    %r12,%rcx
seta   %sil
xor    %ecx,%ecx
test   %bl,%dil
jne    12d9 <stopcheck3_mt+0x199>
and    %sil,%dl
jne    12d9 <stopcheck3_mt+0x199>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
xor    %edx,%edx
movapd 0xd72(%rip),%xmm1
movapd 0xd7a(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
movupd (%r15,%rdx,8),%xmm3
movapd %xmm3,%xmm4
andpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
movupd (%r12,%rdx,8),%xmm5
subpd  %xmm5,%xmm3
andpd  %xmm1,%xmm3
divpd  %xmm4,%xmm3
movupd %xmm3,0x0(%r13,%rdx,8)
add    $0x2,%rdx
cmp    %rdx,%rcx
jne    12a0 <stopcheck3_mt+0x160>
cmp    %rax,%rcx
je     1320 <stopcheck3_mt+0x1e0>
movsd  0xd3f(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%r15,%rcx,8),%xmm2
movapd %xmm2,%xmm3
andpd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
subsd  (%r12,%rcx,8),%xmm2
andpd  %xmm0,%xmm2
divsd  %xmm3,%xmm2
movsd  %xmm2,0x0(%r13,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    12f0 <stopcheck3_mt+0x1b0>
mov    %r13,%rdi
mov    %r14d,%esi
call   1060 <array_max_abs@plt>
xor    %ebp,%ebp
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     133e <stopcheck3_mt+0x1fe>
mov    $0x2,%ebp
mov    %r13,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @stopcheck3_mt(double* %0, double* %1, double %2, i32 %3, double %4, double* %5, double* %6, double %7, double %8, double %9, i32 %10) {
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca double
%16 = alloca i32
%17 = alloca double
%18 = alloca double*
%19 = alloca double*
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca double
%27 = alloca double
%28 = alloca double
%29 = alloca double
%30 = alloca double
%31 = alloca double
%32 = alloca double*
store double* %0, double** %13
store double* %1, double** %14
store double %2, double* %15
store i32 %3, i32* %16
store double %4, double* %17
store double* %5, double** %18
store double* %6, double** %19
store double %7, double* %20
store double %8, double* %21
store double %9, double* %22
store i32 %10, i32* %23
store i32 0, i32* %24
%33 = load i32, i32* %16
%34 = sext i32 %33 to i64
%35 = mul i64 8, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to double*
store double* %38, double** %32
%39 = load i32, i32* %23
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %43
41: ; preds = %11
store i32 4, i32* %24
%42 = load i32, i32* %24
store i32 %42, i32* %12
br label %131
43: ; preds = %11
%44 = load i32, i32* %23
%45 = icmp eq i32 %44, 15
br i1 %45, label %46, label %48
46: ; preds = %43
store i32 15, i32* %24
%47 = load i32, i32* %24
store i32 %47, i32* %12
br label %131
48: ; preds = %43
%49 = load double*, double** %18
%50 = load i32, i32* %16
%51 = call double @l2norm(double* %49, i32 %50)
store double %51, double* %26
%52 = load double, double* %26
%53 = load i32, i32* %16
%54 = sitofp i32 %53 to double
%55 = fdiv double %52, %54
store double %55, double* %27
%56 = load double, double* %17
%57 = call double @llvm.fabs.f64(double %56)
%58 = load double, double* %20
%59 = fcmp olt double %57, %58
br i1 %59, label %60, label %65
60: ; preds = %48
%61 = load double, double* %15
%62 = load double, double* %17
%63 = fsub double %61, %62
%64 = call double @llvm.fabs.f64(double %63)
store double %64, double* %28
br label %72
65: ; preds = %48
%66 = load double, double* %15
%67 = load double, double* %17
%68 = fsub double %66, %67
%69 = load double, double* %17
%70 = fdiv double %68, %69
%71 = call double @llvm.fabs.f64(double %70)
store double %71, double* %28
br label %72
72: ; preds = %65, %60
%73 = load double, double* %27
%74 = load double, double* %21
%75 = fcmp olt double %73, %74
br i1 %75, label %76, label %77
76: ; preds = %72
store i32 1, i32* %24
br label %127
77: ; preds = %72
%78 = load double, double* %28
%79 = load double, double* %22
%80 = fcmp olt double %78, %79
br i1 %80, label %81, label %82
81: ; preds = %77
store i32 6, i32* %24
br label %126
82: ; preds = %77
store i32 0, i32* %25
br label %83
83: ; preds = %114, %82
%84 = load i32, i32* %25
%85 = load i32, i32* %16
%86 = icmp slt i32 %84, %85
br i1 %86, label %87, label %117
87: ; preds = %83
%88 = load double*, double** %14
%89 = load i32, i32* %25
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
%92 = load double, double* %91
%93 = call double @llvm.fabs.f64(double %92)
%94 = fadd double 1.000000e+00, %93
store double %94, double* %30
%95 = load double*, double** %14
%96 = load i32, i32* %25
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds double, double* %95, i64 %97
%99 = load double, double* %98
%100 = load double*, double** %13
%101 = load i32, i32* %25
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %100, i64 %102
%104 = load double, double* %103
%105 = fsub double %99, %104
%106 = call double @llvm.fabs.f64(double %105)
store double %106, double* %29
%107 = load double, double* %29
%108 = load double, double* %30
%109 = fdiv double %107, %108
%110 = load double*, double** %32
%111 = load i32, i32* %25
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds double, double* %110, i64 %112
store double %109, double* %113
br label %114
114: ; preds = %87
%115 = load i32, i32* %25
%116 = add nsw i32 %115, 1
store i32 %116, i32* %25
br label %83
117: ; preds = %83
%118 = load double*, double** %32
%119 = load i32, i32* %16
%120 = call double @array_max_abs(double* %118, i32 %119)
store double %120, double* %31
%121 = load double, double* %31
%122 = load double, double* %21
%123 = fcmp ole double %121, %122
br i1 %123, label %124, label %125
124: ; preds = %117
store i32 2, i32* %24
br label %125
125: ; preds = %124, %117
br label %126
126: ; preds = %125, %81
br label %127
127: ; preds = %126, %76
%128 = load double*, double** %32
%129 = call i32 @free(double* %128)
%130 = load i32, i32* %24
store i32 %130, i32* %12
br label %131
131: ; preds = %127, %46, %41
%132 = load i32, i32* %12
ret i32 %132
}

LLVM IR (-O2):
define i32 @stopcheck3_mt(double* nocapture %0, double* nocapture %1, double %2, i32 %3, double %4, double* %5, double* nocapture readnone %6, double %7, double %8, double %9, i32 %10) {
%12 = shl i32 %3, 3
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
%15 = inttoptr i64 %13 to i8*
switch i32 %10, label %17 [
i32 3, label %92
i32 15, label %16
]
16: ; preds = %11
br label %92
17: ; preds = %11
%18 = tail call double @l2norm(double* %5, i32 %3)
%19 = sitofp i32 %3 to double
%20 = fdiv double %18, %19
%21 = fcmp olt double %20, %8
br i1 %21, label %89, label %22
22: ; preds = %17
%23 = fsub double %2, %4
%24 = tail call double @llvm.fabs.f64(double %4)
%25 = fcmp olt double %24, %7
%26 = select i1 %25, double 1.000000e+00, double %4
%27 = fdiv double %23, %26
%28 = tail call double @llvm.fabs.f64(double %27)
%29 = fcmp olt double %28, %9
br i1 %29, label %89, label %30
30: ; preds = %22
%31 = icmp sgt i32 %3, 0
br i1 %31, label %32, label %85
32: ; preds = %30
%33 = zext i32 %3 to i64
%34 = icmp eq i32 %3, 1
br i1 %34, label %69, label %35
35: ; preds = %32
%36 = getelementptr double, double* %14, i64 %33
%37 = getelementptr double, double* %1, i64 %33
%38 = bitcast double* %37 to i8*
%39 = getelementptr double, double* %0, i64 %33
%40 = bitcast double* %39 to i8*
%41 = icmp ult i8* %15, %38
%42 = icmp ugt double* %36, %1
%43 = and i1 %41, %42
%44 = icmp ult i8* %15, %40
%45 = icmp ugt double* %36, %0
%46 = and i1 %44, %45
%47 = or i1 %43, %46
br i1 %47, label %69, label %48
48: ; preds = %35
%49 = and i64 %33, 4294967294
br label %50
50: ; preds = %50, %48
%51 = phi i64 [ 0, %48 ], [ %65, %50 ]
%52 = getelementptr inbounds double, double* %1, i64 %51
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %54)
%56 = fadd <2 x double> %55, <double 1.000000e+00, double 1.000000e+00>
%57 = getelementptr inbounds double, double* %0, i64 %51
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = fsub <2 x double> %54, %59
%61 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %60)
%62 = fdiv <2 x double> %61, %56
%63 = getelementptr inbounds double, double* %14, i64 %51
%64 = bitcast double* %63 to <2 x double>*
store <2 x double> %62, <2 x double>* %64
%65 = add nuw i64 %51, 2
%66 = icmp eq i64 %65, %49
br i1 %66, label %67, label %50
67: ; preds = %50
%68 = icmp eq i64 %49, %33
br i1 %68, label %85, label %69
69: ; preds = %35, %32, %67
%70 = phi i64 [ 0, %35 ], [ 0, %32 ], [ %49, %67 ]
br label %71
71: ; preds = %69, %71
%72 = phi i64 [ %83, %71 ], [ %70, %69 ]
%73 = getelementptr inbounds double, double* %1, i64 %72
%74 = load double, double* %73
%75 = tail call double @llvm.fabs.f64(double %74)
%76 = fadd double %75, 1.000000e+00
%77 = getelementptr inbounds double, double* %0, i64 %72
%78 = load double, double* %77
%79 = fsub double %74, %78
%80 = tail call double @llvm.fabs.f64(double %79)
%81 = fdiv double %80, %76
%82 = getelementptr inbounds double, double* %14, i64 %72
store double %81, double* %82
%83 = add nuw nsw i64 %72, 1
%84 = icmp eq i64 %83, %33
br i1 %84, label %85, label %71
85: ; preds = %71, %67, %30
%86 = tail call double @array_max_abs(double* %14, i32 %3)
%87 = fcmp ugt double %86, %8
br i1 %87, label %89, label %88
88: ; preds = %85
br label %89
89: ; preds = %22, %17, %88, %85
%90 = phi i32 [ 2, %88 ], [ 0, %85 ], [ 1, %17 ], [ 6, %22 ]
%91 = tail call i32 @free(double* %14)
br label %92
92: ; preds = %11, %89, %16
%93 = phi i32 [ 15, %16 ], [ %90, %89 ], [ 4, %11 ]
ret i32 %93
}