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

; 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.CompressedFileBackedGrid = type <{ %class.StreamingGrid, i32, [4 x i8], i64, i64, ptr, 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 }

@stderr = external global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1
@_ZTV24CompressedFileBackedGrid = external dso_local unnamed_addr constant { [12 x ptr] }, align 8
@.str.16 = external hidden unnamed_addr constant [67 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 @_Z12AllocPointerIhEPT_m(i64 noundef) #1

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN24CompressedFileBackedGridC2Eii(ptr noundef nonnull align 8 dereferenceable(193) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #4 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 @_ZTV24CompressedFileBackedGrid, i32 0, i32 0, i32 2), ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 4
  store i64 0, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 3
  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 %44

13:                                               ; preds = %3
  %14 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 5
  store ptr %12, ptr %14, align 8, !tbaa !22
  %15 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 12
  store i8 1, ptr %15, align 8, !tbaa !23
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 8
  store i32 %16, ptr %17, align 8, !tbaa !24
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 9
  store i32 %18, ptr %19, align 4, !tbaa !25
  %20 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 11
  store i32 0, ptr %20, align 4, !tbaa !26
  %21 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 10
  store i32 0, ptr %21, align 8, !tbaa !27
  %22 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 9
  %23 = load i32, ptr %22, align 4, !tbaa !25
  %24 = add nsw i32 %23, 12
  %25 = sitofp i32 %24 to double
  %26 = fmul double %25, 1.002000e+00
  %27 = fptosi double %26 to i32
  %28 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 1
  store i32 %27, ptr %28, align 8, !tbaa !28
  %29 = invoke noundef ptr @_Z11NullPointerIhEPT_v()
          to label %30 unwind label %44

30:                                               ; preds = %13
  %31 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 6
  store ptr %29, ptr %31, align 8, !tbaa !29
  %32 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !28
  %34 = sext i32 %33 to i64
  %35 = invoke noundef ptr @_Z12AllocPointerIhEPT_m(i64 noundef %34)
          to label %36 unwind label %44

36:                                               ; preds = %30
  %37 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 7
  store ptr %35, ptr %37, align 8, !tbaa !30
  %38 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %9, i32 0, i32 7
  %39 = load ptr, ptr %38, align 8, !tbaa !30
  %40 = icmp ne ptr %39, null
  br i1 %40, label %48, label %41

41:                                               ; preds = %36
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str.16) #5
  call void @exit(i32 noundef 0) #6
  unreachable

44:                                               ; preds = %30, %13, %3
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %7, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %8, align 4
  call void @_ZN13StreamingGridD2Ev(ptr noundef nonnull align 8 dereferenceable(128) %9) #5
  br label %49

48:                                               ; preds = %36
  ret void

49:                                               ; preds = %44
  %50 = load ptr, ptr %7, align 8
  %51 = load i32, ptr %8, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

; 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 = { 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 = { noreturn 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 #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 = { nounwind }
attributes #6 = { noreturn 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 144}
!14 = !{!"_ZTS24CompressedFileBackedGrid", !15, i64 0, !10, i64 128, !20, i64 136, !20, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !18, i64 192}
!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 136}
!22 = !{!14, !6, i64 152}
!23 = !{!14, !18, i64 192}
!24 = !{!14, !10, i64 176}
!25 = !{!14, !10, i64 180}
!26 = !{!14, !10, i64 188}
!27 = !{!14, !10, i64 184}
!28 = !{!14, !10, i64 128}
!29 = !{!14, !6, i64 160}
!30 = !{!14, !6, 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1
@_ZTV24CompressedFileBackedGrid = external dso_local unnamed_addr constant { [12 x ptr] }, align 8
@.str.16 = external hidden unnamed_addr constant [67 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 @_Z12AllocPointerIhEPT_m(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

; 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 uwtable
define dso_local void @_ZN24CompressedFileBackedGridC2Eii(ptr noundef nonnull align 8 dereferenceable(193) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #4 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 @_ZTV24CompressedFileBackedGrid, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 136
  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 %27

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 152
  store ptr %5, ptr %7, align 8, !tbaa !8
  %8 = getelementptr inbounds i8, ptr %0, i64 192
  store i8 1, ptr %8, align 8, !tbaa !19
  %9 = getelementptr inbounds i8, ptr %0, i64 176
  store i32 %2, ptr %9, align 8, !tbaa !20
  %10 = getelementptr inbounds i8, ptr %0, i64 180
  store i32 %1, ptr %10, align 4, !tbaa !21
  %11 = getelementptr inbounds i8, ptr %0, i64 188
  store i32 0, ptr %11, align 4, !tbaa !22
  %12 = getelementptr inbounds i8, ptr %0, i64 184
  store i32 0, ptr %12, align 8, !tbaa !23
  %13 = add nsw i32 %1, 12
  %14 = sitofp i32 %13 to double
  %15 = fmul double %14, 1.002000e+00
  %16 = fptosi double %15 to i32
  %17 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 %16, ptr %17, align 8, !tbaa !24
  %18 = tail call noundef ptr @_Z11NullPointerIhEPT_v()
  %19 = getelementptr inbounds i8, ptr %0, i64 160
  store ptr %18, ptr %19, align 8, !tbaa !25
  %20 = load i32, ptr %17, align 8, !tbaa !24
  %21 = sext i32 %20 to i64
  %22 = tail call noundef ptr @_Z12AllocPointerIhEPT_m(i64 noundef %21)
  %23 = getelementptr inbounds i8, ptr %0, i64 168
  store ptr %22, ptr %23, align 8, !tbaa !26
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %24, label %29

24:                                               ; preds = %6
  %25 = load ptr, ptr @stderr, align 8, !tbaa !27
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.16) #6
  tail call void @exit(i32 noundef 0) #7
  unreachable

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

29:                                               ; preds = %6
  ret void
}

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

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 = { nofree 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 = { noreturn 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { cold nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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 152}
!9 = !{!"_ZTS24CompressedFileBackedGrid", !10, i64 0, !16, i64 128, !18, i64 136, !18, i64 144, !17, i64 152, !17, i64 160, !17, i64 168, !16, i64 176, !16, i64 180, !16, i64 184, !16, i64 188, !14, i64 192}
!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 192}
!20 = !{!9, !16, i64 176}
!21 = !{!9, !16, i64 180}
!22 = !{!9, !16, i64 188}
!23 = !{!9, !16, i64 184}
!24 = !{!9, !16, i64 128}
!25 = !{!9, !17, i64 160}
!26 = !{!9, !17, i64 168}
!27 = !{!17, !17, i64 0}


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