; LLVM IR from chromia/lichtenberg :: src/core.ll (ZN11lichtenberg10CellList2D4loadEPKc)

; 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.lichtenberg::CellList2D" = type { ptr, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

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

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #3

declare noalias ptr @fopen(ptr noundef, ptr noundef) #4

declare i32 @fclose(ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN11lichtenberg10CellList2D4loadEPKc(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #5 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noalias ptr @fopen(ptr noundef %11, ptr noundef @.str.1)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %85

16:                                               ; preds = %2
  %17 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %26

20:                                               ; preds = %16
  %21 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @_ZdaPv(ptr noundef %22) #7
  br label %25

25:                                               ; preds = %24, %20
  br label %26

26:                                               ; preds = %25, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call i64 @fread(ptr noundef %8, i64 noundef 4, i64 noundef 1, ptr noundef %27)
  %29 = icmp ne i64 %28, 1
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  br label %81

31:                                               ; preds = %26
  %32 = load i32, ptr %8, align 4, !tbaa !12
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %77

34:                                               ; preds = %31
  %35 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 1
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call i64 @fread(ptr noundef %35, i64 noundef 4, i64 noundef 1, ptr noundef %36)
  %38 = icmp ne i64 %37, 1
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  br label %81

40:                                               ; preds = %34
  %41 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 2
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i64 @fread(ptr noundef %41, i64 noundef 4, i64 noundef 1, ptr noundef %42)
  %44 = icmp ne i64 %43, 1
  br i1 %44, label %45, label %46

45:                                               ; preds = %40
  br label %81

46:                                               ; preds = %40
  %47 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !13
  %49 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !14
  %51 = mul nsw i32 %48, %50
  %52 = sext i32 %51 to i64
  %53 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %52, i64 12)
  %54 = extractvalue { i64, i1 } %53, 1
  %55 = extractvalue { i64, i1 } %53, 0
  %56 = select i1 %54, i64 -1, i64 %55
  %57 = call noalias noundef nonnull ptr @_Znam(i64 noundef %56) #8
  %58 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 0
  store ptr %57, ptr %58, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %59 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 1
  %60 = load i32, ptr %59, align 8, !tbaa !13
  %61 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 2
  %62 = load i32, ptr %61, align 4, !tbaa !14
  %63 = mul nsw i32 %60, %62
  %64 = sext i32 %63 to i64
  store i64 %64, ptr %9, align 8, !tbaa !15
  %65 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %10, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = load i64, ptr %9, align 8, !tbaa !15
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = call i64 @fread(ptr noundef %66, i64 noundef 12, i64 noundef %67, ptr noundef %68)
  %70 = load i64, ptr %9, align 8, !tbaa !15
  %71 = icmp ne i64 %69, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %46
  store i32 2, ptr %7, align 4
  br label %74

73:                                               ; preds = %46
  store i32 0, ptr %7, align 4
  br label %74

74:                                               ; preds = %73, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  %75 = load i32, ptr %7, align 4
  switch i32 %75, label %84 [
    i32 0, label %76
    i32 2, label %81
  ]

76:                                               ; preds = %74
  br label %78

77:                                               ; preds = %31
  br label %81

78:                                               ; preds = %76
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = call i32 @fclose(ptr noundef %79)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %84

81:                                               ; preds = %77, %74, %45, %39, %30
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = call i32 @fclose(ptr noundef %82)
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %84

84:                                               ; preds = %81, %78, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %85

85:                                               ; preds = %84, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %86 = load i1, ptr %3, align 1
  ret i1 %86
}

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 = { 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 nounwind }
attributes #8 = { builtin allocsize(0) }

!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, !6, i64 0}
!10 = !{!"_ZTSN11lichtenberg10CellList2DE", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 12}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}


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

@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

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

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN11lichtenberg10CellList2D4loadEPKc(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #5 align 2 {
  %3 = alloca i32, align 4
  %4 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %33, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %.not16 = icmp eq ptr %6, null
  br i1 %.not16, label %8, label %7

7:                                                ; preds = %5
  tail call void @_ZdaPv(ptr noundef nonnull %6) #6
  br label %8

8:                                                ; preds = %7, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  %9 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %4)
  %10 = icmp eq i64 %9, 1
  %11 = load i32, ptr %3, align 4
  %12 = icmp eq i32 %11, 1
  %or.cond = select i1 %10, i1 %12, i1 false
  br i1 %or.cond, label %13, label %30

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = tail call i64 @fread(ptr noundef nonnull %14, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %4)
  %.not17 = icmp eq i64 %15, 1
  br i1 %.not17, label %16, label %30

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  %18 = tail call i64 @fread(ptr noundef nonnull %17, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %4)
  %.not18 = icmp eq i64 %18, 1
  br i1 %.not18, label %19, label %30

19:                                               ; preds = %16
  %20 = load i32, ptr %14, align 8, !tbaa !11
  %21 = load i32, ptr %17, align 4, !tbaa !12
  %22 = mul nsw i32 %21, %20
  %23 = sext i32 %22 to i64
  %24 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %23, i64 12)
  %25 = extractvalue { i64, i1 } %24, 1
  %26 = extractvalue { i64, i1 } %24, 0
  %27 = select i1 %25, i64 -1, i64 %26
  %28 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %27) #8
  store ptr %28, ptr %0, align 8, !tbaa !5
  %29 = tail call i64 @fread(ptr noundef nonnull %28, i64 noundef 12, i64 noundef %23, ptr noundef nonnull %4)
  %.not19 = icmp eq i64 %29, %23
  br i1 %.not19, label %31, label %30

30:                                               ; preds = %19, %16, %13, %8
  br label %31

31:                                               ; preds = %19, %30
  %.0 = phi i1 [ false, %30 ], [ true, %19 ]
  %32 = tail call i32 @fclose(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #7
  br label %33

33:                                               ; preds = %2, %31
  %.1 = phi i1 [ %.0, %31 ], [ false, %2 ]
  ret i1 %.1
}

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #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 = { builtin nounwind }
attributes #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }

!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 0}
!6 = !{!"_ZTSN11lichtenberg10CellList2DE", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass