; LLVM IR from CerebusOSS/CereLink :: cbhwlib/CCFUtils.ll (ZN8CCFUtils11ReadVersionEPKc)

; 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"

%class.CCFUtils = type <{ ptr, ptr, i8, [7 x i8], ptr, i8, [7 x i8], ptr, i32, i32, i32, [4 x i8], ptr, i8, i8, [6 x i8] }>

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #0

declare void @_ZN14CCFUtilsXml_v1C1Ev(ptr noundef nonnull align 8 dereferenceable(1008256)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8CCFUtils18GetInternalVersionEv(ptr noundef nonnull align 8 dereferenceable(74)) #3 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8CCFUtils11ReadVersionEPKc(ptr noundef nonnull align 8 dereferenceable(74) %0, ptr noundef %1) unnamed_addr #5 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 12
  store ptr %9, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %27

14:                                               ; preds = %2
  %15 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 1008256) #7
  invoke void @_ZN14CCFUtilsXml_v1C1Ev(ptr noundef nonnull align 8 dereferenceable(1008256) %15)
          to label %16 unwind label %23

16:                                               ; preds = %14
  %17 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  store ptr %15, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 10
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds %class.CCFUtils, ptr %21, i32 0, i32 10
  store i32 %19, ptr %22, align 8, !tbaa !16
  br label %27

23:                                               ; preds = %14
  %24 = landingpad { ptr, i32 }
          cleanup
  %25 = extractvalue { ptr, i32 } %24, 0
  store ptr %25, ptr %6, align 8
  %26 = extractvalue { ptr, i32 } %24, 1
  store i32 %26, ptr %7, align 4
  call void @_ZdlPvm(ptr noundef %15, i64 noundef 1008256) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %65

27:                                               ; preds = %16, %2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %51

30:                                               ; preds = %27
  %31 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %32, align 8, !tbaa !17
  %35 = getelementptr inbounds ptr, ptr %34, i64 4
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef i32 %36(ptr noundef nonnull align 8 dereferenceable(74) %32, ptr noundef %33)
  store i32 %37, ptr %5, align 4, !tbaa !9
  %38 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = call noundef i32 @_ZN8CCFUtils18GetInternalVersionEv(ptr noundef nonnull align 8 dereferenceable(74) %39)
  %41 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 8
  store i32 %40, ptr %41, align 8, !tbaa !19
  %42 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = call noundef i32 @_ZN8CCFUtils26GetInternalOriginalVersionEv(ptr noundef nonnull align 8 dereferenceable(74) %43)
  %45 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 9
  store i32 %44, ptr %45, align 4, !tbaa !20
  %46 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = call noundef zeroext i1 @_ZN8CCFUtils16IsBinaryOriginalEv(ptr noundef nonnull align 8 dereferenceable(74) %47)
  %49 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 14
  %50 = zext i1 %48 to i8
  store i8 %50, ptr %49, align 1, !tbaa !21
  br label %63

51:                                               ; preds = %27
  %52 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = call noundef i32 @_ZN8CCFUtils18GetInternalVersionEv(ptr noundef nonnull align 8 dereferenceable(74) %53)
  %55 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 8
  store i32 %54, ptr %55, align 8, !tbaa !19
  %56 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 8
  %57 = load i32, ptr %56, align 8, !tbaa !19
  %58 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 9
  store i32 %57, ptr %58, align 4, !tbaa !20
  %59 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = getelementptr inbounds %class.CCFUtils, ptr %60, i32 0, i32 9
  store i32 %57, ptr %61, align 4, !tbaa !20
  %62 = getelementptr inbounds %class.CCFUtils, ptr %8, i32 0, i32 14
  store i8 0, ptr %62, align 1, !tbaa !21
  br label %63

63:                                               ; preds = %51, %30
  %64 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  ret i32 %64

65:                                               ; preds = %23
  %66 = load ptr, ptr %6, align 8
  %67 = load i32, ptr %7, align 4
  %68 = insertvalue { ptr, i32 } poison, ptr %66, 0
  %69 = insertvalue { ptr, i32 } %68, i32 %67, 1
  resume { ptr, i32 } %69
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8CCFUtils26GetInternalOriginalVersionEv(ptr noundef nonnull align 8 dereferenceable(74)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8CCFUtils16IsBinaryOriginalEv(ptr noundef nonnull align 8 dereferenceable(74)) #3 align 2

attributes #0 = { nobuiltin allocsize(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 = { "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 = { nobuiltin 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 = { 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 #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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, !10, i64 0}
!10 = !{!"_ZTSN3ccf10_ccfResultE", !7, i64 0}
!11 = !{!12, !6, i64 64}
!12 = !{!"_ZTS8CCFUtils", !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32, !6, i64 40, !14, i64 48, !14, i64 52, !14, i64 56, !6, i64 64, !13, i64 72, !13, i64 73}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !14, i64 56}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = !{!12, !14, i64 48}
!20 = !{!12, !14, i64 52}
!21 = !{!12, !13, i64 73}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

declare void @_ZN14CCFUtilsXml_v1C1Ev(ptr noundef nonnull align 8 dereferenceable(1008256)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8CCFUtils18GetInternalVersionEv(ptr noundef nonnull align 8 dereferenceable(74)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8CCFUtils11ReadVersionEPKc(ptr nocapture noundef nonnull align 8 dereferenceable(74) %0, ptr noundef %1) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !12
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %15

7:                                                ; preds = %2
  %8 = tail call noalias noundef nonnull dereferenceable(1008256) ptr @_Znwm(i64 noundef 1008256) #5
  invoke void @_ZN14CCFUtilsXml_v1C1Ev(ptr noundef nonnull align 8 dereferenceable(1008256) %8)
          to label %9 unwind label %13

9:                                                ; preds = %7
  store ptr %8, ptr %4, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %8, i64 56
  store i32 %11, ptr %12, align 8, !tbaa !13
  br label %15

13:                                               ; preds = %7
  %14 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %8, i64 noundef 1008256) #6
  resume { ptr, i32 } %14

15:                                               ; preds = %9, %2
  %16 = phi ptr [ %8, %9 ], [ %5, %2 ]
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %31, label %17

17:                                               ; preds = %15
  %18 = load ptr, ptr %16, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %18, i64 32
  %20 = load ptr, ptr %19, align 8
  %21 = tail call noundef i32 %20(ptr noundef nonnull align 8 dereferenceable(74) %16, ptr noundef nonnull %1)
  %22 = load ptr, ptr %4, align 8, !tbaa !12
  %23 = tail call noundef i32 @_ZN8CCFUtils18GetInternalVersionEv(ptr noundef nonnull align 8 dereferenceable(74) %22)
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %23, ptr %24, align 8, !tbaa !16
  %25 = load ptr, ptr %4, align 8, !tbaa !12
  %26 = tail call noundef i32 @_ZN8CCFUtils26GetInternalOriginalVersionEv(ptr noundef nonnull align 8 dereferenceable(74) %25)
  %27 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %26, ptr %27, align 4, !tbaa !17
  %28 = load ptr, ptr %4, align 8, !tbaa !12
  %29 = tail call noundef zeroext i1 @_ZN8CCFUtils16IsBinaryOriginalEv(ptr noundef nonnull align 8 dereferenceable(74) %28)
  %30 = zext i1 %29 to i8
  br label %37

31:                                               ; preds = %15
  %32 = tail call noundef i32 @_ZN8CCFUtils18GetInternalVersionEv(ptr noundef nonnull align 8 dereferenceable(74) %16)
  %33 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %32, ptr %33, align 8, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %32, ptr %34, align 4, !tbaa !17
  %35 = load ptr, ptr %4, align 8, !tbaa !12
  %36 = getelementptr inbounds i8, ptr %35, i64 52
  store i32 %32, ptr %36, align 4, !tbaa !17
  br label %37

37:                                               ; preds = %31, %17
  %.sink = phi i8 [ 0, %31 ], [ %30, %17 ]
  %.0 = phi i32 [ 0, %31 ], [ %21, %17 ]
  %38 = getelementptr inbounds i8, ptr %0, i64 73
  store i8 %.sink, ptr %38, align 1
  ret i32 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8CCFUtils26GetInternalOriginalVersionEv(ptr noundef nonnull align 8 dereferenceable(74)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8CCFUtils16IsBinaryOriginalEv(ptr noundef nonnull align 8 dereferenceable(74)) local_unnamed_addr #3 align 2

attributes #0 = { nobuiltin allocsize(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 = { "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 = { nobuiltin 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 = { 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 #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin 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 64}
!6 = !{!"_ZTS8CCFUtils", !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !7, i64 64, !10, i64 72, !10, i64 73}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !11, i64 56}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !9, i64 0}
!16 = !{!6, !11, i64 48}
!17 = !{!6, !11, i64 52}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass