; LLVM IR from jdeokkim/ferox :: src (world)

; 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.frContextNode_ = type { i32, ptr }
%struct.frWorld_ = type { %struct.anon, %struct.anon.0, ptr, ptr, float, float, %struct.frCollisionHandler_, %struct.frVector2_ }
%struct.anon = type { ptr, i64, i64 }
%struct.anon.0 = type { ptr, i64, i32, i32 }
%struct.frCollisionHandler_ = type { ptr, ptr }
%struct.frVector2_ = type { float, float }

; 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) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @frRemoveBodyFromWorld(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.frContextNode_, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %12, label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %9, %2
  store i1 false, ptr %3, align 1
  br label %66

13:                                               ; preds = %9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.frWorld_, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds %struct.anon.0, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = add nsw i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.frWorld_, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.anon.0, ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !18
  %24 = sub i64 %23, 1
  %25 = and i64 %19, %24
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.frWorld_, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.anon.0, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !19
  %30 = sext i32 %29 to i64
  %31 = icmp ne i64 %25, %30
  br i1 %31, label %32, label %62

32:                                               ; preds = %13
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.frWorld_, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.anon.0, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.frWorld_, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.anon.0, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.frContextNode_, ptr %36, i64 %41
  %43 = getelementptr inbounds %struct.frContextNode_, ptr %6, i32 0, i32 0
  store i32 2, ptr %43, align 8, !tbaa !21
  %44 = getelementptr inbounds %struct.frContextNode_, ptr %6, i32 0, i32 1
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %45, ptr %44, align 8, !tbaa !23
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %42, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !24
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.frWorld_, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.anon.0, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.frWorld_, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct.anon.0, ptr %53, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !18
  %56 = sub i64 %55, 1
  %57 = and i64 %51, %56
  %58 = trunc i64 %57 to i32
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.frWorld_, ptr %59, i32 0, i32 1
  %61 = getelementptr inbounds %struct.anon.0, ptr %60, i32 0, i32 2
  store i32 %58, ptr %61, align 8, !tbaa !9
  br label %63

62:                                               ; preds = %13
  br label %63

63:                                               ; preds = %62, %32
  %64 = phi i32 [ 1, %32 ], [ 0, %62 ]
  %65 = icmp ne i32 %64, 0
  store i1 %65, ptr %3, align 1
  br label %66

66:                                               ; preds = %63, %12
  %67 = load i1, ptr %3, align 1
  ret i1 %67
}

attributes #0 = { nocallback nofree 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" }

!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, !14, i64 40}
!10 = !{!"frWorld_", !11, i64 0, !13, i64 24, !6, i64 48, !6, i64 56, !15, i64 64, !15, i64 68, !16, i64 72, !17, i64 88}
!11 = !{!"", !6, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"", !6, i64 0, !12, i64 8, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"frCollisionHandler_", !6, i64 0, !6, i64 8}
!17 = !{!"frVector2_", !15, i64 0, !15, i64 4}
!18 = !{!10, !12, i64 32}
!19 = !{!10, !14, i64 44}
!20 = !{!10, !6, i64 24}
!21 = !{!22, !14, i64 0}
!22 = !{!"frContextNode_", !14, i64 0, !6, i64 8}
!23 = !{!22, !6, i64 8}
!24 = !{i64 0, i64 4, !25, i64 8, i64 8, !5}
!25 = !{!14, !14, 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"

%struct.frContextNode_ = type { i32, ptr }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @frRemoveBodyFromWorld(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %27, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = add nsw i32 %7, 1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i64, ptr %10, align 8, !tbaa !17
  %12 = add i64 %11, -1
  %13 = and i64 %12, %9
  %14 = getelementptr inbounds i8, ptr %0, i64 44
  %15 = load i32, ptr %14, align 4, !tbaa !18
  %16 = sext i32 %15 to i64
  %.not.not = icmp eq i64 %13, %16
  br i1 %.not.not, label %27, label %17

17:                                               ; preds = %5
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  %20 = sext i32 %7 to i64
  %21 = getelementptr inbounds %struct.frContextNode_, ptr %19, i64 %20
  store i32 2, ptr %21, align 8, !tbaa !20
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %21, i64 8
  store ptr %1, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !21
  %22 = load i32, ptr %6, align 8, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = trunc i64 %11 to i32
  %25 = add i32 %24, -1
  %26 = and i32 %23, %25
  store i32 %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %17, %5, %2
  %.0 = phi i1 [ false, %2 ], [ false, %5 ], [ true, %17 ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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, !13, i64 40}
!6 = !{!"frWorld_", !7, i64 0, !12, i64 24, !8, i64 48, !8, i64 56, !14, i64 64, !14, i64 68, !15, i64 72, !16, i64 88}
!7 = !{!"", !8, i64 0, !11, i64 8, !11, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"", !8, i64 0, !11, i64 8, !13, i64 16, !13, i64 20}
!13 = !{!"int", !9, i64 0}
!14 = !{!"float", !9, i64 0}
!15 = !{!"frCollisionHandler_", !8, i64 0, !8, i64 8}
!16 = !{!"frVector2_", !14, i64 0, !14, i64 4}
!17 = !{!6, !11, i64 32}
!18 = !{!6, !13, i64 44}
!19 = !{!6, !8, i64 24}
!20 = !{!13, !13, i64 0}
!21 = !{!8, !8, i64 0}


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