#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*/ atom_info(int, int /*<<< orphan*/ *, double *,
                             int /*<<< orphan*/ *);
double fabs(double);
int /*<<< orphan*/ nrerror(char *);
double veclen(double *);
void atom_linkage(long ib, long ie, long *idx, double **xyz,
                  long nbond_estimated, long *nbond, long **linkage) {
  double dst, dxyz[4], covalence_radii[12];
  long j, k, m;
  atom_info(2, NULL, covalence_radii, NULL);
  for (j = ib; j <= ie - 1; j++)
    for (k = j + 1; k <= ie; k++) {
      dst = 1.15 * (covalence_radii[idx[j]] + covalence_radii[idx[k]]);
      for (m = 1; m <= 3; m++)
        if (fabs(dxyz[m] = xyz[j][m] - xyz[k][m]) > dst)
          break;
      if (m > 3 && veclen(dxyz) <= dst) {
        if (++*nbond > nbond_estimated)
          nrerror("too many linkages");
        else {
          linkage[*nbond][1] = j;
          linkage[*nbond][2] = k;
        }
      }
    }
}


x86 assembly (clang, -O0):
<atom_linkage>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0xc0(%rbp),%rdx
mov    $0x2,%edi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
call   1040 <atom_info@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0xc8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jg     134c <atom_linkage+0x21c>
mov    -0xc8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     1330 <atom_linkage+0x200>
mov    -0x18(%rbp),%rax
mov    -0xc8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  -0xc0(%rbp,%rax,8),%xmm1
ff ff
mov    -0x18(%rbp),%rax
mov    -0xd0(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
addsd  -0xc0(%rbp,%rax,8),%xmm1
ff ff
movsd  0xe13(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x1,-0xd8(%rbp)
cmpq   $0x3,-0xd8(%rbp)
03
jg     1289 <atom_linkage+0x159>
mov    -0x20(%rbp),%rax
mov    -0xc8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0xd8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0xd0(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0xd8(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0xd8(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
movaps 0xdb7(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    126d <atom_linkage+0x13d>
jmp    1289 <atom_linkage+0x159>
jmp    1272 <atom_linkage+0x142>
mov    -0xd8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd8(%rbp)
jmp    1201 <atom_linkage+0xd1>
cmpq   $0x3,-0xd8(%rbp)
03
jle    1314 <atom_linkage+0x1e4>
lea    -0x60(%rbp),%rdi
call   1050 <veclen@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1314 <atom_linkage+0x1e4>
mov    -0x30(%rbp),%rcx
mov    (%rcx),%rax
add    $0x1,%rax
mov    %rax,(%rcx)
cmp    -0x28(%rbp),%rax
jle    12db <atom_linkage+0x1ab>
lea    0xd4f(%rip),%rdi
call   1030 <nrerror@plt>
jmp    130f <atom_linkage+0x1df>
mov    -0xc8(%rbp),%rcx
mov    0x10(%rbp),%rax
mov    -0x30(%rbp),%rdx
mov    (%rdx),%rdx
mov    (%rax,%rdx,8),%rax
mov    %rcx,0x8(%rax)
mov    -0xd0(%rbp),%rcx
mov    0x10(%rbp),%rax
mov    -0x30(%rbp),%rdx
mov    (%rdx),%rdx
mov    (%rax,%rdx,8),%rax
mov    %rcx,0x10(%rax)
jmp    1314 <atom_linkage+0x1e4>
jmp    1319 <atom_linkage+0x1e9>
mov    -0xd0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd0(%rbp)
jmp    11a4 <atom_linkage+0x74>
jmp    1335 <atom_linkage+0x205>
mov    -0xc8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc8(%rbp)
jmp    117a <atom_linkage+0x4a>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atom_linkage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9,%r15
mov    %r8,0x10(%rsp)
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0x40(%rsp),%rdx
mov    $0x2,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <atom_info@plt>
cmp    %r13,%rbp
jge    12b0 <atom_linkage+0x180>
movsd  0xe87(%rip),%xmm1
movapd 0xe8f(%rip),%xmm2
jmp    119e <atom_linkage+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsp),%rbp
cmp    %r13,%rbp
je     12b0 <atom_linkage+0x180>
lea    0x1(%rbp),%r14
mov    %r14,0x8(%rsp)
jmp    11dc <atom_linkage+0xac>
mov    0xe0(%rsp),%rcx
mov    0x8(%rcx,%rax,8),%rax
mov    %rbp,0x8(%rax)
mov    (%r15),%rax
mov    (%rcx,%rax,8),%rax
mov    %r14,0x10(%rax)
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%r14),%rax
cmp    %r13,%r14
mov    %rax,%r14
jge    1190 <atom_linkage+0x60>
mov    (%rbx,%rbp,8),%rax
movsd  0x40(%rsp,%rax,8),%xmm3
mov    (%rbx,%r14,8),%rax
addsd  0x40(%rsp,%rax,8),%xmm3
mulsd  %xmm1,%xmm3
mov    (%r12,%rbp,8),%rcx
mov    (%r12,%r14,8),%rax
movsd  0x8(%rcx),%xmm0
subsd  0x8(%rax),%xmm0
movsd  %xmm0,0x28(%rsp)
andpd  %xmm2,%xmm0
ucomisd %xmm3,%xmm0
ja     11d0 <atom_linkage+0xa0>
movsd  0x10(%rcx),%xmm0
subsd  0x10(%rax),%xmm0
movsd  %xmm0,0x30(%rsp)
andpd  %xmm2,%xmm0
ucomisd %xmm3,%xmm0
ja     11d0 <atom_linkage+0xa0>
movsd  0x18(%rcx),%xmm0
subsd  0x18(%rax),%xmm0
movsd  %xmm0,0x38(%rsp)
andpd  %xmm2,%xmm0
ucomisd %xmm3,%xmm0
ja     11d0 <atom_linkage+0xa0>
lea    0x20(%rsp),%rdi
movsd  %xmm3,0x18(%rsp)
call   1050 <veclen@plt>
movapd 0xdae(%rip),%xmm2
movsd  0xd96(%rip),%xmm1
movsd  0x18(%rsp),%xmm3
ucomisd %xmm0,%xmm3
jb     11d0 <atom_linkage+0xa0>
mov    (%r15),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%r15)
cmp    0x10(%rsp),%rax
jl     11a9 <atom_linkage+0x79>
lea    0xd8a(%rip),%rdi
call   1030 <nrerror@plt>
movapd 0xd6d(%rip),%xmm2
movsd  0xd55(%rip),%xmm1
jmp    11d0 <atom_linkage+0xa0>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"too many linkages\00"
define void @atom_linkage(i64 %0, i64 %1, i64* %2, double** %3, i64 %4, i64* %5, i64** %6) {
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64*
%11 = alloca double**
%12 = alloca i64
%13 = alloca i64*
%14 = alloca i64**
%15 = alloca double
%16 = alloca [4 x double]
%17 = alloca [12 x double]
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
store i64 %0, i64* %8
store i64 %1, i64* %9
store i64* %2, i64** %10
store double** %3, double*** %11
store i64 %4, i64* %12
store i64* %5, i64** %13
store i64** %6, i64*** %14
%21 = getelementptr inbounds [12 x double], [12 x double]* %17, i64 0, i64 0
%22 = call i32 @atom_info(i32 2, i32* null, double* %21, i32* null)
%23 = load i64, i64* %8
store i64 %23, i64* %18
br label %24
24: ; preds = %117, %7
%25 = load i64, i64* %18
%26 = load i64, i64* %9
%27 = sub nsw i64 %26, 1
%28 = icmp sle i64 %25, %27
br i1 %28, label %29, label %120
29: ; preds = %24
%30 = load i64, i64* %18
%31 = add nsw i64 %30, 1
store i64 %31, i64* %19
br label %32
32: ; preds = %113, %29
%33 = load i64, i64* %19
%34 = load i64, i64* %9
%35 = icmp sle i64 %33, %34
br i1 %35, label %36, label %116
36: ; preds = %32
%37 = load i64*, i64** %10
%38 = load i64, i64* %18
%39 = getelementptr inbounds i64, i64* %37, i64 %38
%40 = load i64, i64* %39
%41 = getelementptr inbounds [12 x double], [12 x double]* %17, i64 0, i64 %40
%42 = load double, double* %41
%43 = load i64*, i64** %10
%44 = load i64, i64* %19
%45 = getelementptr inbounds i64, i64* %43, i64 %44
%46 = load i64, i64* %45
%47 = getelementptr inbounds [12 x double], [12 x double]* %17, i64 0, i64 %46
%48 = load double, double* %47
%49 = fadd double %42, %48
%50 = fmul double 1.150000e+00, %49
store double %50, double* %15
store i64 1, i64* %20
br label %51
51: ; preds = %77, %36
%52 = load i64, i64* %20
%53 = icmp sle i64 %52, 3
br i1 %53, label %54, label %80
54: ; preds = %51
%55 = load double**, double*** %11
%56 = load i64, i64* %18
%57 = getelementptr inbounds double*, double** %55, i64 %56
%58 = load double*, double** %57
%59 = load i64, i64* %20
%60 = getelementptr inbounds double, double* %58, i64 %59
%61 = load double, double* %60
%62 = load double**, double*** %11
%63 = load i64, i64* %19
%64 = getelementptr inbounds double*, double** %62, i64 %63
%65 = load double*, double** %64
%66 = load i64, i64* %20
%67 = getelementptr inbounds double, double* %65, i64 %66
%68 = load double, double* %67
%69 = fsub double %61, %68
%70 = load i64, i64* %20
%71 = getelementptr inbounds [4 x double], [4 x double]* %16, i64 0, i64 %70
store double %69, double* %71
%72 = call double @llvm.fabs.f64(double %69)
%73 = load double, double* %15
%74 = fcmp ogt double %72, %73
br i1 %74, label %75, label %76
75: ; preds = %54
br label %80
76: ; preds = %54
br label %77
77: ; preds = %76
%78 = load i64, i64* %20
%79 = add nsw i64 %78, 1
store i64 %79, i64* %20
br label %51
80: ; preds = %75, %51
%81 = load i64, i64* %20
%82 = icmp sgt i64 %81, 3
br i1 %82, label %83, label %112
83: ; preds = %80
%84 = getelementptr inbounds [4 x double], [4 x double]* %16, i64 0, i64 0
%85 = call double @veclen(double* %84)
%86 = load double, double* %15
%87 = fcmp ole double %85, %86
br i1 %87, label %88, label %112
88: ; preds = %83
%89 = load i64*, i64** %13
%90 = load i64, i64* %89
%91 = add nsw i64 %90, 1
store i64 %91, i64* %89
%92 = load i64, i64* %12
%93 = icmp sgt i64 %91, %92
br i1 %93, label %94, label %96
94: ; preds = %88
%95 = call i32 @nrerror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %111
96: ; preds = %88
%97 = load i64, i64* %18
%98 = load i64**, i64*** %14
%99 = load i64*, i64** %13
%100 = load i64, i64* %99
%101 = getelementptr inbounds i64*, i64** %98, i64 %100
%102 = load i64*, i64** %101
%103 = getelementptr inbounds i64, i64* %102, i64 1
store i64 %97, i64* %103
%104 = load i64, i64* %19
%105 = load i64**, i64*** %14
%106 = load i64*, i64** %13
%107 = load i64, i64* %106
%108 = getelementptr inbounds i64*, i64** %105, i64 %107
%109 = load i64*, i64** %108
%110 = getelementptr inbounds i64, i64* %109, i64 2
store i64 %104, i64* %110
br label %111
111: ; preds = %96, %94
br label %112
112: ; preds = %111, %83, %80
br label %113
113: ; preds = %112
%114 = load i64, i64* %19
%115 = add nsw i64 %114, 1
store i64 %115, i64* %19
br label %32
116: ; preds = %32
br label %117
117: ; preds = %116
%118 = load i64, i64* %18
%119 = add nsw i64 %118, 1
store i64 %119, i64* %18
br label %24
120: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"too many linkages\00"
define void @atom_linkage(i64 %0, i64 %1, i64* nocapture %2, double** nocapture %3, i64 %4, i64* nocapture %5, i64** nocapture %6) {
%8 = alloca [4 x double]
%9 = alloca [12 x double]
%10 = bitcast [4 x double]* %8 to i8*
%11 = bitcast [12 x double]* %9 to i8*
%12 = getelementptr inbounds [12 x double], [12 x double]* %9, i64 0, i64 0
%13 = call i32 @atom_info(i32 2, i32* null, double* %12, i32* null)
%14 = icmp slt i64 %0, %1
br i1 %14, label %15, label %84
15: ; preds = %7
%16 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%17 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
%18 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
%19 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 3
br label %22
20: ; preds = %81
%21 = icmp eq i64 %24, %1
br i1 %21, label %84, label %22
22: ; preds = %20, %15
%23 = phi i64 [ %0, %15 ], [ %24, %20 ]
%24 = add i64 %23, 1
%25 = getelementptr inbounds i64, i64* %2, i64 %23
%26 = getelementptr inbounds double*, double** %3, i64 %23
br label %27
27: ; preds = %22, %81
%28 = phi i64 [ %24, %22 ], [ %82, %81 ]
%29 = load i64, i64* %25
%30 = getelementptr inbounds [12 x double], [12 x double]* %9, i64 0, i64 %29
%31 = load double, double* %30
%32 = getelementptr inbounds i64, i64* %2, i64 %28
%33 = load i64, i64* %32
%34 = getelementptr inbounds [12 x double], [12 x double]* %9, i64 0, i64 %33
%35 = load double, double* %34
%36 = fadd double %31, %35
%37 = fmul double %36, 1.150000e+00
%38 = load double*, double** %26
%39 = getelementptr inbounds double*, double** %3, i64 %28
%40 = load double*, double** %39
%41 = getelementptr inbounds double, double* %38, i64 1
%42 = load double, double* %41
%43 = getelementptr inbounds double, double* %40, i64 1
%44 = load double, double* %43
%45 = fsub double %42, %44
store double %45, double* %17
%46 = call double @llvm.fabs.f64(double %45)
%47 = fcmp ogt double %46, %37
br i1 %47, label %81, label %48
48: ; preds = %27
%49 = getelementptr inbounds double, double* %38, i64 2
%50 = load double, double* %49
%51 = getelementptr inbounds double, double* %40, i64 2
%52 = load double, double* %51
%53 = fsub double %50, %52
store double %53, double* %18
%54 = call double @llvm.fabs.f64(double %53)
%55 = fcmp ogt double %54, %37
br i1 %55, label %81, label %56
56: ; preds = %48
%57 = getelementptr inbounds double, double* %38, i64 3
%58 = load double, double* %57
%59 = getelementptr inbounds double, double* %40, i64 3
%60 = load double, double* %59
%61 = fsub double %58, %60
store double %61, double* %19
%62 = call double @llvm.fabs.f64(double %61)
%63 = fcmp ogt double %62, %37
br i1 %63, label %81, label %64
64: ; preds = %56
%65 = call double @veclen(double* %16)
%66 = fcmp ugt double %65, %37
br i1 %66, label %81, label %67
67: ; preds = %64
%68 = load i64, i64* %5
%69 = add nsw i64 %68, 1
store i64 %69, i64* %5
%70 = icmp slt i64 %68, %4
br i1 %70, label %73, label %71
71: ; preds = %67
%72 = call i32 @nrerror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %81
73: ; preds = %67
%74 = getelementptr inbounds i64*, i64** %6, i64 %69
%75 = load i64*, i64** %74
%76 = getelementptr inbounds i64, i64* %75, i64 1
store i64 %23, i64* %76
%77 = load i64, i64* %5
%78 = getelementptr inbounds i64*, i64** %6, i64 %77
%79 = load i64*, i64** %78
%80 = getelementptr inbounds i64, i64* %79, i64 2
store i64 %28, i64* %80
br label %81
81: ; preds = %27, %48, %56, %64, %73, %71
%82 = add nsw i64 %28, 1
%83 = icmp slt i64 %28, %1
br i1 %83, label %27, label %20
84: ; preds = %20, %7
ret void
}