#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ diagnostics(int, char *, double, double, ...);
scalar_t__ my_rint(double);
void AdjustScaling(double h, double w, double target_h, double target_w,
                   double s, uint16_t *sx, uint16_t *sy) {
  diagnostics(5, "AdjustScaling h       =%f w       =%f s=%f", h, w, s);
  diagnostics(5, "AdjustScaling target_h=%f target_w=%f", target_h, target_w);
  if (target_h != 0 && h != 0)
    *sy = (uint16_t)my_rint(100.0 * target_h / h);
  else
    *sy = (uint16_t)my_rint(s * 100);
  if (target_w == 0 || w == 0)
    *sx = *sy;
  else
    *sx = (uint16_t)my_rint(100.0 * target_w / w);
  if (target_h == 0 && target_w != 0)
    *sy = *sx;
  diagnostics(5, "AdjustScaling xscale=%d yscale=%d", *sx, *sy);
}


x86 assembly (clang, -O0):
<AdjustScaling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
mov    %rdi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mov    $0x5,%edi
lea    0xea4(%rip),%rsi
mov    $0x3,%al
call   1030 <diagnostics@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    $0x5,%edi
lea    0xeb2(%rip),%rsi
mov    $0x2,%al
call   1030 <diagnostics@plt>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a5 <AdjustScaling+0x85>
jp     11a5 <AdjustScaling+0x85>
jmp    11eb <AdjustScaling+0xcb>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c2 <AdjustScaling+0xa2>
jp     11c2 <AdjustScaling+0xa2>
jmp    11eb <AdjustScaling+0xcb>
movsd  0xe36(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1040 <my_rint@plt>
cvtsi2sd %rax,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    120a <AdjustScaling+0xea>
movsd  0xe0d(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1040 <my_rint@plt>
cvtsi2sd %rax,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1227 <AdjustScaling+0x107>
jp     1227 <AdjustScaling+0x107>
jmp    123f <AdjustScaling+0x11f>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1254 <AdjustScaling+0x134>
jp     1254 <AdjustScaling+0x134>
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1278 <AdjustScaling+0x158>
movsd  0xda4(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <my_rint@plt>
cvtsi2sd %rax,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12bd <AdjustScaling+0x19d>
jp     12bd <AdjustScaling+0x19d>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12ad <AdjustScaling+0x18d>
jp     12ad <AdjustScaling+0x18d>
jmp    12bd <AdjustScaling+0x19d>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm1
mov    $0x5,%edi
lea    0xd80(%rip),%rsi
mov    $0x2,%al
call   1030 <diagnostics@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AdjustScaling>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  %xmm3,(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
lea    0xec3(%rip),%rsi
mov    $0x5,%edi
movsd  %xmm1,0x20(%rsp)
movsd  %xmm4,0x10(%rsp)
movaps %xmm4,%xmm2
mov    $0x3,%al
call   1030 <diagnostics@plt>
lea    0xecc(%rip),%rsi
mov    $0x5,%edi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
mov    $0x2,%al
call   1030 <diagnostics@plt>
movsd  0x18(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1196 <AdjustScaling+0x76>
jnp    11b0 <AdjustScaling+0x90>
ucomisd %xmm0,%xmm1
jne    119e <AdjustScaling+0x7e>
jnp    11b0 <AdjustScaling+0x90>
movsd  0xe5a(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
jmp    11be <AdjustScaling+0x9e>
movsd  0x10(%rsp),%xmm0
mulsd  0xe42(%rip),%xmm0
call   1040 <my_rint@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rbx)
xorpd  %xmm3,%xmm3
movsd  0x20(%rsp),%xmm2
ucomisd %xmm3,%xmm2
jne    11e1 <AdjustScaling+0xc1>
jnp    1210 <AdjustScaling+0xf0>
movsd  (%rsp),%xmm1
ucomisd %xmm3,%xmm1
jne    11ee <AdjustScaling+0xce>
jnp    1210 <AdjustScaling+0xf0>
movsd  0xe0a(%rip),%xmm0
mulsd  (%rsp),%xmm0
divsd  %xmm2,%xmm0
call   1040 <my_rint@plt>
xorpd  %xmm3,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%r14)
movsd  0x8(%rsp),%xmm1
ucomisd %xmm3,%xmm1
jne    1243 <AdjustScaling+0x123>
jp     1243 <AdjustScaling+0x123>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm2
ucomisd %xmm1,%xmm2
jne    1234 <AdjustScaling+0x114>
jnp    1243 <AdjustScaling+0x123>
movsd  %xmm0,(%rbx)
movapd %xmm0,%xmm1
movsd  (%r14),%xmm0
jmp    1247 <AdjustScaling+0x127>
movsd  (%rbx),%xmm1
lea    0xe0b(%rip),%rsi
mov    $0x5,%edi
mov    $0x2,%al
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1030 <diagnostics@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"AdjustScaling h =%f w =%f s=%f\00"
@.str.1 = [38 x i8] c"AdjustScaling target_h=%f target_w=%f\00"
@.str.2 = [34 x i8] c"AdjustScaling xscale=%d yscale=%d\00"
define void @AdjustScaling(double %0, double %1, double %2, double %3, double %4, double* %5, double* %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double*
%14 = alloca double*
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double* %5, double** %13
store double* %6, double** %14
%15 = load double, double* %8
%16 = load double, double* %9
%17 = load double, double* %12
%18 = call i32 (i32, i8*, double, double, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %15, double %16, double %17)
%19 = load double, double* %10
%20 = load double, double* %11
%21 = call i32 (i32, i8*, double, double, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), double %19, double %20)
%22 = load double, double* %10
%23 = fcmp une double %22, 0.000000e+00
br i1 %23, label %24, label %35
24: ; preds = %7
%25 = load double, double* %8
%26 = fcmp une double %25, 0.000000e+00
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load double, double* %10
%29 = fmul double 1.000000e+02, %28
%30 = load double, double* %8
%31 = fdiv double %29, %30
%32 = call i64 @my_rint(double %31)
%33 = sitofp i64 %32 to double
%34 = load double*, double** %14
store double %33, double* %34
br label %41
35: ; preds = %24, %7
%36 = load double, double* %12
%37 = fmul double %36, 1.000000e+02
%38 = call i64 @my_rint(double %37)
%39 = sitofp i64 %38 to double
%40 = load double*, double** %14
store double %39, double* %40
br label %41
41: ; preds = %35, %27
%42 = load double, double* %11
%43 = fcmp oeq double %42, 0.000000e+00
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load double, double* %9
%46 = fcmp oeq double %45, 0.000000e+00
br i1 %46, label %47, label %51
47: ; preds = %44, %41
%48 = load double*, double** %14
%49 = load double, double* %48
%50 = load double*, double** %13
store double %49, double* %50
br label %59
51: ; preds = %44
%52 = load double, double* %11
%53 = fmul double 1.000000e+02, %52
%54 = load double, double* %9
%55 = fdiv double %53, %54
%56 = call i64 @my_rint(double %55)
%57 = sitofp i64 %56 to double
%58 = load double*, double** %13
store double %57, double* %58
br label %59
59: ; preds = %51, %47
%60 = load double, double* %10
%61 = fcmp oeq double %60, 0.000000e+00
br i1 %61, label %62, label %69
62: ; preds = %59
%63 = load double, double* %11
%64 = fcmp une double %63, 0.000000e+00
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load double*, double** %13
%67 = load double, double* %66
%68 = load double*, double** %14
store double %67, double* %68
br label %69
69: ; preds = %65, %62, %59
%70 = load double*, double** %13
%71 = load double, double* %70
%72 = load double*, double** %14
%73 = load double, double* %72
%74 = call i32 (i32, i8*, double, double, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), double %71, double %73)
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"AdjustScaling h =%f w =%f s=%f\00"
@.str.1 = [38 x i8] c"AdjustScaling target_h=%f target_w=%f\00"
@.str.2 = [34 x i8] c"AdjustScaling xscale=%d yscale=%d\00"
define void @AdjustScaling(double %0, double %1, double %2, double %3, double %4, double* nocapture %5, double* nocapture %6) {
%8 = tail call i32 (i32, i8*, double, double, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %0, double %1, double %4)
%9 = tail call i32 (i32, i8*, double, double, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), double %2, double %3)
%10 = fcmp une double %2, 0.000000e+00
%11 = fcmp une double %0, 0.000000e+00
%12 = and i1 %11, %10
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = fmul double %2, 1.000000e+02
%15 = fdiv double %14, %0
br label %18
16: ; preds = %7
%17 = fmul double %4, 1.000000e+02
br label %18
18: ; preds = %16, %13
%19 = phi double [ %17, %16 ], [ %15, %13 ]
%20 = tail call i64 @my_rint(double %19)
%21 = sitofp i64 %20 to double
store double %21, double* %6
%22 = fcmp oeq double %3, 0.000000e+00
%23 = fcmp oeq double %1, 0.000000e+00
%24 = or i1 %23, %22
br i1 %24, label %30, label %25
25: ; preds = %18
%26 = fmul double %3, 1.000000e+02
%27 = fdiv double %26, %1
%28 = tail call i64 @my_rint(double %27)
%29 = sitofp i64 %28 to double
br label %30
30: ; preds = %18, %25
%31 = phi double [ %29, %25 ], [ %21, %18 ]
store double %31, double* %5
%32 = fcmp oeq double %2, 0.000000e+00
%33 = fcmp une double %3, 0.000000e+00
%34 = and i1 %32, %33
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = load double, double* %6
br label %39
37: ; preds = %30
store double %31, double* %6
%38 = load double, double* %5
br label %39
39: ; preds = %35, %37
%40 = phi double [ %31, %37 ], [ %36, %35 ]
%41 = phi double [ %38, %37 ], [ %31, %35 ]
%42 = tail call i32 (i32, i8*, double, double, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), double %41, double %40)
ret void
}