#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 */
scalar_t__ malloc(int);
scalar_t__ round(double);
int *nbMonths(int startPriceOld, int startPriceNew, int savingperMonth,
              double percentLossByMonth) {
  int *results = (int *)malloc(sizeof(int) * 2);
  double priceOld = startPriceOld;
  double priceNew = startPriceNew;
  int month = 0;
  double money = priceOld - priceNew;
  double loss = percentLossByMonth / 100.0;
  while (money < 0) {
    if ((++month % 2) == 0) {
      loss += 0.005;
    }
    priceOld *= 1 - loss;
    priceNew *= 1 - loss;
    money = priceOld - priceNew + savingperMonth * month;
  }
  results[0] = month;
  results[1] = (int)round(money);
  return results;
}


x86 assembly (clang, -O0):
<nbMonths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe85(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    120f <nbMonths+0xef>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11be <nbMonths+0x9e>
movsd  0xe54(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe4a(%rip),%xmm0
subsd  -0x48(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe33(%rip),%xmm0
subsd  -0x48(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0xc(%rbp),%eax
imul   -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1184 <nbMonths+0x64>
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movsd  -0x40(%rbp),%xmm0
call   1040 <round@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nbMonths>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%ebx
mov    $0x8,%edi
call   1030 <malloc@plt>
movsd  (%rsp),%xmm7
cvtsi2sd %ebx,%xmm1
mov    %rax,%r14
cvtsi2sd %r15d,%xmm2
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
xor    %eax,%eax
xorpd  %xmm3,%xmm3
ucomisd %xmm0,%xmm3
jbe    11d0 <nbMonths+0xb0>
divsd  0xe96(%rip),%xmm7
xor    %eax,%eax
movsd  0xe94(%rip),%xmm4
movsd  0xe94(%rip),%xmm5
mov    %ebp,%ecx
movapd %xmm7,%xmm6
jmp    11bf <nbMonths+0x9f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd %xmm5,%xmm0
subsd  %xmm6,%xmm0
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm2
movapd %xmm1,%xmm7
subsd  %xmm2,%xmm7
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
addsd  %xmm7,%xmm0
add    %ebp,%ecx
ucomisd %xmm0,%xmm3
movapd %xmm6,%xmm7
jbe    11d0 <nbMonths+0xb0>
add    $0x1,%eax
addsd  %xmm4,%xmm6
test   $0x1,%al
je     1190 <nbMonths+0x70>
movapd %xmm7,%xmm6
jmp    1190 <nbMonths+0x70>
mov    %eax,(%r14)
call   1040 <round@plt>
mov    %eax,0x4(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @nbMonths(i32 %0, i32 %1, i32 %2, double %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32*
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double %3, double* %8
%15 = call i64 @malloc(i32 8)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %9
%17 = load i32, i32* %5
%18 = sitofp i32 %17 to double
store double %18, double* %10
%19 = load i32, i32* %6
%20 = sitofp i32 %19 to double
store double %20, double* %11
store i32 0, i32* %12
%21 = load double, double* %10
%22 = load double, double* %11
%23 = fsub double %21, %22
store double %23, double* %13
%24 = load double, double* %8
%25 = fdiv double %24, 1.000000e+02
store double %25, double* %14
br label %26
26: ; preds = %37, %4
%27 = load double, double* %13
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %54
29: ; preds = %26
%30 = load i32, i32* %12
%31 = add nsw i32 %30, 1
store i32 %31, i32* %12
%32 = srem i32 %31, 2
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load double, double* %14
%36 = fadd double %35, 5.000000e-03
store double %36, double* %14
br label %37
37: ; preds = %34, %29
%38 = load double, double* %14
%39 = fsub double 1.000000e+00, %38
%40 = load double, double* %10
%41 = fmul double %40, %39
store double %41, double* %10
%42 = load double, double* %14
%43 = fsub double 1.000000e+00, %42
%44 = load double, double* %11
%45 = fmul double %44, %43
store double %45, double* %11
%46 = load double, double* %10
%47 = load double, double* %11
%48 = fsub double %46, %47
%49 = load i32, i32* %7
%50 = load i32, i32* %12
%51 = mul nsw i32 %49, %50
%52 = sitofp i32 %51 to double
%53 = fadd double %48, %52
store double %53, double* %13
br label %26
54: ; preds = %26
%55 = load i32, i32* %12
%56 = load i32*, i32** %9
%57 = getelementptr inbounds i32, i32* %56, i64 0
store i32 %55, i32* %57
%58 = load double, double* %13
%59 = call i64 @round(double %58)
%60 = trunc i64 %59 to i32
%61 = load i32*, i32** %9
%62 = getelementptr inbounds i32, i32* %61, i64 1
store i32 %60, i32* %62
%63 = load i32*, i32** %9
ret i32* %63
}

LLVM IR (-O2):
define i32* @nbMonths(i32 %0, i32 %1, i32 %2, double %3) {
%5 = tail call i64 @malloc(i32 8)
%6 = inttoptr i64 %5 to i32*
%7 = sitofp i32 %0 to double
%8 = sitofp i32 %1 to double
%9 = fsub double %7, %8
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %31
11: ; preds = %4
%12 = fdiv double %3, 1.000000e+02
br label %13
13: ; preds = %11, %13
%14 = phi double [ %22, %13 ], [ %12, %11 ]
%15 = phi i32 [ %18, %13 ], [ 0, %11 ]
%16 = phi double [ %25, %13 ], [ %8, %11 ]
%17 = phi double [ %24, %13 ], [ %7, %11 ]
%18 = add nuw nsw i32 %15, 1
%19 = and i32 %18, 1
%20 = icmp eq i32 %19, 0
%21 = fadd double %14, 5.000000e-03
%22 = select i1 %20, double %21, double %14
%23 = fsub double 1.000000e+00, %22
%24 = fmul double %17, %23
%25 = fmul double %16, %23
%26 = fsub double %24, %25
%27 = mul nsw i32 %18, %2
%28 = sitofp i32 %27 to double
%29 = fadd double %26, %28
%30 = fcmp olt double %29, 0.000000e+00
br i1 %30, label %13, label %31
31: ; preds = %13, %4
%32 = phi i32 [ 0, %4 ], [ %18, %13 ]
%33 = phi double [ %9, %4 ], [ %29, %13 ]
store i32 %32, i32* %6
%34 = tail call i64 @round(double %33)
%35 = trunc i64 %34 to i32
%36 = getelementptr inbounds i32, i32* %6, i64 1
store i32 %35, i32* %36
ret i32* %6
}