; LLVM IR from b00dle/libpcc :: src/Encoder.ll (ZN7Encoder6mapVecERK3VecIfERK11BoundingBoxRKS0_I8BitCountE)

; 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.Vec.0 = type { ptr, i64, i64, i64 }
%struct.Vec = type <{ ptr, float, float, float, [4 x i8] }>
%struct.BoundingBox = type { %struct.Vec, %struct.Vec }
%struct.Vec.3 = type <{ ptr, i32, i32, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef, float noundef, float noundef, i8 noundef zeroext) #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3VecImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef, i64 noundef, i64 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3VecImED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Encoder6mapVecERK3VecIfERK11BoundingBoxRKS0_I8BitCountE(ptr dead_on_unwind noalias writable sret(%struct.Vec.0) align 8 %0, ptr noundef nonnull align 8 dereferenceable(20) %1, ptr noundef nonnull align 8 dereferenceable(48) %2, ptr noundef nonnull align 8 dereferenceable(20) %3) #0 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i1, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  store i1 false, ptr %9, align 1
  call void @_ZN3VecImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Vec, ptr %12, i32 0, i32 1
  %14 = load float, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.BoundingBox, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.Vec, ptr %16, i32 0, i32 1
  %18 = load float, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.BoundingBox, ptr %19, i32 0, i32 1
  %21 = getelementptr inbounds %struct.Vec, ptr %20, i32 0, i32 1
  %22 = load float, ptr %21, align 8, !tbaa !14
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Vec.3, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = trunc i32 %25 to i8
  %27 = invoke noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef %14, float noundef %18, float noundef %22, i8 noundef zeroext %26)
          to label %28 unwind label %70

28:                                               ; preds = %4
  %29 = zext i32 %27 to i64
  %30 = getelementptr inbounds %struct.Vec.0, ptr %0, i32 0, i32 1
  store i64 %29, ptr %30, align 8, !tbaa !18
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Vec, ptr %31, i32 0, i32 2
  %33 = load float, ptr %32, align 4, !tbaa !21
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.BoundingBox, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.Vec, ptr %35, i32 0, i32 2
  %37 = load float, ptr %36, align 4, !tbaa !22
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.BoundingBox, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds %struct.Vec, ptr %39, i32 0, i32 2
  %41 = load float, ptr %40, align 4, !tbaa !23
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Vec.3, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !24
  %45 = trunc i32 %44 to i8
  %46 = invoke noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef %33, float noundef %37, float noundef %41, i8 noundef zeroext %45)
          to label %47 unwind label %70

47:                                               ; preds = %28
  %48 = zext i32 %46 to i64
  %49 = getelementptr inbounds %struct.Vec.0, ptr %0, i32 0, i32 2
  store i64 %48, ptr %49, align 8, !tbaa !25
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Vec, ptr %50, i32 0, i32 3
  %52 = load float, ptr %51, align 8, !tbaa !26
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.BoundingBox, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.Vec, ptr %54, i32 0, i32 3
  %56 = load float, ptr %55, align 8, !tbaa !27
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.BoundingBox, ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds %struct.Vec, ptr %58, i32 0, i32 3
  %60 = load float, ptr %59, align 8, !tbaa !28
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Vec.3, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 8, !tbaa !29
  %64 = trunc i32 %63 to i8
  %65 = invoke noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef %52, float noundef %56, float noundef %60, i8 noundef zeroext %64)
          to label %66 unwind label %70

66:                                               ; preds = %47
  %67 = zext i32 %65 to i64
  %68 = getelementptr inbounds %struct.Vec.0, ptr %0, i32 0, i32 3
  store i64 %67, ptr %68, align 8, !tbaa !30
  store i1 true, ptr %9, align 1
  %69 = load i1, ptr %9, align 1
  br i1 %69, label %75, label %74

70:                                               ; preds = %47, %28, %4
  %71 = landingpad { ptr, i32 }
          cleanup
  %72 = extractvalue { ptr, i32 } %71, 0
  store ptr %72, ptr %10, align 8
  %73 = extractvalue { ptr, i32 } %71, 1
  store i32 %73, ptr %11, align 4
  call void @_ZN3VecImED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  br label %76

74:                                               ; preds = %66
  call void @_ZN3VecImED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  br label %75

75:                                               ; preds = %74, %66
  ret void

76:                                               ; preds = %70
  %77 = load ptr, ptr %10, align 8
  %78 = load i32, ptr %11, align 4
  %79 = insertvalue { ptr, i32 } poison, ptr %77, 0
  %80 = insertvalue { ptr, i32 } %79, i32 %78, 1
  resume { ptr, i32 } %80
}

attributes #0 = { mustprogress 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 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++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTS3VecIfE", !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"float", !7, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"_ZTS11BoundingBox", !10, i64 0, !10, i64 24}
!14 = !{!13, !11, i64 32}
!15 = !{!16, !17, i64 8}
!16 = !{!"_ZTS3VecI8BitCountE", !17, i64 8, !17, i64 12, !17, i64 16}
!17 = !{!"_ZTS8BitCount", !7, i64 0}
!18 = !{!19, !20, i64 8}
!19 = !{!"_ZTS3VecImE", !20, i64 8, !20, i64 16, !20, i64 24}
!20 = !{!"long", !7, i64 0}
!21 = !{!10, !11, i64 12}
!22 = !{!13, !11, i64 12}
!23 = !{!13, !11, i64 36}
!24 = !{!16, !17, i64 12}
!25 = !{!19, !20, i64 16}
!26 = !{!10, !11, i64 16}
!27 = !{!13, !11, i64 16}
!28 = !{!13, !11, i64 40}
!29 = !{!16, !17, i64 16}
!30 = !{!19, !20, i64 24}


; 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.Vec.0 = type { ptr, i64, i64, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef, float noundef, float noundef, i8 noundef zeroext) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3VecImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef, i64 noundef, i64 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3VecImED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Encoder6mapVecERK3VecIfERK11BoundingBoxRKS0_I8BitCountE(ptr dead_on_unwind noalias nonnull writable sret(%struct.Vec.0) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(20) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %2, ptr nocapture noundef nonnull readonly align 8 dereferenceable(20) %3) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN3VecImEC2Emmm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load float, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  %8 = load float, ptr %7, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %2, i64 32
  %10 = load float, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = trunc i32 %12 to i8
  %14 = invoke noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef %6, float noundef %8, float noundef %10, i8 noundef zeroext %13)
          to label %15 unwind label %44

15:                                               ; preds = %4
  %16 = zext i32 %14 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %16, ptr %17, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %1, i64 12
  %19 = load float, ptr %18, align 4, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %2, i64 12
  %21 = load float, ptr %20, align 4, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %2, i64 36
  %23 = load float, ptr %22, align 4, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %3, i64 12
  %25 = load i32, ptr %24, align 4, !tbaa !22
  %26 = trunc i32 %25 to i8
  %27 = invoke noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef %19, float noundef %21, float noundef %23, i8 noundef zeroext %26)
          to label %28 unwind label %44

28:                                               ; preds = %15
  %29 = zext i32 %27 to i64
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %29, ptr %30, align 8, !tbaa !23
  %31 = getelementptr inbounds i8, ptr %1, i64 16
  %32 = load float, ptr %31, align 8, !tbaa !24
  %33 = getelementptr inbounds i8, ptr %2, i64 16
  %34 = load float, ptr %33, align 8, !tbaa !25
  %35 = getelementptr inbounds i8, ptr %2, i64 40
  %36 = load float, ptr %35, align 8, !tbaa !26
  %37 = getelementptr inbounds i8, ptr %3, i64 16
  %38 = load i32, ptr %37, align 8, !tbaa !27
  %39 = trunc i32 %38 to i8
  %40 = invoke noundef i32 @_ZN7Encoder8mapToBitEfffh(float noundef %32, float noundef %34, float noundef %36, i8 noundef zeroext %39)
          to label %41 unwind label %44

41:                                               ; preds = %28
  %42 = zext i32 %40 to i64
  %43 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %42, ptr %43, align 8, !tbaa !28
  ret void

44:                                               ; preds = %28, %15, %4
  %45 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN3VecImED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  resume { ptr, i32 } %45
}

attributes #0 = { mustprogress 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 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, !7, i64 8}
!6 = !{!"_ZTS3VecIfE", !7, i64 8, !7, i64 12, !7, i64 16}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 8}
!11 = !{!"_ZTS11BoundingBox", !6, i64 0, !6, i64 24}
!12 = !{!11, !7, i64 32}
!13 = !{!14, !15, i64 8}
!14 = !{!"_ZTS3VecI8BitCountE", !15, i64 8, !15, i64 12, !15, i64 16}
!15 = !{!"_ZTS8BitCount", !8, i64 0}
!16 = !{!17, !18, i64 8}
!17 = !{!"_ZTS3VecImE", !18, i64 8, !18, i64 16, !18, i64 24}
!18 = !{!"long", !8, i64 0}
!19 = !{!6, !7, i64 12}
!20 = !{!11, !7, i64 12}
!21 = !{!11, !7, i64 36}
!22 = !{!14, !15, i64 12}
!23 = !{!17, !18, i64 16}
!24 = !{!6, !7, i64 16}
!25 = !{!11, !7, i64 16}
!26 = !{!11, !7, i64 40}
!27 = !{!14, !15, i64 16}
!28 = !{!17, !18, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass