#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 */
typedef double uint64_t;
typedef double uint32_t;

/* Variables and functions */
void fix_ratio(uint32_t src_width, uint32_t src_height, uint32_t *out_width,
               uint32_t *out_height) {
  double width_ratio, height_ratio;
  width_ratio = *out_width / (double)src_width;
  height_ratio = *out_height / (double)src_height;
  if (width_ratio < height_ratio) {
    *out_height = (uint64_t)src_height * *out_width / src_width;
    *out_height = *out_height ? *out_height : 1;
  } else {
    *out_width = (uint64_t)src_width * *out_height / src_height;
    *out_width = *out_width ? *out_width : 1;
  }
}


x86 assembly (clang, -O0):
<fix_ratio>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11be <fix_ratio+0xbe>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm0
divsd  -0x8(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1188 <fix_ratio+0x88>
jp     1188 <fix_ratio+0x88>
jmp    119a <fix_ratio+0x9a>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11ac <fix_ratio+0xac>
movsd  0xe5e(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11ac <fix_ratio+0xac>
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1229 <fix_ratio+0x129>
movsd  -0x8(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f8 <fix_ratio+0xf8>
jp     11f8 <fix_ratio+0xf8>
jmp    120a <fix_ratio+0x10a>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    121c <fix_ratio+0x11c>
movsd  0xdee(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    121c <fix_ratio+0x11c>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_ratio>:
movsd  (%rdi),%xmm2
movsd  (%rsi),%xmm3
movapd %xmm2,%xmm4
unpcklpd %xmm3,%xmm4
movapd %xmm0,%xmm5
unpcklpd %xmm1,%xmm5
divpd  %xmm5,%xmm4
movapd %xmm4,%xmm5
unpckhpd %xmm4,%xmm5
ucomisd %xmm4,%xmm5
jbe    1134 <fix_ratio+0x34>
mulsd  %xmm1,%xmm2
divsd  %xmm0,%xmm2
jmp    1143 <fix_ratio+0x43>
mulsd  %xmm0,%xmm3
divsd  %xmm1,%xmm3
movapd %xmm3,%xmm2
mov    %rdi,%rsi
xorpd  %xmm0,%xmm0
cmpneqsd %xmm2,%xmm0
andpd  %xmm0,%xmm2
movsd  0xea8(%rip),%xmm1
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
movlpd %xmm0,(%rsi)
ret

LLVM IR (-O0):
define void @fix_ratio(double %0, double %1, double* %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
store double %0, double* %5
store double %1, double* %6
store double* %2, double** %7
store double* %3, double** %8
%11 = load double*, double** %7
%12 = load double, double* %11
%13 = load double, double* %5
%14 = fdiv double %12, %13
store double %14, double* %9
%15 = load double*, double** %8
%16 = load double, double* %15
%17 = load double, double* %6
%18 = fdiv double %16, %17
store double %18, double* %10
%19 = load double, double* %9
%20 = load double, double* %10
%21 = fcmp olt double %19, %20
br i1 %21, label %22, label %40
22: ; preds = %4
%23 = load double, double* %6
%24 = load double*, double** %7
%25 = load double, double* %24
%26 = fmul double %23, %25
%27 = load double, double* %5
%28 = fdiv double %26, %27
%29 = load double*, double** %8
store double %28, double* %29
%30 = load double*, double** %8
%31 = load double, double* %30
%32 = fcmp une double %31, 0.000000e+00
br i1 %32, label %33, label %36
33: ; preds = %22
%34 = load double*, double** %8
%35 = load double, double* %34
br label %37
36: ; preds = %22
br label %37
37: ; preds = %36, %33
%38 = phi double [ %35, %33 ], [ 1.000000e+00, %36 ]
%39 = load double*, double** %8
store double %38, double* %39
br label %58
40: ; preds = %4
%41 = load double, double* %5
%42 = load double*, double** %8
%43 = load double, double* %42
%44 = fmul double %41, %43
%45 = load double, double* %6
%46 = fdiv double %44, %45
%47 = load double*, double** %7
store double %46, double* %47
%48 = load double*, double** %7
%49 = load double, double* %48
%50 = fcmp une double %49, 0.000000e+00
br i1 %50, label %51, label %54
51: ; preds = %40
%52 = load double*, double** %7
%53 = load double, double* %52
br label %55
54: ; preds = %40
br label %55
55: ; preds = %54, %51
%56 = phi double [ %53, %51 ], [ 1.000000e+00, %54 ]
%57 = load double*, double** %7
store double %56, double* %57
br label %58
58: ; preds = %55, %37
ret void
}

LLVM IR (-O2):
define void @fix_ratio(double %0, double %1, double* nocapture %2, double* nocapture %3) {
%5 = load double, double* %2
%6 = load double, double* %3
%7 = insertelement <2 x double> poison, double %5, i64 0
%8 = insertelement <2 x double> %7, double %6, i64 1
%9 = insertelement <2 x double> poison, double %0, i64 0
%10 = insertelement <2 x double> %9, double %1, i64 1
%11 = fdiv <2 x double> %8, %10
%12 = extractelement <2 x double> %11, i64 0
%13 = extractelement <2 x double> %11, i64 1
%14 = fcmp olt double %12, %13
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = fmul double %5, %1
%17 = fdiv double %16, %0
br label %21
18: ; preds = %4
%19 = fmul double %6, %0
%20 = fdiv double %19, %1
br label %21
21: ; preds = %18, %15
%22 = phi double [ %20, %18 ], [ %17, %15 ]
%23 = phi double* [ %2, %18 ], [ %3, %15 ]
%24 = fcmp une double %22, 0.000000e+00
%25 = select i1 %24, double %22, double 1.000000e+00
store double %25, double* %23
ret void
}