; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-15/E - The Emperor's plan - tjz.ll (Z4calciiii)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@fact = external dso_local global [210 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z4calciiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = fsub double %13, %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sub nsw i32 %19, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fsub double %18, %24
  %26 = load double, ptr %9, align 8, !tbaa !9
  %27 = fadd double %26, %25
  store double %27, ptr %9, align 8, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = fsub double %31, %35
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = sub nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = fsub double %36, %42
  %44 = load double, ptr %9, align 8, !tbaa !9
  %45 = fadd double %44, %43
  store double %45, ptr %9, align 8, !tbaa !9
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = add nsw i32 %52, %53
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !9
  %58 = fsub double %51, %57
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sub nsw i32 %61, %62
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = sub nsw i32 %63, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !9
  %69 = fsub double %58, %68
  %70 = load double, ptr %9, align 8, !tbaa !9
  %71 = fsub double %70, %69
  store double %71, ptr %9, align 8, !tbaa !9
  %72 = load double, ptr %9, align 8, !tbaa !9
  %73 = call double @exp(double noundef %72) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret double %73
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare double @exp(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@fact = external dso_local local_unnamed_addr global [210 x double], align 16

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: write) uwtable
define dso_local noundef double @_Z4calciiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %5
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fsub double %7, %10
  %12 = sub nsw i32 %0, %1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %13
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fsub double %11, %15
  %17 = fadd double %16, 0.000000e+00
  %18 = sext i32 %2 to i64
  %19 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = sext i32 %3 to i64
  %22 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = fsub double %20, %23
  %25 = sub nsw i32 %2, %3
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fsub double %24, %28
  %30 = fadd double %17, %29
  %31 = add nsw i32 %2, %0
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = add nsw i32 %3, %1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = fsub double %34, %38
  %40 = sub i32 %31, %35
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [210 x double], ptr @fact, i64 0, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = fsub double %43, %39
  %45 = fadd double %30, %44
  %46 = tail call double @exp(double noundef %45) #2
  ret double %46
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @exp(double noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: write) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass