double convert_to_scientific_notation(double number) {
  if (number < 0) {
    number = 0 - number;
  }
  if (number < 1)
    while (number <= 1) {
      number *= 2;
    }
  else {
    while (number > 2) {
      number /= 2;
    }
  }
  return number;
}


x86 assembly (clang, -O0):
<convert_to_scientific_notation>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1124 <convert_to_scientific_notation+0x24>
xorps  %xmm0,%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xed4(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    116b <convert_to_scientific_notation+0x6b>
jmp    113c <convert_to_scientific_notation+0x3c>
movsd  0xebc(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1166 <convert_to_scientific_notation+0x66>
movsd  0xeb1(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    113c <convert_to_scientific_notation+0x3c>
jmp    11a7 <convert_to_scientific_notation+0xa7>
jmp    1170 <convert_to_scientific_notation+0x70>
movsd  -0x8(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a2 <convert_to_scientific_notation+0xa2>
movsd  -0x8(%rbp),%xmm0
movsd  0xe74(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1170 <convert_to_scientific_notation+0x70>
jmp    11a7 <convert_to_scientific_notation+0xa7>
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_to_scientific_notation>:
movapd %xmm0,%xmm1
xorpd  %xmm2,%xmm2
cmpltsd %xmm2,%xmm0
subsd  %xmm1,%xmm2
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
movsd  0xedb(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1142 <convert_to_scientific_notation+0x42>
nopl   0x0(%rax,%rax,1)
ucomisd %xmm0,%xmm1
jb     116a <convert_to_scientific_notation+0x6a>
addsd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jae    1136 <convert_to_scientific_notation+0x36>
jmp    116a <convert_to_scientific_notation+0x6a>
ucomisd 0xebe(%rip),%xmm0
jbe    116a <convert_to_scientific_notation+0x6a>
movsd  0xebc(%rip),%xmm1
movsd  0xeac(%rip),%xmm2
nopl   0x0(%rax)
mulsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
ja     1160 <convert_to_scientific_notation+0x60>
ret

LLVM IR (-O0):
define double @convert_to_scientific_notation(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fcmp olt double %3, 0.000000e+00
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load double, double* %2
%7 = fsub double 0.000000e+00, %6
store double %7, double* %2
br label %8
8: ; preds = %5, %1
%9 = load double, double* %2
%10 = fcmp olt double %9, 1.000000e+00
br i1 %10, label %11, label %19
11: ; preds = %8
br label %12
12: ; preds = %15, %11
%13 = load double, double* %2
%14 = fcmp ole double %13, 1.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load double, double* %2
%17 = fmul double %16, 2.000000e+00
store double %17, double* %2
br label %12
18: ; preds = %12
br label %27
19: ; preds = %8
br label %20
20: ; preds = %23, %19
%21 = load double, double* %2
%22 = fcmp ogt double %21, 2.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load double, double* %2
%25 = fdiv double %24, 2.000000e+00
store double %25, double* %2
br label %20
26: ; preds = %20
br label %27
27: ; preds = %26, %18
%28 = load double, double* %2
ret double %28
}

LLVM IR (-O2):
define double @convert_to_scientific_notation(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fsub double 0.000000e+00, %0
%4 = select i1 %2, double %3, double %0
%5 = fcmp olt double %4, 1.000000e+00
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = fcmp ogt double %4, 2.000000e+00
br i1 %7, label %14, label %18
8: ; preds = %1
%9 = fcmp ugt double %4, 1.000000e+00
br i1 %9, label %18, label %10
10: ; preds = %8, %10
%11 = phi double [ %12, %10 ], [ %4, %8 ]
%12 = fmul double %11, 2.000000e+00
%13 = fcmp ugt double %12, 1.000000e+00
br i1 %13, label %18, label %10
14: ; preds = %6, %14
%15 = phi double [ %16, %14 ], [ %4, %6 ]
%16 = fmul double %15, 5.000000e-01
%17 = fcmp ogt double %16, 2.000000e+00
br i1 %17, label %14, label %18
18: ; preds = %14, %10, %6, %8
%19 = phi double [ %4, %8 ], [ %4, %6 ], [ %12, %10 ], [ %16, %14 ]
ret double %19
}