; LLVM IR from niuyishuai/PDCABB :: LAPACK_BLAS/LIBF2C/libf2c (z_sqrt)

; 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.doublecomplex = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local void @z_sqrt(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.doublecomplex, ptr %8, i32 0, i32 1
  %10 = load double, ptr %9, align 8, !tbaa !9
  store double %10, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.doublecomplex, ptr %11, i32 0, i32 0
  %13 = load double, ptr %12, align 8, !tbaa !13
  store double %13, ptr %7, align 8, !tbaa !12
  %14 = load double, ptr %7, align 8, !tbaa !12
  %15 = load double, ptr %6, align 8, !tbaa !12
  %16 = call double @f__cabs(double noundef %14, double noundef %15)
  store double %16, ptr %5, align 8, !tbaa !12
  %17 = fcmp oeq double %16, 0.000000e+00
  br i1 %17, label %18, label %23

18:                                               ; preds = %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.doublecomplex, ptr %19, i32 0, i32 1
  store double 0.000000e+00, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.doublecomplex, ptr %21, i32 0, i32 0
  store double 0.000000e+00, ptr %22, align 8, !tbaa !13
  br label %69

23:                                               ; preds = %2
  %24 = load double, ptr %7, align 8, !tbaa !12
  %25 = fcmp ogt double %24, 0.000000e+00
  br i1 %25, label %26, label %42

26:                                               ; preds = %23
  %27 = load double, ptr %5, align 8, !tbaa !12
  %28 = load double, ptr %7, align 8, !tbaa !12
  %29 = fadd double %27, %28
  %30 = fmul double 5.000000e-01, %29
  %31 = call double @sqrt(double noundef %30) #4
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.doublecomplex, ptr %32, i32 0, i32 0
  store double %31, ptr %33, align 8, !tbaa !13
  %34 = load double, ptr %6, align 8, !tbaa !12
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.doublecomplex, ptr %35, i32 0, i32 0
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = fdiv double %34, %37
  %39 = fdiv double %38, 2.000000e+00
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.doublecomplex, ptr %40, i32 0, i32 1
  store double %39, ptr %41, align 8, !tbaa !9
  br label %68

42:                                               ; preds = %23
  %43 = load double, ptr %5, align 8, !tbaa !12
  %44 = load double, ptr %7, align 8, !tbaa !12
  %45 = fsub double %43, %44
  %46 = fmul double 5.000000e-01, %45
  %47 = call double @sqrt(double noundef %46) #4
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.doublecomplex, ptr %48, i32 0, i32 1
  store double %47, ptr %49, align 8, !tbaa !9
  %50 = load double, ptr %6, align 8, !tbaa !12
  %51 = fcmp olt double %50, 0.000000e+00
  br i1 %51, label %52, label %59

52:                                               ; preds = %42
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.doublecomplex, ptr %53, i32 0, i32 1
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fneg double %55
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.doublecomplex, ptr %57, i32 0, i32 1
  store double %56, ptr %58, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %52, %42
  %60 = load double, ptr %6, align 8, !tbaa !12
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.doublecomplex, ptr %61, i32 0, i32 1
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = fdiv double %60, %63
  %65 = fdiv double %64, 2.000000e+00
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.doublecomplex, ptr %66, i32 0, i32 0
  store double %65, ptr %67, align 8, !tbaa !13
  br label %68

68:                                               ; preds = %59, %26
  br label %69

69:                                               ; preds = %68, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

declare double @f__cabs(double noundef, double noundef) #2

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

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

attributes #0 = { 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 = { "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 "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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, 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"

; Function Attrs: nounwind uwtable
define dso_local void @z_sqrt(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = load double, ptr %1, align 8, !tbaa !10
  %6 = tail call double @f__cabs(double noundef %5, double noundef %4) #4
  %7 = fcmp oeq double %6, 0.000000e+00
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  br label %27

9:                                                ; preds = %2
  %10 = fcmp ogt double %5, 0.000000e+00
  br i1 %10, label %11, label %18

11:                                               ; preds = %9
  %12 = fadd double %5, %6
  %13 = fmul double %12, 5.000000e-01
  %14 = tail call double @sqrt(double noundef %13) #4
  store double %14, ptr %0, align 8, !tbaa !10
  %15 = fdiv double %4, %14
  %16 = fmul double %15, 5.000000e-01
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store double %16, ptr %17, align 8, !tbaa !5
  br label %27

18:                                               ; preds = %9
  %19 = fsub double %6, %5
  %20 = fmul double %19, 5.000000e-01
  %21 = tail call double @sqrt(double noundef %20) #4
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = fcmp olt double %4, 0.000000e+00
  %24 = fneg double %21
  %storemerge = select i1 %23, double %24, double %21
  store double %storemerge, ptr %22, align 8, !tbaa !5
  %25 = fdiv double %4, %storemerge
  %26 = fmul double %25, 5.000000e-01
  store double %26, ptr %0, align 8, !tbaa !10
  br label %27

27:                                               ; preds = %11, %18, %8
  ret void
}

declare double @f__cabs(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #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 = { 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 = { "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 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 #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, !7, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 8}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}


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