; 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 @bbox_inside(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @bbox_zhi(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @inside_inside_naive(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca [3 x double], align 16
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca ptr, align 8
  %21 = 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 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.start.p0(i64 24, ptr %17) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #2
  store double 1.000000e-10, ptr %19, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Inside, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  store ptr %24, ptr %13, 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 %6, align 4, !tbaa !16
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Inside, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  store ptr %30, ptr %12, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Inside, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !18
  store ptr %33, ptr %20, align 8, !tbaa !5
  %34 = load ptr, ptr %20, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @bbox_inside(ptr noundef %34, ptr noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %21, align 4
  br label %101

39:                                               ; preds = %2
  %40 = load ptr, ptr %20, align 8, !tbaa !5
  %41 = call double @bbox_zhi(ptr noundef %40)
  store double %41, ptr %18, align 8, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds double, ptr %42, i64 0
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds [3 x double], ptr %17, i64 0, i64 0
  store double %44, ptr %45, align 16, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds double, ptr %46, i64 1
  %48 = load double, ptr %47, align 8, !tbaa !9
  %49 = getelementptr inbounds [3 x double], ptr %17, i64 0, i64 1
  store double %48, ptr %49, align 8, !tbaa !9
  %50 = load double, ptr %18, align 8, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds double, ptr %51, i64 2
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = call double @max_dbl(double noundef %50, double noundef %53)
  %55 = load double, ptr %19, align 8, !tbaa !9
  %56 = fadd double %54, %55
  %57 = getelementptr inbounds [3 x double], ptr %17, i64 0, i64 2
  store double %56, ptr %57, align 16, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !16
  store i32 0, ptr %7, align 4, !tbaa !16
  br label %58

58:                                               ; preds = %95, %39
  %59 = load i32, ptr %7, align 4, !tbaa !16
  %60 = load i32, ptr %6, align 4, !tbaa !16
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %62, label %98

62:                                               ; preds = %58
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = getelementptr inbounds i32, ptr %63, i32 1
  store ptr %64, ptr %12, align 8, !tbaa !5
  %65 = load i32, ptr %63, align 4, !tbaa !16
  store i32 %65, ptr %8, align 4, !tbaa !16
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = getelementptr inbounds i32, ptr %66, i32 1
  store ptr %67, ptr %12, align 8, !tbaa !5
  %68 = load i32, ptr %66, align 4, !tbaa !16
  store i32 %68, ptr %9, align 4, !tbaa !16
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = getelementptr inbounds i32, ptr %69, i32 1
  store ptr %70, ptr %12, align 8, !tbaa !5
  %71 = load i32, ptr %69, align 4, !tbaa !16
  store i32 %71, ptr %10, align 4, !tbaa !16
  %72 = load ptr, ptr %13, align 8, !tbaa !5
  %73 = load i32, ptr %8, align 4, !tbaa !16
  %74 = mul nsw i32 3, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds double, ptr %72, i64 %75
  store ptr %76, ptr %14, align 8, !tbaa !5
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !16
  %79 = mul nsw i32 3, %78
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds double, ptr %77, i64 %80
  store ptr %81, ptr %15, align 8, !tbaa !5
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = load i32, ptr %10, align 4, !tbaa !16
  %84 = mul nsw i32 3, %83
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds double, ptr %82, i64 %85
  store ptr %86, ptr %16, align 8, !tbaa !5
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds [3 x double], ptr %17, i64 0, i64 0
  %89 = load ptr, ptr %14, align 8, !tbaa !5
  %90 = load ptr, ptr %15, align 8, !tbaa !5
  %91 = load ptr, ptr %16, align 8, !tbaa !5
  %92 = call i32 @predicate_ray(ptr noundef %87, ptr noundef %88, ptr noundef %89, ptr noundef %90, ptr noundef %91)
  %93 = load i32, ptr %11, align 4, !tbaa !16
  %94 = add nsw i32 %93, %92
  store i32 %94, ptr %11, align 4, !tbaa !16
  br label %95

95:                                               ; preds = %62
  %96 = load i32, ptr %7, align 4, !tbaa !16
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %7, align 4, !tbaa !16
  br label %58, !llvm.loop !19

98:                                               ; preds = %58
  %99 = load i32, ptr %11, align 4, !tbaa !16
  %100 = srem i32 %99, 2
  store i32 %100, ptr %3, align 4
  store i32 1, ptr %21, align 4
  br label %101

101:                                              ; preds = %98, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 24, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %102 = load i32, ptr %3, align 4
  ret i32 %102
}

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

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 }

!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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"Inside", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !7, i64 0, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 52}
!15 = !{!12, !13, i64 0}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 16}
!18 = !{!12, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 @bbox_inside(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local double @bbox_zhi(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @inside_inside_naive(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #2
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load i32, ptr %0, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = tail call i32 @bbox_inside(ptr noundef %10, ptr noundef %1)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge, label %12

12:                                               ; preds = %2
  %13 = tail call double @bbox_zhi(ptr noundef %10)
  %14 = load <2 x double>, ptr %1, align 8, !tbaa !16
  store <2 x double> %14, ptr %3, align 16, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  %16 = load double, ptr %15, align 8, !tbaa !16
  %17 = tail call double @max_dbl(double noundef %13, double noundef %16)
  %18 = fadd double %17, 1.000000e-10
  %19 = getelementptr inbounds i8, ptr %3, i64 16
  store double %18, ptr %19, align 16, !tbaa !16
  %20 = icmp sgt i32 %6, 0
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.03035 = phi i32 [ %38, %.lr.ph ], [ 0, %12 ]
  %.03134 = phi i32 [ %37, %.lr.ph ], [ 0, %12 ]
  %.03233 = phi ptr [ %25, %.lr.ph ], [ %8, %12 ]
  %21 = getelementptr inbounds i8, ptr %.03233, i64 4
  %22 = load i32, ptr %.03233, align 4, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %.03233, i64 8
  %24 = load i32, ptr %21, align 4, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %.03233, i64 12
  %26 = load i32, ptr %23, align 4, !tbaa !17
  %27 = mul nsw i32 %22, 3
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %5, i64 %28
  %30 = mul nsw i32 %24, 3
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %5, i64 %31
  %33 = mul nsw i32 %26, 3
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %5, i64 %34
  %36 = call i32 @predicate_ray(ptr noundef nonnull %1, ptr noundef nonnull %3, ptr noundef %29, ptr noundef %32, ptr noundef %35)
  %37 = add nsw i32 %36, %.03134
  %38 = add nuw nsw i32 %.03035, 1
  %exitcond.not = icmp eq i32 %38, %6
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !18

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %39 = srem i32 %37, 2
  br label %._crit_edge

._crit_edge:                                      ; preds = %12, %._crit_edge.loopexit, %2
  %.0 = phi i32 [ 0, %2 ], [ 0, %12 ], [ %39, %._crit_edge.loopexit ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #2
  ret i32 %.0
}

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

attributes #0 = { mustprogress 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 }

!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, !7, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !10, i64 8}
!16 = !{!12, !12, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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