#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 */

/* Variables and functions */
double INT_MAX;
double round(double);
int oil_fix_ratio(int src_width, int src_height, int *out_width,
                  int *out_height) {
  double width_ratio, height_ratio, tmp;
  int *adjust_dim;
  if (src_width < 1 || src_height < 1 || *out_width < 1 || *out_height < 1) {
    return -1;
  }
  width_ratio = *out_width / (double)src_width;
  height_ratio = *out_height / (double)src_height;
  if (width_ratio < height_ratio) {
    tmp = round(width_ratio * src_height);
    adjust_dim = out_height;
  } else {
    tmp = round(height_ratio * src_width);
    adjust_dim = out_width;
  }
  if (tmp > INT_MAX) {
    return -2;
  }
  *adjust_dim = tmp ? tmp : 1;
  return 0;
}


x86 assembly (clang, -O0):
<oil_fix_ratio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1154 <oil_fix_ratio+0x44>
cmpl   $0x1,-0xc(%rbp)
jl     1154 <oil_fix_ratio+0x44>
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jl     1154 <oil_fix_ratio+0x44>
mov    -0x20(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1160 <oil_fix_ratio+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <oil_fix_ratio+0x14b>
mov    -0x18(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c5 <oil_fix_ratio+0xb5>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <round@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11e5 <oil_fix_ratio+0xd5>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <round@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    0x2df7(%rip),%rax
ucomisd (%rax),%xmm0
jbe    1207 <oil_fix_ratio+0xf7>
movl   $0xfffffffe,-0x4(%rbp)
jmp    125b <oil_fix_ratio+0x14b>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1224 <oil_fix_ratio+0x114>
jp     1224 <oil_fix_ratio+0x114>
jmp    1233 <oil_fix_ratio+0x123>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1245 <oil_fix_ratio+0x135>
movsd  0xdc5(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1245 <oil_fix_ratio+0x135>
movsd  -0x48(%rbp),%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oil_fix_ratio>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    $0xffffffff,%eax
test   %edi,%edi
jle    11f2 <oil_fix_ratio+0xe2>
test   %esi,%esi
jle    11f2 <oil_fix_ratio+0xe2>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    (%rdx),%ecx
test   %ecx,%ecx
jle    11f2 <oil_fix_ratio+0xe2>
mov    (%r14),%edx
test   %edx,%edx
jle    11f2 <oil_fix_ratio+0xe2>
movd   %edx,%xmm0
movd   %ecx,%xmm1
punpckldq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm3
movd   %esi,%xmm0
movd   %edi,%xmm1
punpckldq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
divpd  %xmm1,%xmm3
movapd %xmm3,%xmm4
unpckhpd %xmm3,%xmm4
movapd %xmm4,%xmm2
mulsd  %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
mulsd  %xmm3,%xmm1
movapd %xmm3,0x10(%rsp)
movapd %xmm3,%xmm0
movapd %xmm4,(%rsp)
cmpltsd %xmm4,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
call   1030 <round@plt>
mov    0x2e39(%rip),%rcx
mov    $0xfffffffe,%eax
ucomisd (%rcx),%xmm0
ja     11f2 <oil_fix_ratio+0xe2>
movapd (%rsp),%xmm1
ucomisd 0x10(%rsp),%xmm1
cmova  %r14,%rbx
xorpd  %xmm1,%xmm1
cmpneqsd %xmm0,%xmm1
movapd %xmm1,%xmm2
andpd  %xmm0,%xmm2
movsd  0xe1e(%rip),%xmm0
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@INT_MAX = global double 0.000000e+00
define i32 @oil_fix_ratio(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 1
br i1 %15, label %27, label %16
16: ; preds = %4
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 1
br i1 %18, label %27, label %19
19: ; preds = %16
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = icmp slt i32 %21, 1
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32*, i32** %9
%25 = load i32, i32* %24
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %23, %19, %16, %4
store i32 -1, i32* %5
br label %73
28: ; preds = %23
%29 = load i32*, i32** %8
%30 = load i32, i32* %29
%31 = sitofp i32 %30 to double
%32 = load i32, i32* %6
%33 = sitofp i32 %32 to double
%34 = fdiv double %31, %33
store double %34, double* %10
%35 = load i32*, i32** %9
%36 = load i32, i32* %35
%37 = sitofp i32 %36 to double
%38 = load i32, i32* %7
%39 = sitofp i32 %38 to double
%40 = fdiv double %37, %39
store double %40, double* %11
%41 = load double, double* %10
%42 = load double, double* %11
%43 = fcmp olt double %41, %42
br i1 %43, label %44, label %51
44: ; preds = %28
%45 = load double, double* %10
%46 = load i32, i32* %7
%47 = sitofp i32 %46 to double
%48 = fmul double %45, %47
%49 = call double @llvm.round.f64(double %48)
store double %49, double* %12
%50 = load i32*, i32** %9
store i32* %50, i32** %13
br label %58
51: ; preds = %28
%52 = load double, double* %11
%53 = load i32, i32* %6
%54 = sitofp i32 %53 to double
%55 = fmul double %52, %54
%56 = call double @llvm.round.f64(double %55)
store double %56, double* %12
%57 = load i32*, i32** %8
store i32* %57, i32** %13
br label %58
58: ; preds = %51, %44
%59 = load double, double* %12
%60 = load double, double* @INT_MAX
%61 = fcmp ogt double %59, %60
br i1 %61, label %62, label %63
62: ; preds = %58
store i32 -2, i32* %5
br label %73
63: ; preds = %58
%64 = load double, double* %12
%65 = fcmp une double %64, 0.000000e+00
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = load double, double* %12
br label %69
68: ; preds = %63
br label %69
69: ; preds = %68, %66
%70 = phi double [ %67, %66 ], [ 1.000000e+00, %68 ]
%71 = fptosi double %70 to i32
%72 = load i32*, i32** %13
store i32 %71, i32* %72
store i32 0, i32* %5
br label %73
73: ; preds = %69, %62, %27
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@INT_MAX = global double 0.000000e+00
define i32 @oil_fix_ratio(i32 %0, i32 %1, i32* nocapture %2, i32* nocapture %3) {
%5 = icmp slt i32 %0, 1
%6 = icmp slt i32 %1, 1
%7 = or i1 %5, %6
br i1 %7, label %39, label %8
8: ; preds = %4
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 1
br i1 %10, label %39, label %11
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1
br i1 %13, label %39, label %14
14: ; preds = %11
%15 = insertelement <2 x i32> poison, i32 %9, i64 0
%16 = insertelement <2 x i32> %15, i32 %12, i64 1
%17 = sitofp <2 x i32> %16 to <2 x double>
%18 = insertelement <2 x i32> poison, i32 %0, i64 0
%19 = insertelement <2 x i32> %18, i32 %1, i64 1
%20 = sitofp <2 x i32> %19 to <2 x double>
%21 = fdiv <2 x double> %17, %20
%22 = extractelement <2 x double> %21, i64 0
%23 = extractelement <2 x double> %21, i64 1
%24 = fcmp olt double %22, %23
%25 = extractelement <2 x double> %20, i64 0
%26 = fmul double %23, %25
%27 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%28 = fmul <2 x double> %21, %27
%29 = extractelement <2 x double> %28, i64 0
%30 = select i1 %24, double %29, double %26
%31 = tail call double @llvm.round.f64(double %30)
%32 = load double, double* @INT_MAX
%33 = fcmp ogt double %31, %32
br i1 %33, label %39, label %34
34: ; preds = %14
%35 = select i1 %24, i32* %3, i32* %2
%36 = fcmp une double %31, 0.000000e+00
%37 = select i1 %36, double %31, double 1.000000e+00
%38 = fptosi double %37 to i32
store i32 %38, i32* %35
br label %39
39: ; preds = %14, %4, %8, %11, %34
%40 = phi i32 [ 0, %34 ], [ -1, %11 ], [ -1, %8 ], [ -1, %4 ], [ -2, %14 ]
ret i32 %40
}