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

; 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

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 @_ZN14FileBackedGridC2EiiP11_FileHandle(ptr noundef nonnull align 8 dereferenceable(177) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @_ZN13StreamingGridC2Ev(ptr noundef nonnull align 8 dereferenceable(128) %11)
  store ptr getelementptr inbounds inrange(-16, 80) ({ [12 x ptr] }, ptr @_ZTV14FileBackedGrid, i32 0, i32 0, i32 2), ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds %class.FileBackedGrid, ptr %11, i32 0, i32 2
  store i64 0, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %class.FileBackedGrid, ptr %11, i32 0, i32 1
  store i64 0, ptr %13, align 8, !tbaa !21
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.FileBackedGrid, ptr %11, i32 0, i32 3
  store ptr %14, ptr %15, align 8, !tbaa !22
  %16 = getelementptr inbounds %class.FileBackedGrid, ptr %11, i32 0, i32 9
  store i8 1, ptr %16, align 8, !tbaa !23
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.FileBackedGrid, ptr %11, i32 0, i32 5
  store i32 %17, ptr %18, align 8, !tbaa !24
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = getelementptr inbounds %class.FileBackedGrid, ptr %11, i32 0, i32 6
  store i32 %19, ptr %20, align 4, !tbaa !25
  %21 = invoke noundef ptr @_Z11NullPointerIhEPT_v()
          to label %22 unwind label %26

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

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

30:                                               ; preds = %26
  %31 = load ptr, ptr %9, align 8
  %32 = load i32, ptr %10, align 4
  %33 = insertvalue { ptr, i32 } poison, ptr %31, 0
  %34 = insertvalue { ptr, i32 } %33, i32 %32, 1
  resume { ptr, i32 } %34
}

; 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

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 @_ZN14FileBackedGridC2EiiP11_FileHandle(ptr noundef nonnull align 8 dereferenceable(177) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) 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
  %5 = getelementptr inbounds i8, ptr %0, i64 128
  %6 = getelementptr inbounds i8, ptr %0, i64 144
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, i8 0, i64 16, i1 false)
  store ptr %3, ptr %6, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %0, i64 176
  store i8 1, ptr %7, align 8, !tbaa !19
  %8 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 %2, ptr %8, align 8, !tbaa !20
  %9 = getelementptr inbounds i8, ptr %0, i64 164
  store i32 %1, ptr %9, align 4, !tbaa !21
  %10 = tail call noundef ptr @_Z11NullPointerIhEPT_v()
  %11 = getelementptr inbounds i8, ptr %0, i64 152
  store ptr %10, ptr %11, align 8, !tbaa !22
  %12 = getelementptr inbounds i8, ptr %0, i64 172
  store i32 0, ptr %12, align 4, !tbaa !23
  %13 = getelementptr inbounds i8, ptr %0, i64 168
  store i32 0, ptr %13, align 8, !tbaa !24
  ret void
}

; 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) }

!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: GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass