; LLVM IR from Samson-Mano/EM_Propogation_simulation :: EM_Propogation_simulation/src/ImGui/imgui.ll (Z18ImFileLoadToMemoryPKcS0_Pmi)

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

@.str.3 = external hidden unnamed_addr constant [117 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._Z18ImFileLoadToMemoryPKcS0_Pmi = external hidden unnamed_addr constant [68 x i8], align 1

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

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN5ImGui8MemAllocEm(i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5ImGui7MemFreeEPv(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z10ImFileOpenPKcS0_(ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z13ImFileGetSizeP8_IO_FILE(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z10ImFileReadPvyyP8_IO_FILE(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z18ImFileLoadToMemoryPKcS0_Pmi(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br label %19

19:                                               ; preds = %16, %4
  %20 = phi i1 [ false, %4 ], [ %18, %16 ]
  br i1 %20, label %21, label %22

21:                                               ; preds = %19
  br label %24

22:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.15, ptr noundef @.str.3, i32 noundef 2000, ptr noundef @__PRETTY_FUNCTION__._Z18ImFileLoadToMemoryPKcS0_Pmi) #4
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %28, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %27, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call noundef ptr @_Z10ImFileOpenPKcS0_(ptr noundef %30, ptr noundef %31)
  store ptr %32, ptr %10, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %86

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call noundef i64 @_Z13ImFileGetSizeP8_IO_FILE(ptr noundef %36)
  store i64 %37, ptr %12, align 8, !tbaa !11
  %38 = load i64, ptr %12, align 8, !tbaa !11
  %39 = icmp eq i64 %38, -1
  br i1 %39, label %40, label %43

40:                                               ; preds = %35
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef %41)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

43:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %44 = load i64, ptr %12, align 8, !tbaa !11
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = add i64 %44, %46
  %48 = call noundef ptr @_ZN5ImGui8MemAllocEm(i64 noundef %47)
  store ptr %48, ptr %13, align 8, !tbaa !5
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %54

51:                                               ; preds = %43
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef %52)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

54:                                               ; preds = %43
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = load i64, ptr %12, align 8, !tbaa !11
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = call noundef i64 @_Z10ImFileReadPvyyP8_IO_FILE(ptr noundef %55, i64 noundef 1, i64 noundef %56, ptr noundef %57)
  %59 = load i64, ptr %12, align 8, !tbaa !11
  %60 = icmp ne i64 %58, %59
  br i1 %60, label %61, label %65

61:                                               ; preds = %54
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef %62)
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  call void @_ZN5ImGui7MemFreeEPv(ptr noundef %64)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

65:                                               ; preds = %54
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = icmp sgt i32 %66, 0
  br i1 %67, label %68, label %74

68:                                               ; preds = %65
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = load i64, ptr %12, align 8, !tbaa !11
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %71, i8 0, i64 %73, i1 false)
  br label %74

74:                                               ; preds = %68, %65
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef %75)
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %82

79:                                               ; preds = %74
  %80 = load i64, ptr %12, align 8, !tbaa !11
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %80, ptr %81, align 8, !tbaa !11
  br label %82

82:                                               ; preds = %79, %74
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %83, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

84:                                               ; preds = %82, %61, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %85

85:                                               ; preds = %84, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %86

86:                                               ; preds = %85, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %87 = load ptr, ptr %5, align 8
  ret ptr %87
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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 = !{!"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.3 = external hidden unnamed_addr constant [117 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._Z18ImFileLoadToMemoryPKcS0_Pmi = external hidden unnamed_addr constant [68 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN5ImGui8MemAllocEm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5ImGui7MemFreeEPv(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z10ImFileOpenPKcS0_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z13ImFileGetSizeP8_IO_FILE(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z10ImFileReadPvyyP8_IO_FILE(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z18ImFileLoadToMemoryPKcS0_Pmi(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %7 = and i1 %5, %6
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.3, i32 noundef 2000, ptr noundef nonnull @__PRETTY_FUNCTION__._Z18ImFileLoadToMemoryPKcS0_Pmi) #3
  unreachable

9:                                                ; preds = %4
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %11, label %10

10:                                               ; preds = %9
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %10, %9
  %12 = tail call noundef ptr @_Z10ImFileOpenPKcS0_(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %13 = icmp eq ptr %12, null
  br i1 %13, label %37, label %14

14:                                               ; preds = %11
  %15 = tail call noundef i64 @_Z13ImFileGetSizeP8_IO_FILE(ptr noundef nonnull %12)
  %16 = icmp eq i64 %15, -1
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = tail call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef nonnull %12)
  br label %37

19:                                               ; preds = %14
  %20 = sext i32 %3 to i64
  %21 = add i64 %15, %20
  %22 = tail call noundef ptr @_ZN5ImGui8MemAllocEm(i64 noundef %21)
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  %25 = tail call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef nonnull %12)
  br label %37

26:                                               ; preds = %19
  %27 = tail call noundef i64 @_Z10ImFileReadPvyyP8_IO_FILE(ptr noundef nonnull %22, i64 noundef 1, i64 noundef %15, ptr noundef nonnull %12)
  %.not35 = icmp eq i64 %27, %15
  br i1 %.not35, label %30, label %28

28:                                               ; preds = %26
  %29 = tail call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef nonnull %12)
  tail call void @_ZN5ImGui7MemFreeEPv(ptr noundef nonnull %22)
  br label %37

30:                                               ; preds = %26
  %31 = icmp sgt i32 %3, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %30
  %33 = getelementptr inbounds i8, ptr %22, i64 %15
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %33, i8 0, i64 %20, i1 false)
  br label %34

34:                                               ; preds = %32, %30
  %35 = tail call noundef zeroext i1 @_Z11ImFileCloseP8_IO_FILE(ptr noundef nonnull %12)
  br i1 %.not, label %37, label %36

36:                                               ; preds = %34
  store i64 %15, ptr %2, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %17, %34, %36, %28, %24, %11
  %.2 = phi ptr [ null, %11 ], [ null, %17 ], [ null, %24 ], [ null, %28 ], [ %22, %36 ], [ %22, %34 ]
  ret ptr %.2
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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