; LLVM IR from BoysTownOrg/chapro :: cha_core (cha_data_load)

; 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.36 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @cha_allocate(ptr noundef, i32 noundef, i32 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

; 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 hidden ptr @data_plan(ptr noundef, ptr noundef, ptr noundef) #0

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

declare i32 @fclose(ptr noundef) #2

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

21:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %16, align 4
  br label %126

22:                                               ; preds = %2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call noalias ptr @fopen(ptr noundef %23, ptr noundef @.str.36)
  store ptr %24, ptr %15, align 8, !tbaa !5
  %25 = load ptr, ptr %15, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i32 2, ptr %3, align 4
  store i32 1, ptr %16, align 4
  br label %126

28:                                               ; preds = %22
  store i32 4, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  %29 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 0
  store i32 349488, ptr %29, align 16, !tbaa !9
  %30 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 1
  store i32 426289, ptr %30, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 2
  store i32 %31, ptr %32, align 8, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 3
  store i32 %33, ptr %34, align 4, !tbaa !9
  %35 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = load ptr, ptr %15, align 8, !tbaa !5
  %39 = call i64 @fread(ptr noundef %35, i64 noundef %37, i64 noundef 4, ptr noundef %38)
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %56, %28
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = icmp slt i32 %42, 4
  br i1 %43, label %44, label %59

44:                                               ; preds = %41
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = icmp ne i32 %48, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %44
  br label %59

55:                                               ; preds = %44
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !9
  br label %41, !llvm.loop !11

59:                                               ; preds = %54, %41
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = icmp slt i32 %60, 4
  br i1 %61, label %62, label %65

62:                                               ; preds = %59
  %63 = load ptr, ptr %15, align 8, !tbaa !5
  %64 = call i32 @fclose(ptr noundef %63)
  store i32 4, ptr %3, align 4
  store i32 1, ptr %16, align 4
  br label %126

65:                                               ; preds = %59
  %66 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  %67 = load i32, ptr %66, align 8, !tbaa !9
  store i32 %67, ptr %6, align 4, !tbaa !9
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = mul nsw i32 64, %68
  store i32 %69, ptr %7, align 4, !tbaa !9
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = call ptr @cha_allocate(ptr noundef %70, i32 noundef 64, i32 noundef %71, i32 noundef 0)
  store ptr %72, ptr %13, align 8, !tbaa !5
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = load ptr, ptr %15, align 8, !tbaa !5
  %77 = call i64 @fread(ptr noundef %73, i64 noundef 64, i64 noundef %75, ptr noundef %76)
  %78 = trunc i64 %77 to i32
  store i32 %78, ptr %10, align 4, !tbaa !9
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = getelementptr inbounds i32, ptr %79, i64 0
  %81 = load i32, ptr %80, align 4, !tbaa !9
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = icmp ne i32 %81, %82
  br i1 %83, label %84, label %85

84:                                               ; preds = %65
  store i32 4, ptr %3, align 4
  store i32 1, ptr %16, align 4
  br label %126

85:                                               ; preds = %65
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %86

86:                                               ; preds = %119, %85
  %87 = load i32, ptr %9, align 4, !tbaa !9
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = icmp slt i32 %87, %88
  br i1 %89, label %90, label %122

90:                                               ; preds = %86
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = load i32, ptr %9, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i32, ptr %91, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !9
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %118

97:                                               ; preds = %90
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i32, ptr %98, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !9
  %103 = load i32, ptr %8, align 4, !tbaa !9
  %104 = udiv i32 %102, %103
  store i32 %104, ptr %7, align 4, !tbaa !9
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = load i32, ptr %7, align 4, !tbaa !9
  %107 = load i32, ptr %8, align 4, !tbaa !9
  %108 = load i32, ptr %9, align 4, !tbaa !9
  %109 = call ptr @cha_allocate(ptr noundef %105, i32 noundef %106, i32 noundef %107, i32 noundef %108)
  store ptr %109, ptr %14, align 8, !tbaa !5
  %110 = load ptr, ptr %14, align 8, !tbaa !5
  %111 = load i32, ptr %7, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = load i32, ptr %8, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = load ptr, ptr %15, align 8, !tbaa !5
  %116 = call i64 @fread(ptr noundef %110, i64 noundef %112, i64 noundef %114, ptr noundef %115)
  %117 = trunc i64 %116 to i32
  store i32 %117, ptr %10, align 4, !tbaa !9
  br label %118

118:                                              ; preds = %97, %90
  br label %119

119:                                              ; preds = %118
  %120 = load i32, ptr %9, align 4, !tbaa !9
  %121 = add nsw i32 %120, 1
  store i32 %121, ptr %9, align 4, !tbaa !9
  br label %86, !llvm.loop !13

122:                                              ; preds = %86
  %123 = load ptr, ptr %15, align 8, !tbaa !5
  %124 = call i32 @fclose(ptr noundef %123)
  %125 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %125, ptr %3, align 4
  store i32 1, ptr %16, align 4
  br label %126

126:                                              ; preds = %122, %84, %62, %27, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %127 = load i32, ptr %3, align 4
  ret i32 %127
}

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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.36 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @data_plan(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cha_data_load(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  %6 = call ptr @data_plan(ptr noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %47, label %9

9:                                                ; preds = %2
  %10 = call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.36)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %47, label %12

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = call i64 @fread(ptr noundef nonnull %5, i64 noundef 4, i64 noundef 4, ptr noundef nonnull %10)
  %16 = load <4 x i32>, ptr %5, align 16
  %17 = insertelement <4 x i32> <i32 349488, i32 426289, i32 poison, i32 poison>, i32 %13, i64 2
  %18 = insertelement <4 x i32> %17, i32 %14, i64 3
  %19 = icmp eq <4 x i32> %16, %18
  %20 = freeze <4 x i1> %19
  %21 = bitcast <4 x i1> %20 to i4
  %22 = icmp eq i4 %21, -1
  br i1 %22, label %.critedge, label %.sink.split

.critedge:                                        ; preds = %12
  store i32 %13, ptr %3, align 4, !tbaa !5
  store i32 256, ptr %4, align 4, !tbaa !5
  %23 = call ptr @cha_allocate(ptr noundef %0, i32 noundef 64, i32 noundef 4, i32 noundef 0)
  %24 = call i64 @fread(ptr noundef %23, i64 noundef 64, i64 noundef 4, ptr noundef nonnull %10)
  %25 = load i32, ptr %23, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %.not38 = icmp eq i32 %25, %26
  br i1 %.not38, label %27, label %47

27:                                               ; preds = %.critedge
  %28 = trunc i64 %24 to i32
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 1
  br i1 %30, label %.lr.ph, label %.sink.split

.lr.ph:                                           ; preds = %27, %42
  %31 = phi i32 [ %43, %42 ], [ %29, %27 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %42 ], [ 1, %27 ]
  %.03441 = phi i32 [ %.135, %42 ], [ %28, %27 ]
  %32 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %.not39 = icmp eq i32 %33, 0
  br i1 %.not39, label %42, label %34

34:                                               ; preds = %.lr.ph
  %35 = lshr i32 %33, 2
  store i32 %35, ptr %4, align 4, !tbaa !5
  %36 = trunc nuw nsw i64 %indvars.iv to i32
  %37 = call ptr @cha_allocate(ptr noundef %0, i32 noundef %35, i32 noundef 4, i32 noundef %36)
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = call i64 @fread(ptr noundef %37, i64 noundef %39, i64 noundef 4, ptr noundef nonnull %10)
  %41 = trunc i64 %40 to i32
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.lr.ph, %34
  %43 = phi i32 [ %.pre, %34 ], [ %31, %.lr.ph ]
  %.135 = phi i32 [ %41, %34 ], [ %.03441, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next, %44
  br i1 %45, label %.lr.ph, label %.sink.split, !llvm.loop !9

.sink.split:                                      ; preds = %42, %27, %12
  %.0.ph = phi i32 [ 4, %12 ], [ %28, %27 ], [ %.135, %42 ]
  %46 = call i32 @fclose(ptr noundef nonnull %10)
  br label %47

47:                                               ; preds = %.sink.split, %.critedge, %9, %2
  %.0 = phi i32 [ 1, %2 ], [ 2, %9 ], [ 4, %.critedge ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %.0
}

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass