#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 *, ...);
double calcFinVel(int m1, int m2, double v1, double v2) {
  double fv;
  printf("\n-- After collision:");
  fv = (m1 * v1 + m2 * v2) / (m1 + m2);
  printf("\nVelocity (m/s): %.2lf", fv);
  return fv;
}


x86 assembly (clang, -O0):
<calcFinVel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xea4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcFinVel>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    %ebp,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xea9(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\0A-- After collision:\00"
@.str.1 = [23 x i8] c"\0AVelocity (m/s): %.2lf\00"
define double @calcFinVel(i32 %0, i32 %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
store double %3, double* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to double
%13 = load double, double* %7
%14 = load i32, i32* %6
%15 = sitofp i32 %14 to double
%16 = load double, double* %8
%17 = fmul double %15, %16
%18 = call double @llvm.fmuladd.f64(double %12, double %13, double %17)
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = add nsw i32 %19, %20
%22 = sitofp i32 %21 to double
%23 = fdiv double %18, %22
store double %23, double* %9
%24 = load double, double* %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %24)
%26 = load double, double* %9
ret double %26
}

LLVM IR (-O2):
@.str = [21 x i8] c"\0A-- After collision:\00"
@.str.1 = [23 x i8] c"\0AVelocity (m/s): %.2lf\00"
define double @calcFinVel(i32 %0, i32 %1, double %2, double %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = sitofp i32 %0 to double
%7 = sitofp i32 %1 to double
%8 = fmul double %7, %3
%9 = tail call double @llvm.fmuladd.f64(double %6, double %2, double %8)
%10 = add nsw i32 %1, %0
%11 = sitofp i32 %10 to double
%12 = fdiv double %9, %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %12)
ret double %12
}