; LLVM IR from kala13x/libxutils :: src/sys (xfs)

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

%struct.XFile = type { i64, i32, i64, i64, i8, i8, i32, i32 }

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @XFile_Read(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @XFile_GetStats(ptr noundef) #3

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

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %17, %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i32 @XFile_GetStats(ptr noundef %20)
  %22 = icmp sle i32 %21, 0
  br i1 %22, label %29, label %23

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.XFile, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = and i32 %26, 61440
  %28 = icmp eq i32 %27, 32768
  br i1 %28, label %30, label %29

29:                                               ; preds = %23, %19
  store ptr null, ptr %4, align 8
  br label %120

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XFile, ptr %32, i32 0, i32 3
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = icmp ult i64 %31, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %30
  %37 = load i64, ptr %6, align 8, !tbaa !9
  br label %42

38:                                               ; preds = %30
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XFile, ptr %39, i32 0, i32 3
  %41 = load i64, ptr %40, align 8, !tbaa !14
  br label %42

42:                                               ; preds = %38, %36
  %43 = phi i64 [ %37, %36 ], [ %41, %38 ]
  store i64 %43, ptr %8, align 8, !tbaa !9
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %42
  %47 = load i64, ptr %8, align 8, !tbaa !9
  br label %52

48:                                               ; preds = %42
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XFile, ptr %49, i32 0, i32 3
  %51 = load i64, ptr %50, align 8, !tbaa !14
  br label %52

52:                                               ; preds = %48, %46
  %53 = phi i64 [ %47, %46 ], [ %51, %48 ]
  store i64 %53, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = add i64 %54, 1
  %56 = call noalias ptr @malloc(i64 noundef %55) #5
  store ptr %56, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  br i1 %58, label %59, label %60

59:                                               ; preds = %52
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %119

60:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !15
  br label %61

61:                                               ; preds = %99, %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = sub i64 %62, %63
  store i64 %64, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.XFile, ptr %65, i32 0, i32 2
  %67 = load i64, ptr %66, align 8, !tbaa !16
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = icmp ult i64 %67, %68
  br i1 %69, label %70, label %74

70:                                               ; preds = %61
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.XFile, ptr %71, i32 0, i32 2
  %73 = load i64, ptr %72, align 8, !tbaa !16
  br label %76

74:                                               ; preds = %61
  %75 = load i64, ptr %13, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %74, %70
  %77 = phi i64 [ %73, %70 ], [ %75, %74 ]
  store i64 %77, ptr %14, align 8, !tbaa !9
  %78 = load i64, ptr %14, align 8, !tbaa !9
  %79 = icmp eq i64 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %76
  store i32 2, ptr %10, align 4
  br label %96

81:                                               ; preds = %76
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = load i64, ptr %11, align 8, !tbaa !9
  %85 = getelementptr inbounds i8, ptr %83, i64 %84
  %86 = load i64, ptr %14, align 8, !tbaa !9
  %87 = call i32 @XFile_Read(ptr noundef %82, ptr noundef %85, i64 noundef %86)
  store i32 %87, ptr %12, align 4, !tbaa !15
  %88 = load i32, ptr %12, align 4, !tbaa !15
  %89 = icmp sgt i32 %88, 0
  br i1 %89, label %90, label %95

90:                                               ; preds = %81
  %91 = load i32, ptr %12, align 4, !tbaa !15
  %92 = sext i32 %91 to i64
  %93 = load i64, ptr %11, align 8, !tbaa !9
  %94 = add i64 %93, %92
  store i64 %94, ptr %11, align 8, !tbaa !9
  br label %95

95:                                               ; preds = %90, %81
  store i32 0, ptr %10, align 4
  br label %96

96:                                               ; preds = %95, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %97 = load i32, ptr %10, align 4
  switch i32 %97, label %122 [
    i32 0, label %98
    i32 2, label %102
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %12, align 4, !tbaa !15
  %101 = icmp sgt i32 %100, 0
  br i1 %101, label %61, label %102, !llvm.loop !17

102:                                              ; preds = %99, %96
  %103 = load i64, ptr %11, align 8, !tbaa !9
  %104 = icmp ne i64 %103, 0
  br i1 %104, label %107, label %105

105:                                              ; preds = %102
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %106) #4
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %118

107:                                              ; preds = %102
  %108 = load ptr, ptr %9, align 8, !tbaa !5
  %109 = load i64, ptr %11, align 8, !tbaa !9
  %110 = getelementptr inbounds i8, ptr %108, i64 %109
  store i8 0, ptr %110, align 1, !tbaa !19
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = icmp ne ptr %111, null
  br i1 %112, label %113, label %116

113:                                              ; preds = %107
  %114 = load i64, ptr %11, align 8, !tbaa !9
  %115 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %114, ptr %115, align 8, !tbaa !9
  br label %116

116:                                              ; preds = %113, %107
  %117 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %117, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %118

118:                                              ; preds = %116, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %119

119:                                              ; preds = %118, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %120

120:                                              ; preds = %119, %29
  %121 = load ptr, ptr %4, align 8
  ret ptr %121

122:                                              ; preds = %96
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind 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 = { 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 = { 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 #4 = { nounwind }
attributes #5 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"XFile", !10, i64 0, !13, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 33, !13, i64 36, !13, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!7, !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"

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XFile_Read(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @XFile_GetStats(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @XFile_LoadSize(ptr noundef %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #2 {
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %3
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %4, %3
  %6 = tail call i32 @XFile_GetStats(ptr noundef %0)
  %7 = icmp slt i32 %6, 1
  br i1 %7, label %33, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = and i32 %10, 61440
  %12 = icmp eq i32 %11, 32768
  br i1 %12, label %13, label %33

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load i64, ptr %14, align 8, !tbaa !12
  %. = tail call i64 @llvm.umin.i64(i64 %15, i64 %1)
  %.not53 = icmp eq i64 %., 0
  %spec.select = select i1 %.not53, i64 %15, i64 %.
  %16 = add i64 %spec.select, 1
  %17 = tail call noalias ptr @malloc(i64 noundef %16) #4
  %18 = icmp eq ptr %17, null
  br i1 %18, label %33, label %.preheader

.preheader:                                       ; preds = %13
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  br label %20

20:                                               ; preds = %.preheader, %24
  %.039 = phi i64 [ %.140, %24 ], [ 0, %.preheader ]
  %21 = sub i64 %spec.select, %.039
  %22 = load i64, ptr %19, align 8, !tbaa !13
  %.55 = tail call i64 @llvm.umin.i64(i64 %22, i64 %21)
  %23 = icmp eq i64 %.55, 0
  br i1 %23, label %.thread, label %24

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %17, i64 %.039
  %26 = tail call i32 @XFile_Read(ptr noundef nonnull %0, ptr noundef nonnull %25, i64 noundef %.55)
  %narrow = tail call i32 @llvm.smax.i32(i32 %26, i32 0)
  %27 = zext nneg i32 %narrow to i64
  %.140 = add i64 %.039, %27
  %28 = icmp sgt i32 %26, 0
  br i1 %28, label %20, label %.thread, !llvm.loop !14

.thread:                                          ; preds = %20, %24
  %.24161 = phi i64 [ %.140, %24 ], [ %.039, %20 ]
  %.not54 = icmp eq i64 %.24161, 0
  br i1 %.not54, label %29, label %30

29:                                               ; preds = %.thread
  tail call void @free(ptr noundef %17) #5
  br label %33

30:                                               ; preds = %.thread
  %31 = getelementptr inbounds i8, ptr %17, i64 %.24161
  store i8 0, ptr %31, align 1, !tbaa !16
  br i1 %.not, label %33, label %32

32:                                               ; preds = %30
  store i64 %.24161, ptr %2, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %13, %30, %32, %29, %5, %8
  %.2 = phi ptr [ null, %8 ], [ null, %5 ], [ null, %13 ], [ null, %29 ], [ %17, %32 ], [ %17, %30 ]
  ret ptr %.2
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind allocsize(0) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"XFile", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !11, i64 36, !11, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!10, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!7, !7, i64 0}


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