; LLVM IR from mkazhdan/DMG :: Util/GridStream.ll (ZN24CompressedFileBackedGridC2EiiP11_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.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
@_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: mustprogress uwtable
define dso_local void @_ZN24CompressedFileBackedGridC2EiiP11_FileHandle(ptr noundef nonnull align 8 dereferenceable(193) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #4 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 @_ZTV24CompressedFileBackedGrid, i32 0, i32 0, i32 2), ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 4
  store i64 0, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 3
  store i64 0, ptr %13, align 8, !tbaa !21
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 5
  store ptr %14, ptr %15, align 8, !tbaa !22
  %16 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 12
  store i8 1, ptr %16, align 8, !tbaa !23
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 8
  store i32 %17, ptr %18, align 8, !tbaa !24
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 9
  store i32 %19, ptr %20, align 4, !tbaa !25
  %21 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 11
  store i32 0, ptr %21, align 4, !tbaa !26
  %22 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 10
  store i32 0, ptr %22, align 8, !tbaa !27
  %23 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 9
  %24 = load i32, ptr %23, align 4, !tbaa !25
  %25 = add nsw i32 %24, 12
  %26 = sitofp i32 %25 to double
  %27 = fmul double %26, 1.002000e+00
  %28 = fptosi double %27 to i32
  %29 = getelementptr inbounds %class.CompressedFileBackedGrid, ptr %11, i32 0, i32 1
  store i32 %28, ptr %29, align 8, !tbaa !28
  %30 = invoke noundef ptr @_Z11NullPointerIhEPT_v()
          to label %31 unwind label %45

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

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

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

45:                                               ; preds = %31, %4
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %9, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %10, align 4
  call void @_ZN13StreamingGridD2Ev(ptr noundef nonnull align 8 dereferenceable(128) %11) #5
  br label %50

49:                                               ; preds = %37
  ret void

50:                                               ; preds = %45
  %51 = load ptr, ptr %9, align 8
  %52 = load i32, ptr %10, align 4
  %53 = insertvalue { ptr, i32 } poison, ptr %51, 0
  %54 = insertvalue { ptr, i32 } %53, i32 %52, 1
  resume { ptr, i32 } %54
}

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

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

26:                                               ; preds = %4
  ret void
}

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

!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