void boundbox_from_corners(long ic, long nc, const double *restrict corner_lon,
                           const double *restrict corner_lat,
                           double *restrict bound_box) {
  long inc, j;
  double clon, clat;
  inc = ic * nc;
  clat = corner_lat[inc];
  clon = corner_lon[inc];
  bound_box[0] = clat;
  bound_box[1] = clat;
  bound_box[2] = clon;
  bound_box[3] = clon;
  for (j = 1; j < nc; ++j) {
    clat = corner_lat[inc + j];
    clon = corner_lon[inc + j];
    if (clat < bound_box[0])
      bound_box[0] = clat;
    if (clat > bound_box[1])
      bound_box[1] = clat;
    if (clon < bound_box[2])
      bound_box[2] = clon;
    if (clon > bound_box[3])
      bound_box[3] = clon;
  }
}


x86 assembly (clang, -O0):
<boundbox_from_corners>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movq   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1266 <boundbox_from_corners+0x166>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e6 <boundbox_from_corners+0xe6>
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
ucomisd 0x8(%rax),%xmm0
jbe    1208 <boundbox_from_corners+0x108>
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x40(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movsd  0x10(%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    122e <boundbox_from_corners+0x12e>
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
ucomisd 0x18(%rax),%xmm0
jbe    1250 <boundbox_from_corners+0x150>
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    1255 <boundbox_from_corners+0x155>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1188 <boundbox_from_corners+0x88>
pop    %rbp
ret

x86 assembly (clang, -O2):
<boundbox_from_corners>:
imul   %rsi,%rdi
movsd  (%rcx,%rdi,8),%xmm0
movsd  (%rdx,%rdi,8),%xmm1
movsd  %xmm0,(%r8)
movsd  %xmm0,0x8(%r8)
movsd  %xmm1,0x10(%r8)
movsd  %xmm1,0x18(%r8)
cmp    $0x2,%rsi
jl     11a4 <boundbox_from_corners+0xa4>
lea    (%rdx,%rdi,8),%rax
lea    (%rcx,%rdi,8),%rcx
mov    $0x1,%edx
movapd %xmm1,%xmm2
movapd %xmm0,%xmm3
jmp    1159 <boundbox_from_corners+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rdx
cmp    %rdx,%rsi
je     11a4 <boundbox_from_corners+0xa4>
movsd  (%rcx,%rdx,8),%xmm4
ucomisd %xmm4,%xmm3
jbe    116d <boundbox_from_corners+0x6d>
movsd  %xmm4,(%r8)
movapd %xmm4,%xmm3
ucomisd %xmm0,%xmm4
jbe    117d <boundbox_from_corners+0x7d>
movsd  %xmm4,0x8(%r8)
movapd %xmm4,%xmm0
movsd  (%rax,%rdx,8),%xmm4
ucomisd %xmm4,%xmm2
jbe    1192 <boundbox_from_corners+0x92>
movsd  %xmm4,0x10(%r8)
movapd %xmm4,%xmm2
ucomisd %xmm1,%xmm4
jbe    1150 <boundbox_from_corners+0x50>
movsd  %xmm4,0x18(%r8)
movapd %xmm4,%xmm1
jmp    1150 <boundbox_from_corners+0x50>
ret

LLVM IR (-O0):
define void @boundbox_from_corners(i64 %0, i64 %1, double* noalias %2, double* noalias %3, double* noalias %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
%14 = alloca double
store i64 %0, i64* %6
store i64 %1, i64* %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%15 = load i64, i64* %6
%16 = load i64, i64* %7
%17 = mul nsw i64 %15, %16
store i64 %17, i64* %11
%18 = load double*, double** %9
%19 = load i64, i64* %11
%20 = getelementptr inbounds double, double* %18, i64 %19
%21 = load double, double* %20
store double %21, double* %14
%22 = load double*, double** %8
%23 = load i64, i64* %11
%24 = getelementptr inbounds double, double* %22, i64 %23
%25 = load double, double* %24
store double %25, double* %13
%26 = load double, double* %14
%27 = load double*, double** %10
%28 = getelementptr inbounds double, double* %27, i64 0
store double %26, double* %28
%29 = load double, double* %14
%30 = load double*, double** %10
%31 = getelementptr inbounds double, double* %30, i64 1
store double %29, double* %31
%32 = load double, double* %13
%33 = load double*, double** %10
%34 = getelementptr inbounds double, double* %33, i64 2
store double %32, double* %34
%35 = load double, double* %13
%36 = load double*, double** %10
%37 = getelementptr inbounds double, double* %36, i64 3
store double %35, double* %37
store i64 1, i64* %12
br label %38
38: ; preds = %95, %5
%39 = load i64, i64* %12
%40 = load i64, i64* %7
%41 = icmp slt i64 %39, %40
br i1 %41, label %42, label %98
42: ; preds = %38
%43 = load double*, double** %9
%44 = load i64, i64* %11
%45 = load i64, i64* %12
%46 = add nsw i64 %44, %45
%47 = getelementptr inbounds double, double* %43, i64 %46
%48 = load double, double* %47
store double %48, double* %14
%49 = load double*, double** %8
%50 = load i64, i64* %11
%51 = load i64, i64* %12
%52 = add nsw i64 %50, %51
%53 = getelementptr inbounds double, double* %49, i64 %52
%54 = load double, double* %53
store double %54, double* %13
%55 = load double, double* %14
%56 = load double*, double** %10
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
%59 = fcmp olt double %55, %58
br i1 %59, label %60, label %64
60: ; preds = %42
%61 = load double, double* %14
%62 = load double*, double** %10
%63 = getelementptr inbounds double, double* %62, i64 0
store double %61, double* %63
br label %64
64: ; preds = %60, %42
%65 = load double, double* %14
%66 = load double*, double** %10
%67 = getelementptr inbounds double, double* %66, i64 1
%68 = load double, double* %67
%69 = fcmp ogt double %65, %68
br i1 %69, label %70, label %74
70: ; preds = %64
%71 = load double, double* %14
%72 = load double*, double** %10
%73 = getelementptr inbounds double, double* %72, i64 1
store double %71, double* %73
br label %74
74: ; preds = %70, %64
%75 = load double, double* %13
%76 = load double*, double** %10
%77 = getelementptr inbounds double, double* %76, i64 2
%78 = load double, double* %77
%79 = fcmp olt double %75, %78
br i1 %79, label %80, label %84
80: ; preds = %74
%81 = load double, double* %13
%82 = load double*, double** %10
%83 = getelementptr inbounds double, double* %82, i64 2
store double %81, double* %83
br label %84
84: ; preds = %80, %74
%85 = load double, double* %13
%86 = load double*, double** %10
%87 = getelementptr inbounds double, double* %86, i64 3
%88 = load double, double* %87
%89 = fcmp ogt double %85, %88
br i1 %89, label %90, label %94
90: ; preds = %84
%91 = load double, double* %13
%92 = load double*, double** %10
%93 = getelementptr inbounds double, double* %92, i64 3
store double %91, double* %93
br label %94
94: ; preds = %90, %84
br label %95
95: ; preds = %94
%96 = load i64, i64* %12
%97 = add nsw i64 %96, 1
store i64 %97, i64* %12
br label %38
98: ; preds = %38
ret void
}

LLVM IR (-O2):
define void @boundbox_from_corners(i64 %0, i64 %1, double* noalias nocapture %2, double* noalias nocapture %3, double* noalias nocapture %4) {
%6 = mul nsw i64 %1, %0
%7 = getelementptr inbounds double, double* %3, i64 %6
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %2, i64 %6
%10 = load double, double* %9
store double %8, double* %4
%11 = getelementptr inbounds double, double* %4, i64 1
store double %8, double* %11
%12 = getelementptr inbounds double, double* %4, i64 2
store double %10, double* %12
%13 = getelementptr inbounds double, double* %4, i64 3
store double %10, double* %13
%14 = icmp sgt i64 %1, 1
br i1 %14, label %15, label %44
15: ; preds = %5, %40
%16 = phi double [ %41, %40 ], [ %10, %5 ]
%17 = phi double [ %37, %40 ], [ %10, %5 ]
%18 = phi double [ %33, %40 ], [ %8, %5 ]
%19 = phi double [ %29, %40 ], [ %8, %5 ]
%20 = phi i64 [ %42, %40 ], [ 1, %5 ]
%21 = add nsw i64 %20, %6
%22 = getelementptr inbounds double, double* %3, i64 %21
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %2, i64 %21
%25 = load double, double* %24
%26 = fcmp olt double %23, %19
br i1 %26, label %27, label %28
27: ; preds = %15
store double %23, double* %4
br label %28
28: ; preds = %27, %15
%29 = phi double [ %23, %27 ], [ %19, %15 ]
%30 = fcmp ogt double %23, %18
br i1 %30, label %31, label %32
31: ; preds = %28
store double %23, double* %11
br label %32
32: ; preds = %31, %28
%33 = phi double [ %23, %31 ], [ %18, %28 ]
%34 = fcmp olt double %25, %17
br i1 %34, label %35, label %36
35: ; preds = %32
store double %25, double* %12
br label %36
36: ; preds = %35, %32
%37 = phi double [ %25, %35 ], [ %17, %32 ]
%38 = fcmp ogt double %25, %16
br i1 %38, label %39, label %40
39: ; preds = %36
store double %25, double* %13
br label %40
40: ; preds = %36, %39
%41 = phi double [ %16, %36 ], [ %25, %39 ]
%42 = add nuw nsw i64 %20, 1
%43 = icmp eq i64 %42, %1
br i1 %43, label %44, label %15
44: ; preds = %40, %5
ret void
}