float ftg_aspect_correct_scale_for_rect(const float screen[2],
                                        const float rect[2]) {
  float screenAspect = screen[0] / screen[1];
  float rectAspect = rect[0] / rect[1];
  float scaleFactor;
  if (screenAspect > rectAspect)
    scaleFactor = screen[1] / rect[1];
  else
    scaleFactor = screen[0] / rect[0];
  return scaleFactor;
}


x86 assembly (clang, -O0):
<ftg_aspect_correct_scale_for_rect>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
divss  0x4(%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
divss  0x4(%rax),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1163 <ftg_aspect_correct_scale_for_rect+0x63>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x10(%rbp),%rax
divss  0x4(%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1178 <ftg_aspect_correct_scale_for_rect+0x78>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftg_aspect_correct_scale_for_rect>:
movss  (%rdi),%xmm1
movss  0x4(%rdi),%xmm0
movss  (%rsi),%xmm2
movss  0x4(%rsi),%xmm3
movaps %xmm1,%xmm4
unpcklps %xmm2,%xmm4
movaps %xmm0,%xmm5
unpcklps %xmm3,%xmm5
divps  %xmm5,%xmm4
movaps %xmm4,%xmm5
shufps $0x55,%xmm4,%xmm5
ucomiss %xmm5,%xmm4
jbe    1132 <ftg_aspect_correct_scale_for_rect+0x32>
divss  %xmm3,%xmm0
ret
divss  %xmm2,%xmm1
movaps %xmm1,%xmm0
ret

LLVM IR (-O0):
define float @ftg_aspect_correct_scale_for_rect(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float* %0, float** %3
store float* %1, float** %4
%8 = load float*, float** %3
%9 = getelementptr inbounds float, float* %8, i64 0
%10 = load float, float* %9
%11 = load float*, float** %3
%12 = getelementptr inbounds float, float* %11, i64 1
%13 = load float, float* %12
%14 = fdiv float %10, %13
store float %14, float* %5
%15 = load float*, float** %4
%16 = getelementptr inbounds float, float* %15, i64 0
%17 = load float, float* %16
%18 = load float*, float** %4
%19 = getelementptr inbounds float, float* %18, i64 1
%20 = load float, float* %19
%21 = fdiv float %17, %20
store float %21, float* %6
%22 = load float, float* %5
%23 = load float, float* %6
%24 = fcmp ogt float %22, %23
br i1 %24, label %25, label %33
25: ; preds = %2
%26 = load float*, float** %3
%27 = getelementptr inbounds float, float* %26, i64 1
%28 = load float, float* %27
%29 = load float*, float** %4
%30 = getelementptr inbounds float, float* %29, i64 1
%31 = load float, float* %30
%32 = fdiv float %28, %31
store float %32, float* %7
br label %41
33: ; preds = %2
%34 = load float*, float** %3
%35 = getelementptr inbounds float, float* %34, i64 0
%36 = load float, float* %35
%37 = load float*, float** %4
%38 = getelementptr inbounds float, float* %37, i64 0
%39 = load float, float* %38
%40 = fdiv float %36, %39
store float %40, float* %7
br label %41
41: ; preds = %33, %25
%42 = load float, float* %7
ret float %42
}

LLVM IR (-O2):
define float @ftg_aspect_correct_scale_for_rect(float* nocapture %0, float* nocapture %1) {
%3 = load float, float* %0
%4 = getelementptr inbounds float, float* %0, i64 1
%5 = load float, float* %4
%6 = load float, float* %1
%7 = getelementptr inbounds float, float* %1, i64 1
%8 = load float, float* %7
%9 = insertelement <2 x float> poison, float %3, i64 0
%10 = insertelement <2 x float> %9, float %6, i64 1
%11 = insertelement <2 x float> poison, float %5, i64 0
%12 = insertelement <2 x float> %11, float %8, i64 1
%13 = fdiv <2 x float> %10, %12
%14 = extractelement <2 x float> %13, i64 0
%15 = extractelement <2 x float> %13, i64 1
%16 = fcmp ogt float %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = fdiv float %5, %8
br label %21
19: ; preds = %2
%20 = fdiv float %3, %6
br label %21
21: ; preds = %19, %17
%22 = phi float [ %18, %17 ], [ %20, %19 ]
ret float %22
}