#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 *, float *);
int main(void) {
  float loan_amount, interest_rate, payment, monthly_interest_rate, payment_amt;
  int i;
  printf("Enter amount of loan: ");
  scanf("%f", &loan_amount);
  printf("Enter interest rate: ");
  scanf("%f", &interest_rate);
  printf("Enter monthly payment: ");
  scanf("%f", &payment);
  printf("How many payments: ");
  scanf("%f", &payment_amt);
  monthly_interest_rate = (interest_rate / 100) / 12;
  for (i = 1; i <= payment_amt; i++) {
    loan_amount =
        (loan_amount - payment) + (loan_amount * monthly_interest_rate);
    printf("Balance remaining after payment #%d: $%.2f\n", i, loan_amount);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe81(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0xc(%rbp),%xmm0
movss  0xe50(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe40(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
cvtsi2ssl -0x1c(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     122c <main+0x10c>
movss  -0x8(%rbp),%xmm1
subss  -0x10(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x1c(%rbp),%esi
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d0 <main+0xb0>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xede(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee7(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xed6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
movss  0x4(%rsp),%xmm0
ucomiss 0xe61(%rip),%xmm0
jb     1224 <main+0x104>
movss  0x14(%rsp),%xmm0
divss  0xe49(%rip),%xmm0
divss  0xe45(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    $0x1,%ebx
lea    0xe97(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  0x8(%rsp),%xmm0
movaps %xmm0,%xmm1
subss  0x10(%rsp),%xmm1
mulss  0xc(%rsp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,0x8(%rsp)
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x1,%ebx
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jae    11e0 <main+0xc0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"Enter amount of loan: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [22 x i8] c"Enter interest rate: \00"
@.str.3 = [24 x i8] c"Enter monthly payment: \00"
@.str.4 = [20 x i8] c"How many payments: \00"
@.str.5 = [44 x i8] c"Balance remaining after payment #%d: $%.2f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = bitcast float* %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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
%17 = load float, float* %2
%18 = fdiv float %17, 1.000000e+02
%19 = fdiv float %18, 1.200000e+01
%20 = load float, float* %4
%21 = fcmp ult float %20, 1.000000e+00
br i1 %21, label %34, label %22
22: ; preds = %0, %22
%23 = phi i32 [ %30, %22 ], [ 1, %0 ]
%24 = load float, float* %1
%25 = load float, float* %3
%26 = fsub float %24, %25
%27 = call float @llvm.fmuladd.f32(float %24, float %19, float %26)
store float %27, float* %1
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %23, double %28)
%30 = add nuw nsw i32 %23, 1
%31 = sitofp i32 %30 to float
%32 = load float, float* %4
%33 = fcmp ult float %32, %31
br i1 %33, label %34, label %22
34: ; preds = %22, %0
ret i32 0
}