#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 */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int payments;
  float balance, interest_rate, monthly_payment, monthly_interest;
  printf("Enter number of payments: ");
  scanf("%d", &payments);
  printf("Enter amount of loan: ");
  scanf("%f", &balance);
  printf("Enter interest rate: ");
  scanf("%f", &interest_rate);
  printf("Enter monthly payment: ");
  scanf("%f", &monthly_payment);
  monthly_interest = (interest_rate * 0.01) / 12;
  for (int i = 1; i < -payments; i++) {
    balance = balance - monthly_payment + (balance * monthly_interest);
    printf("Balance remaining after payment %d : %.2f\n", i, balance);
    printf("Balance: %.2f\n", balance);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe48(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe34(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
xor    %ecx,%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    1250 <main+0x130>
movss  -0xc(%rbp),%xmm1
subss  -0x14(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
movss  -0x18(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x1c(%rbp),%esi
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe52(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe66(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e0 <main+0xc0>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeed(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xedd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee6(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1c(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0xfffffffe,0x10(%rsp)
jg     1240 <main+0x120>
movss  0x1c(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe3b(%rip),%xmm0
divsd  0xe3b(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x14(%rsp)
mov    $0x1,%ebx
lea    0xe93(%rip),%r14
lea    0xeb7(%rip),%r15
nopw   0x0(%rax,%rax,1)
movss  0xc(%rsp),%xmm0
movaps %xmm0,%xmm1
subss  0x18(%rsp),%xmm1
mulss  0x14(%rsp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x1,%ebx
xor    %eax,%eax
sub    0x10(%rsp),%eax
cmp    %eax,%ebx
jl     11f0 <main+0xd0>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter number of payments: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Enter amount of loan: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [22 x i8] c"Enter interest rate: \00"
@.str.5 = [24 x i8] c"Enter monthly payment: \00"
@.str.6 = [43 x i8] c"Balance remaining after payment %d : %.2f\0A\00"
@.str.7 = [15 x i8] c"Balance: %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %4)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %5)
%16 = load float, float* %4
%17 = fpext float %16 to double
%18 = fmul double %17, 1.000000e-02
%19 = fdiv double %18, 1.200000e+01
%20 = fptrunc double %19 to float
store float %20, float* %6
store i32 1, i32* %7
br label %21
21: ; preds = %40, %0
%22 = load i32, i32* %7
%23 = load i32, i32* %2
%24 = sub nsw i32 0, %23
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %43
26: ; preds = %21
%27 = load float, float* %3
%28 = load float, float* %5
%29 = fsub float %27, %28
%30 = load float, float* %3
%31 = load float, float* %6
%32 = call float @llvm.fmuladd.f32(float %30, float %31, float %29)
store float %32, float* %3
%33 = load i32, i32* %7
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %33, double %35)
%37 = load float, float* %3
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), double %38)
br label %40
40: ; preds = %26
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %21
43: ; preds = %21
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter number of payments: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Enter amount of loan: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [22 x i8] c"Enter interest rate: \00"
@.str.5 = [24 x i8] c"Enter monthly payment: \00"
@.str.6 = [43 x i8] c"Balance remaining after payment %d : %.2f\0A\00"
@.str.7 = [15 x i8] c"Balance: %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = bitcast i32* %1 to i8*
%6 = bitcast float* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %4)
%17 = load float, float* %3
%18 = fpext float %17 to double
%19 = fmul double %18, 1.000000e-02
%20 = fdiv double %19, 1.200000e+01
%21 = fptrunc double %20 to float
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, -1
br i1 %23, label %25, label %24
24: ; preds = %25, %0
ret i32 0
25: ; preds = %0, %25
%26 = phi i32 [ %36, %25 ], [ 1, %0 ]
%27 = load float, float* %2
%28 = load float, float* %4
%29 = fsub float %27, %28
%30 = call float @llvm.fmuladd.f32(float %27, float %21, float %29)
store float %30, float* %2
%31 = fpext float %30 to double
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %26, double %31)
%33 = load float, float* %2
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), double %34)
%36 = add nuw nsw i32 %26, 1
%37 = load i32, i32* %1
%38 = sub nsw i32 0, %37
%39 = icmp slt i32 %36, %38
br i1 %39, label %25, label %24
}