; LLVM IR from mkazhdan/DMG :: Util/GridStream.ll (ZN14FileBackedGridC2Eii)

; 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.FileBackedGrid = type <{ %class.StreamingGrid, i64, i64, ptr, ptr, i32, i32, i32, i32, i8, [7 x i8] }>
%class.StreamingGrid = type { %class.IOClient }
%class.IOClient = type { ptr, %"class.boost::recursive_timed_mutex", ptr }
%"class.boost::recursive_timed_mutex" = type <{ %union.pthread_mutex_t, %union.pthread_cond_t, i8, [7 x i8], i64, i32, [4 x i8] }>
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }

@_ZTV14FileBackedGrid = external dso_local unnamed_addr constant { [12 x ptr] }, align 8
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN13StreamingGridC2Ev(ptr noundef nonnull align 8 dereferenceable(128)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z11NullPointerIhEPT_v() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14FileBackedGridC2Eii(ptr noundef nonnull align 8 dereferenceable(177) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @_ZN13StreamingGridC2Ev(ptr noundef nonnull align 8 dereferenceable(128) %9)
  store ptr getelementptr inbounds inrange(-16, 80) ({ [12 x ptr] }, ptr @_ZTV14FileBackedGrid, i32 0, i32 0, i32 2), ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 2
  store i64 0, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 1
  store i64 0, ptr %11, align 8, !tbaa !21
  %12 = invoke noundef ptr @_Z16CreateFileHandlePKcS0_b(ptr noundef @.str.13, ptr noundef null, i1 noundef zeroext true)
          to label %13 unwind label %25

13:                                               ; preds = %3
  %14 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 3
  store ptr %12, ptr %14, align 8, !tbaa !22
  %15 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 9
  store i8 1, ptr %15, align 8, !tbaa !23
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 5
  store i32 %16, ptr %17, align 8, !tbaa !24
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 6
  store i32 %18, ptr %19, align 4, !tbaa !25
  %20 = invoke noundef ptr @_Z11NullPointerIhEPT_v()
          to label %21 unwind label %25

21:                                               ; preds = %13
  %22 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 4
  store ptr %20, ptr %22, align 8, !tbaa !26
  %23 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 8
  store i32 0, ptr %23, align 4, !tbaa !27
  %24 = getelementptr inbounds %class.FileBackedGrid, ptr %9, i32 0, i32 7
  store i32 0, ptr %24, align 8, !tbaa !28
  ret void

25:                                               ; preds = %13, %3
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %7, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %8, align 4
  call void @_ZN13StreamingGridD2Ev(ptr noundef nonnull align 8 dereferenceable(128) %9) #3
  br label %29

29:                                               ; preds = %25
  %30 = load ptr, ptr %7, align 8
  %31 = load i32, ptr %8, align 4
  %32 = insertvalue { ptr, i32 } poison, ptr %30, 0
  %33 = insertvalue { ptr, i32 } %32, i32 %31, 1
  resume { ptr, i32 } %33
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z16CreateFileHandlePKcS0_b(ptr noundef, ptr noundef, i1 noundef zeroext) #0

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

attributes #0 = { inlinehint 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 = { 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 #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !20, i64 136}
!14 = !{!"_ZTS14FileBackedGrid", !15, i64 0, !20, i64 128, !20, i64 136, !6, i64 144, !6, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !18, i64 176}
!15 = !{!"_ZTS13StreamingGrid", !16, i64 0}
!16 = !{!"_ZTS8IOClient", !17, i64 8, !6, i64 120}
!17 = !{!"_ZTSN5boost21recursive_timed_mutexE", !7, i64 0, !7, i64 40, !18, i64 88, !19, i64 96, !10, i64 104}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"long long", !7, i64 0}
!21 = !{!14, !20, i64 128}
!22 = !{!14, !6, i64 144}
!23 = !{!14, !18, i64 176}
!24 = !{!14, !10, i64 160}
!25 = !{!14, !10, i64 164}
!26 = !{!14, !6, i64 152}
!27 = !{!14, !10, i64 172}
!28 = !{!14, !10, i64 168}


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

@_ZTV14FileBackedGrid = external dso_local unnamed_addr constant { [12 x ptr] }, align 8
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN13StreamingGridC2Ev(ptr noundef nonnull align 8 dereferenceable(128)) unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14FileBackedGridC2Eii(ptr noundef nonnull align 8 dereferenceable(177) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN13StreamingGridC2Ev(ptr noundef nonnull align 8 dereferenceable(128) %0)
  store ptr getelementptr inbounds inrange(-16, 80) (i8, ptr @_ZTV14FileBackedGrid, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  %5 = invoke noundef ptr @_Z16CreateFileHandlePKcS0_b(ptr noundef nonnull @.str.13, ptr noundef null, i1 noundef zeroext true)
          to label %6 unwind label %15

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 144
  store ptr %5, ptr %7, align 8, !tbaa !8
  %8 = getelementptr inbounds i8, ptr %0, i64 176
  store i8 1, ptr %8, align 8, !tbaa !19
  %9 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 %2, ptr %9, align 8, !tbaa !20
  %10 = getelementptr inbounds i8, ptr %0, i64 164
  store i32 %1, ptr %10, align 4, !tbaa !21
  %11 = tail call noundef ptr @_Z11NullPointerIhEPT_v()
  %12 = getelementptr inbounds i8, ptr %0, i64 152
  store ptr %11, ptr %12, align 8, !tbaa !22
  %13 = getelementptr inbounds i8, ptr %0, i64 172
  store i32 0, ptr %13, align 4, !tbaa !23
  %14 = getelementptr inbounds i8, ptr %0, i64 168
  store i32 0, ptr %14, align 8, !tbaa !24
  ret void

15:                                               ; preds = %3
  %16 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN13StreamingGridD2Ev(ptr noundef nonnull align 8 dereferenceable(128) %0) #4
  resume { ptr, i32 } %16
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z16CreateFileHandlePKcS0_b(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { inlinehint 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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !17, i64 144}
!9 = !{!"_ZTS14FileBackedGrid", !10, i64 0, !18, i64 128, !18, i64 136, !17, i64 144, !17, i64 152, !16, i64 160, !16, i64 164, !16, i64 168, !16, i64 172, !14, i64 176}
!10 = !{!"_ZTS13StreamingGrid", !11, i64 0}
!11 = !{!"_ZTS8IOClient", !12, i64 8, !17, i64 120}
!12 = !{!"_ZTSN5boost21recursive_timed_mutexE", !13, i64 0, !13, i64 40, !14, i64 88, !15, i64 96, !16, i64 104}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!"bool", !13, i64 0}
!15 = !{!"long", !13, i64 0}
!16 = !{!"int", !13, i64 0}
!17 = !{!"any pointer", !13, i64 0}
!18 = !{!"long long", !13, i64 0}
!19 = !{!9, !14, i64 176}
!20 = !{!9, !16, i64 160}
!21 = !{!9, !16, i64 164}
!22 = !{!9, !17, i64 152}
!23 = !{!9, !16, i64 172}
!24 = !{!9, !16, i64 168}


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