; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_file)

; 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.Chunk = type { i32, i32, i32 }
%struct.HandleMORNFile = type { ptr, ptr, i32 }

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@__FUNCTION__.mMORNRead = external hidden unnamed_addr constant [10 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [52 x i8], align 1

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #0

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @MORNInit(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mMORNRead(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call ptr @MORNInit(ptr noundef %19)
  store ptr %20, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = call ptr @MornChunk(ptr noundef %21, i32 noundef %22)
  store ptr %23, ptr %13, align 8, !tbaa !5
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %5
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %122

27:                                               ; preds = %5
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = icmp sle i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %30, %27
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = icmp sle i32 %32, 0
  br i1 %33, label %34, label %55

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Chunk, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = srem i32 %38, %39
  %41 = icmp ne i32 %40, 0
  %42 = zext i1 %41 to i32
  store i32 %42, ptr %15, align 4, !tbaa !9
  %43 = load i32, ptr %15, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %35
  %46 = load i32, ptr %15, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %46, i32 noundef -1, ptr noundef @.str, i32 noundef 129, ptr noundef @__FUNCTION__.mMORNRead, ptr noundef @.str.2)
  br label %47

47:                                               ; preds = %45, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Chunk, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = sdiv i32 %52, %53
  store i32 %54, ptr %11, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %49, %31
  br label %56

56:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Chunk, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !11
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = mul nsw i32 %60, %61
  %63 = icmp slt i32 %59, %62
  %64 = zext i1 %63 to i32
  store i32 %64, ptr %16, align 4, !tbaa !9
  %65 = load i32, ptr %16, align 4, !tbaa !9
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %76

67:                                               ; preds = %56
  %68 = load i32, ptr %16, align 4, !tbaa !9
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = load i32, ptr %11, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = mul nsw i32 %70, %71
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Chunk, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !11
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %68, i32 noundef -1, ptr noundef @.str, i32 noundef 130, ptr noundef @__FUNCTION__.mMORNRead, ptr noundef @.str.10, i32 noundef %69, i32 noundef %72, i32 noundef %75)
  br label %76

76:                                               ; preds = %67, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.HandleMORNFile, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !13
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.Chunk, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 4, !tbaa !15
  %85 = sext i32 %84 to i64
  %86 = call i32 @fseek(ptr noundef %81, i64 noundef %85, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %115, %78
  %88 = load i32, ptr %17, align 4, !tbaa !9
  %89 = load i32, ptr %10, align 4, !tbaa !9
  %90 = icmp slt i32 %88, %89
  br i1 %90, label %92, label %91

91:                                               ; preds = %87
  store i32 6, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %118

92:                                               ; preds = %87
  br label %93

93:                                               ; preds = %92
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = load i32, ptr %17, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds ptr, ptr %94, i64 %96
  %98 = load ptr, ptr %97, align 8, !tbaa !5
  %99 = load i32, ptr %11, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = load ptr, ptr %12, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.HandleMORNFile, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !13
  %104 = call i64 @fread(ptr noundef %98, i64 noundef %100, i64 noundef 1, ptr noundef %103)
  %105 = trunc i64 %104 to i32
  %106 = icmp ne i32 %105, 1
  %107 = zext i1 %106 to i32
  store i32 %107, ptr %18, align 4, !tbaa !9
  %108 = load i32, ptr %18, align 4, !tbaa !9
  %109 = icmp ne i32 %108, 0
  br i1 %109, label %110, label %112

110:                                              ; preds = %93
  %111 = load i32, ptr %18, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %111, i32 noundef -1, ptr noundef @.str, i32 noundef 133, ptr noundef @__FUNCTION__.mMORNRead, ptr noundef @.str.8)
  br label %112

112:                                              ; preds = %110, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114
  %116 = load i32, ptr %17, align 4, !tbaa !9
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %17, align 4, !tbaa !9
  br label %87, !llvm.loop !16

118:                                              ; preds = %91
  %119 = load ptr, ptr %13, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.Chunk, ptr %119, i32 0, i32 1
  %121 = load i32, ptr %120, align 4, !tbaa !11
  store i32 %121, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %122

122:                                              ; preds = %118, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %123 = load i32, ptr %6, align 4
  ret i32 %123
}

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"Chunk", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!14, !6, i64 0}
!14 = !{!"HandleMORNFile", !6, i64 0, !6, i64 8, !10, i64 16}
!15 = !{!12, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1
@__FUNCTION__.mMORNRead = external hidden unnamed_addr constant [10 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mMORNRead(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = tail call ptr @MORNInit(ptr noundef %0)
  %7 = tail call ptr @MornChunk(ptr noundef %6, i32 noundef %1)
  %8 = icmp eq ptr %7, null
  br i1 %8, label %41, label %9

9:                                                ; preds = %5
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %3, i32 1)
  %10 = icmp slt i32 %4, 1
  %11 = getelementptr inbounds i8, ptr %7, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  br i1 %10, label %13, label %._crit_edge

13:                                               ; preds = %9
  %14 = srem i32 %12, %spec.store.select
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %16, label %15

15:                                               ; preds = %13
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 129, ptr noundef nonnull @__FUNCTION__.mMORNRead, ptr noundef nonnull @.str.2) #4
  %.pre = load i32, ptr %11, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %15, %13
  %17 = phi i32 [ %.pre, %15 ], [ %12, %13 ]
  %18 = sdiv i32 %17, %spec.store.select
  br label %._crit_edge

._crit_edge:                                      ; preds = %9, %16
  %19 = phi i32 [ %17, %16 ], [ %12, %9 ]
  %.034 = phi i32 [ %18, %16 ], [ %4, %9 ]
  %20 = getelementptr inbounds i8, ptr %7, i64 4
  %21 = mul nsw i32 %.034, %spec.store.select
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %._crit_edge
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 130, ptr noundef nonnull @__FUNCTION__.mMORNRead, ptr noundef nonnull @.str.10, i32 noundef %1, i32 noundef %21, i32 noundef %19) #4
  br label %24

24:                                               ; preds = %23, %._crit_edge
  %25 = load ptr, ptr %6, align 8, !tbaa !10
  %26 = getelementptr inbounds i8, ptr %7, i64 8
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = sext i32 %27 to i64
  %29 = tail call i32 @fseek(ptr noundef %25, i64 noundef %28, i32 noundef 0)
  %30 = sext i32 %.034 to i64
  %wide.trip.count = zext nneg i32 %spec.store.select to i64
  br label %33

31:                                               ; preds = %40
  %32 = load i32, ptr %20, align 4, !tbaa !5
  br label %41

33:                                               ; preds = %24, %40
  %indvars.iv = phi i64 [ 0, %24 ], [ %indvars.iv.next, %40 ]
  %34 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load ptr, ptr %6, align 8, !tbaa !10
  %37 = tail call i64 @fread(ptr noundef %35, i64 noundef %30, i64 noundef 1, ptr noundef %36)
  %38 = and i64 %37, 4294967295
  %.not39 = icmp eq i64 %38, 1
  br i1 %.not39, label %40, label %39

39:                                               ; preds = %33
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 133, ptr noundef nonnull @__FUNCTION__.mMORNRead, ptr noundef nonnull @.str.8) #4
  br label %40

40:                                               ; preds = %39, %33
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %31, label %33, !llvm.loop !15

41:                                               ; preds = %5, %31
  %.0 = phi i32 [ %32, %31 ], [ -1, %5 ]
  ret i32 %.0
}

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

attributes #0 = { 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 #1 = { "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 }

!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 4}
!6 = !{!"Chunk", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"HandleMORNFile", !12, i64 0, !12, i64 8, !7, i64 16}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!12, !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass