; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-01/F.ll (Z4calcd)

; 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"

%struct.Point = type { double, double }

@A = external dso_local global %struct.Point, align 8
@B = external dso_local global %struct.Point, align 8
@C = external dso_local global %struct.Point, align 8
@D = external dso_local global %struct.Point, align 8
@h = external dso_local global i32, align 4
@m = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z4calcd(double noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca %struct.Point, align 8
  %5 = alloca double, align 8
  %6 = alloca %struct.Point, align 8
  %7 = alloca %struct.Point, align 8
  %8 = alloca %struct.Point, align 8
  %9 = alloca %struct.Point, align 8
  %10 = alloca double, align 8
  %11 = alloca %struct.Point, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  %12 = load double, ptr %2, align 8, !tbaa !5
  %13 = fdiv double %12, 2.000000e+00
  %14 = load i32, ptr @m, align 4, !tbaa !9
  %15 = load i32, ptr @m, align 4, !tbaa !9
  %16 = mul nsw i32 %14, %15
  %17 = load i32, ptr @h, align 4, !tbaa !9
  %18 = load i32, ptr @h, align 4, !tbaa !9
  %19 = mul nsw i32 %17, %18
  %20 = sub nsw i32 %16, %19
  %21 = sitofp i32 %20 to double
  %22 = call double @sqrt(double noundef %21) #5
  %23 = fadd double %13, %22
  store double %23, ptr @A, align 8, !tbaa !11
  %24 = load i32, ptr @h, align 4, !tbaa !9
  %25 = sitofp i32 %24 to double
  store double %25, ptr getelementptr inbounds (%struct.Point, ptr @A, i32 0, i32 1), align 8, !tbaa !13
  store double 0.000000e+00, ptr @B, align 8, !tbaa !11
  store double 0.000000e+00, ptr getelementptr inbounds (%struct.Point, ptr @B, i32 0, i32 1), align 8, !tbaa !13
  %26 = load double, ptr %2, align 8, !tbaa !5
  store double %26, ptr @C, align 8, !tbaa !11
  store double 0.000000e+00, ptr getelementptr inbounds (%struct.Point, ptr @C, i32 0, i32 1), align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  %27 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @C)
  %28 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 0
  %29 = extractvalue { double, double } %27, 0
  store double %29, ptr %28, align 8
  %30 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 1
  %31 = extractvalue { double, double } %27, 1
  store double %31, ptr %30, align 8
  %32 = call noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  store double %32, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  %33 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @B)
  %34 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  %35 = extractvalue { double, double } %33, 0
  store double %35, ptr %34, align 8
  %36 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  %37 = extractvalue { double, double } %33, 1
  store double %37, ptr %36, align 8
  %38 = call noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  store double %38, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %39 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @C, ptr noundef nonnull align 8 dereferenceable(16) @B)
  %40 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 0
  %41 = extractvalue { double, double } %39, 0
  store double %41, ptr %40, align 8
  %42 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 1
  %43 = extractvalue { double, double } %39, 1
  store double %43, ptr %42, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %44 = load double, ptr %5, align 8, !tbaa !5
  %45 = load double, ptr %3, align 8, !tbaa !5
  %46 = load double, ptr %5, align 8, !tbaa !5
  %47 = fadd double %45, %46
  %48 = fdiv double %44, %47
  store double %48, ptr %10, align 8, !tbaa !5
  %49 = call { double, double } @_ZNK5PointmlERKd(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %50 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %51 = extractvalue { double, double } %49, 0
  store double %51, ptr %50, align 8
  %52 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %53 = extractvalue { double, double } %49, 1
  store double %53, ptr %52, align 8
  %54 = call { double, double } @_ZNK5PointplERKS_(ptr noundef nonnull align 8 dereferenceable(16) @B, ptr noundef nonnull align 8 dereferenceable(16) %8)
  %55 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %56 = extractvalue { double, double } %54, 0
  store double %56, ptr %55, align 8
  %57 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %58 = extractvalue { double, double } %54, 1
  store double %58, ptr %57, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @D, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %59 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @D)
  %60 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %61 = extractvalue { double, double } %59, 0
  store double %61, ptr %60, align 8
  %62 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %63 = extractvalue { double, double } %59, 1
  store double %63, ptr %62, align 8
  %64 = call noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16) %11)
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret double %64
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_ZNK5PointplERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_ZNK5PointmlERKd(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { mustprogress 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS5Point", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}


; 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"

%struct.Point = type { double, double }

@A = external dso_local global %struct.Point, align 8
@B = external dso_local global %struct.Point, align 8
@C = external dso_local global %struct.Point, align 8
@D = external dso_local global %struct.Point, align 8
@h = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z4calcd(double noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.Point, align 8
  %3 = alloca %struct.Point, align 8
  %4 = alloca %struct.Point, align 8
  %5 = alloca %struct.Point, align 8
  %6 = alloca double, align 8
  %7 = alloca %struct.Point, align 8
  %8 = fmul double %0, 5.000000e-01
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %10 = load i32, ptr @h, align 4, !tbaa !5
  %add = add nsw i32 %10, %9
  %sub = sub nsw i32 %9, %10
  %11 = mul nsw i32 %add, %sub
  %12 = sitofp i32 %11 to double
  %13 = tail call double @sqrt(double noundef %12) #4
  %14 = fadd double %8, %13
  store double %14, ptr @A, align 8, !tbaa !9
  %15 = load i32, ptr @h, align 4, !tbaa !5
  %16 = sitofp i32 %15 to double
  store double %16, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8, !tbaa !12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) @B, i8 0, i64 16, i1 false)
  store double %0, ptr @C, align 8, !tbaa !9
  store double 0.000000e+00, ptr getelementptr inbounds (i8, ptr @C, i64 8), align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  %17 = tail call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @C)
  %18 = extractvalue { double, double } %17, 0
  store double %18, ptr %2, align 8
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  %20 = extractvalue { double, double } %17, 1
  store double %20, ptr %19, align 8
  %21 = call noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %22 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @B)
  %23 = extractvalue { double, double } %22, 0
  store double %23, ptr %3, align 8
  %24 = getelementptr inbounds i8, ptr %3, i64 8
  %25 = extractvalue { double, double } %22, 1
  store double %25, ptr %24, align 8
  %26 = call noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16) %3)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %27 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @C, ptr noundef nonnull align 8 dereferenceable(16) @B)
  %28 = extractvalue { double, double } %27, 0
  store double %28, ptr %5, align 8
  %29 = getelementptr inbounds i8, ptr %5, i64 8
  %30 = extractvalue { double, double } %27, 1
  store double %30, ptr %29, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %31 = fadd double %21, %26
  %32 = fdiv double %26, %31
  store double %32, ptr %6, align 8, !tbaa !13
  %33 = call { double, double } @_ZNK5PointmlERKd(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %34 = extractvalue { double, double } %33, 0
  store double %34, ptr %4, align 8
  %35 = getelementptr inbounds i8, ptr %4, i64 8
  %36 = extractvalue { double, double } %33, 1
  store double %36, ptr %35, align 8
  %37 = call { double, double } @_ZNK5PointplERKS_(ptr noundef nonnull align 8 dereferenceable(16) @B, ptr noundef nonnull align 8 dereferenceable(16) %4)
  %38 = extractvalue { double, double } %37, 0
  %39 = extractvalue { double, double } %37, 1
  store double %38, ptr @D, align 8, !tbaa !13
  store double %39, ptr getelementptr inbounds (i8, ptr @D, i64 8), align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %40 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @D)
  %41 = extractvalue { double, double } %40, 0
  store double %41, ptr %7, align 8
  %42 = getelementptr inbounds i8, ptr %7, i64 8
  %43 = extractvalue { double, double } %40, 1
  store double %43, ptr %42, align 8
  %44 = call noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret double %44
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN5Point4normEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_ZNK5PointplERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_ZNK5PointmlERKd(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !11, i64 0}
!10 = !{!"_ZTS5Point", !11, i64 0, !11, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}


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