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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @inside_fin(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.Inside, ptr %4, i32 0, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = call i32 @bbox_fin(ptr noundef %6)
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %8

8:                                                ; preds = %29, %1
  %9 = load i32, ptr %3, align 4, !tbaa !14
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Inside, ptr %10, i32 0, i32 4
  %12 = getelementptr inbounds %struct.anon, ptr %11, i32 0, i32 5
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Inside, ptr %14, i32 0, i32 4
  %16 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 6
  %17 = load i32, ptr %16, align 4, !tbaa !16
  %18 = mul nsw i32 %13, %17
  %19 = icmp slt i32 %9, %18
  br i1 %19, label %20, label %32

20:                                               ; preds = %8
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Inside, ptr %21, i32 0, i32 4
  %23 = getelementptr inbounds %struct.anon, ptr %22, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = load i32, ptr %3, align 4, !tbaa !14
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  call void @memory_free(ptr noundef %28)
  br label %29

29:                                               ; preds = %20
  %30 = load i32, ptr %3, align 4, !tbaa !14
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %3, align 4, !tbaa !14
  br label %8, !llvm.loop !18

32:                                               ; preds = %8
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Inside, ptr %33, i32 0, i32 4
  %35 = getelementptr inbounds %struct.anon, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  call void @memory_free(ptr noundef %36)
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Inside, ptr %37, i32 0, i32 4
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  call void @memory_free(ptr noundef %40)
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Inside, ptr %41, i32 0, i32 4
  %43 = getelementptr inbounds %struct.anon, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  call void @memory_free(ptr noundef %44)
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  call void @memory_free(ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 0
}

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, !6, i64 8}
!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 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 80}
!16 = !{!10, !11, i64 84}
!17 = !{!10, !6, i64 72}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !6, i64 56}
!21 = !{!10, !6, i64 64}


; 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 void @memory_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @bbox_fin(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @inside_fin(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 @bbox_fin(ptr noundef %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  %6 = getelementptr inbounds i8, ptr %0, i64 84
  %7 = load i32, ptr %5, align 8, !tbaa !13
  %8 = load i32, ptr %6, align 4, !tbaa !14
  %9 = mul nsw i32 %8, %7
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 72
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %13 = load ptr, ptr %11, align 8, !tbaa !15
  %14 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  tail call void @memory_free(ptr noundef %15)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr %5, align 8, !tbaa !13
  %17 = load i32, ptr %6, align 4, !tbaa !14
  %18 = mul nsw i32 %17, %16
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %12, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %12, %1
  %21 = getelementptr inbounds i8, ptr %0, i64 56
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  tail call void @memory_free(ptr noundef %22)
  %23 = getelementptr inbounds i8, ptr %0, i64 72
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  tail call void @memory_free(ptr noundef %24)
  %25 = getelementptr inbounds i8, ptr %0, i64 64
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  tail call void @memory_free(ptr noundef %26)
  tail call void @memory_free(ptr noundef nonnull %0)
  ret i32 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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass