; LLVM IR from cselab/aphros :: src/inside (main)

; 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.Inside = type { i32, ptr, ptr, ptr, %struct.anon }
%struct.anon = type { [2 x double], double, ptr, ptr, ptr, i32, i32 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @inside_inside(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden double @tri_point_distance2(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local double @inside_distance_naive(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Inside, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Inside, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Inside, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !15
  store i32 %27, ptr %17, align 4, !tbaa !16
  store double 0x7FEFFFFFFFFFFFFF, ptr %12, align 8, !tbaa !17
  store i32 0, ptr %16, align 4, !tbaa !16
  br label %28

28:                                               ; preds = %79, %2
  %29 = load i32, ptr %16, align 4, !tbaa !16
  %30 = load i32, ptr %17, align 4, !tbaa !16
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %82

32:                                               ; preds = %28
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load i32, ptr %16, align 4, !tbaa !16
  %35 = mul nsw i32 3, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %33, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !16
  store i32 %38, ptr %13, align 4, !tbaa !16
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i32, ptr %16, align 4, !tbaa !16
  %41 = mul nsw i32 3, %40
  %42 = add nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %39, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !16
  store i32 %45, ptr %14, align 4, !tbaa !16
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load i32, ptr %16, align 4, !tbaa !16
  %48 = mul nsw i32 3, %47
  %49 = add nsw i32 %48, 2
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %46, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !16
  store i32 %52, ptr %15, align 4, !tbaa !16
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load i32, ptr %13, align 4, !tbaa !16
  %55 = mul nsw i32 3, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %53, i64 %56
  store ptr %57, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load i32, ptr %14, align 4, !tbaa !16
  %60 = mul nsw i32 3, %59
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %58, i64 %61
  store ptr %62, ptr %7, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i32, ptr %15, align 4, !tbaa !16
  %65 = mul nsw i32 3, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %63, i64 %66
  store ptr %67, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = call double @tri_point_distance2(ptr noundef %68, ptr noundef %69, ptr noundef %70, ptr noundef %71)
  store double %72, ptr %11, align 8, !tbaa !17
  %73 = load double, ptr %11, align 8, !tbaa !17
  %74 = load double, ptr %12, align 8, !tbaa !17
  %75 = fcmp olt double %73, %74
  br i1 %75, label %76, label %78

76:                                               ; preds = %32
  %77 = load double, ptr %11, align 8, !tbaa !17
  store double %77, ptr %12, align 8, !tbaa !17
  br label %78

78:                                               ; preds = %76, %32
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %16, align 4, !tbaa !16
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %16, align 4, !tbaa !16
  br label %28, !llvm.loop !18

82:                                               ; preds = %28
  %83 = load double, ptr %12, align 8, !tbaa !17
  %84 = call double @sqrt(double noundef %83) #3
  store double %84, ptr %11, align 8, !tbaa !17
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call i32 @inside_inside(ptr noundef %85, ptr noundef %86)
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %92

89:                                               ; preds = %82
  %90 = load double, ptr %11, align 8, !tbaa !17
  %91 = fneg double %90
  store double %91, ptr %3, align 8
  store i32 1, ptr %18, align 4
  br label %94

92:                                               ; preds = %82
  %93 = load double, ptr %11, align 8, !tbaa !17
  store double %93, ptr %3, align 8
  store i32 1, ptr %18, align 4
  br label %94

94:                                               ; preds = %92, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %95 = load double, ptr %3, align 8
  ret double %95
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"Inside", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !7, i64 0, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52}
!13 = !{!"double", !7, i64 0}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !11, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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
declare dso_local i32 @inside_inside(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden double @tri_point_distance2(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local double @inside_distance_naive(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %7 = load i32, ptr %0, align 8, !tbaa !14
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.03133 = phi double [ 0x7FEFFFFFFFFFFFFF, %.lr.ph.preheader ], [ %.1, %.lr.ph ]
  %.idx = mul i64 %indvars.iv, 12
  %9 = getelementptr inbounds i8, ptr %6, i64 %.idx
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %9, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %9, i64 8
  %14 = load i32, ptr %13, align 4, !tbaa !15
  %15 = mul nsw i32 %10, 3
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds double, ptr %4, i64 %16
  %18 = mul nsw i32 %12, 3
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %4, i64 %19
  %21 = mul nsw i32 %14, 3
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr %4, i64 %22
  %24 = tail call double @tri_point_distance2(ptr noundef %17, ptr noundef %20, ptr noundef %23, ptr noundef %1)
  %25 = fcmp olt double %24, %.03133
  %.1 = select i1 %25, double %24, double %.03133
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.031.lcssa = phi double [ 0x7FEFFFFFFFFFFFFF, %2 ], [ %.1, %.lr.ph ]
  %26 = tail call double @sqrt(double noundef %.031.lcssa) #2
  %27 = tail call i32 @inside_inside(ptr noundef nonnull %0, ptr noundef %1)
  %.not = icmp eq i32 %27, 0
  %28 = fneg double %26
  %.0 = select i1 %.not, double %26, double %28
  ret double %.0
}

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 = { 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, !10, i64 24}
!6 = !{!"Inside", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"", !8, i64 0, !12, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 52}
!12 = !{!"double", !8, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass