void nlopt_reorder_bounds(unsigned n, double *lb, double *ub) {
  unsigned i;
  for (i = 0; i < n; ++i)
    if (lb[i] > ub[i]) {
      double t = lb[i];
      lb[i] = ub[i];
      ub[i] = t;
    }
}


x86 assembly (clang, -O0):
<nlopt_reorder_bounds>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    118d <nlopt_reorder_bounds+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
ucomisd (%rax,%rcx,8),%xmm0
jbe    117a <nlopt_reorder_bounds+0x7a>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
jmp    117f <nlopt_reorder_bounds+0x7f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1116 <nlopt_reorder_bounds+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<nlopt_reorder_bounds>:
test   %edi,%edi
je     112c <nlopt_reorder_bounds+0x2c>
mov    %edi,%ecx
cmp    $0x1,%edi
jne    112d <nlopt_reorder_bounds+0x2d>
xor    %eax,%eax
test   $0x1,%cl
je     112c <nlopt_reorder_bounds+0x2c>
movsd  (%rsi,%rax,8),%xmm0
movsd  (%rdx,%rax,8),%xmm1
ucomisd %xmm1,%xmm0
jbe    112c <nlopt_reorder_bounds+0x2c>
movsd  %xmm1,(%rsi,%rax,8)
movsd  %xmm0,(%rdx,%rax,8)
ret
mov    %ecx,%edi
and    $0xfffffffe,%edi
xor    %eax,%eax
jmp    1149 <nlopt_reorder_bounds+0x49>
cs nopw 0x0(%rax,%rax,1)
add    $0x2,%rax
cmp    %rax,%rdi
je     110d <nlopt_reorder_bounds+0xd>
movsd  (%rsi,%rax,8),%xmm0
movsd  (%rdx,%rax,8),%xmm1
ucomisd %xmm1,%xmm0
jbe    1163 <nlopt_reorder_bounds+0x63>
movsd  %xmm1,(%rsi,%rax,8)
movsd  %xmm0,(%rdx,%rax,8)
movsd  0x8(%rsi,%rax,8),%xmm0
movsd  0x8(%rdx,%rax,8),%xmm1
ucomisd %xmm1,%xmm0
jbe    1140 <nlopt_reorder_bounds+0x40>
movsd  %xmm1,0x8(%rsi,%rax,8)
movsd  %xmm0,0x8(%rdx,%rax,8)
jmp    1140 <nlopt_reorder_bounds+0x40>

LLVM IR (-O0):
define void @nlopt_reorder_bounds(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store i32 0, i32* %7
br label %9
9: ; preds = %46, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %49
13: ; preds = %9
%14 = load double*, double** %5
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %6
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fcmp ogt double %18, %23
br i1 %24, label %25, label %45
25: ; preds = %13
%26 = load double*, double** %5
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
store double %30, double* %8
%31 = load double*, double** %6
%32 = load i32, i32* %7
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %5
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
store double %35, double* %39
%40 = load double, double* %8
%41 = load double*, double** %6
%42 = load i32, i32* %7
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double %40, double* %44
br label %45
45: ; preds = %25, %13
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add i32 %47, 1
store i32 %48, i32* %7
br label %9
49: ; preds = %9
ret void
}

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