; LLVM IR from JessonYue/LeetCodeLearning :: BaseDataStructure/elf (soparse)

; 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.DataOffest = type { i32, i16, i32, i16, i32, i32, i32, i32, i32, i32, i32, i32, i16, i32, i32 }

@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [10 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

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

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

declare i32 @printf(ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @parseStrSection(ptr noundef %0, ptr noundef byval(%struct.DataOffest) align 8 %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %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 i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %2, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  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 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 1, ptr %9, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %20

15:                                               ; preds = %3
  %16 = getelementptr inbounds %struct.DataOffest, ptr %1, i32 0, i32 7
  %17 = load i32, ptr %16, align 4, !tbaa !11
  store i32 %17, ptr %12, align 4, !tbaa !9
  %18 = getelementptr inbounds %struct.DataOffest, ptr %1, i32 0, i32 6
  %19 = load i32, ptr %18, align 8, !tbaa !14
  store i32 %19, ptr %10, align 4, !tbaa !9
  br label %34

20:                                               ; preds = %3
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 2
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = getelementptr inbounds %struct.DataOffest, ptr %1, i32 0, i32 9
  %25 = load i32, ptr %24, align 4, !tbaa !15
  store i32 %25, ptr %12, align 4, !tbaa !9
  %26 = getelementptr inbounds %struct.DataOffest, ptr %1, i32 0, i32 8
  %27 = load i32, ptr %26, align 8, !tbaa !16
  store i32 %27, ptr %10, align 4, !tbaa !9
  br label %33

28:                                               ; preds = %20
  %29 = getelementptr inbounds %struct.DataOffest, ptr %1, i32 0, i32 11
  %30 = load i32, ptr %29, align 4, !tbaa !17
  store i32 %30, ptr %12, align 4, !tbaa !9
  %31 = getelementptr inbounds %struct.DataOffest, ptr %1, i32 0, i32 10
  %32 = load i32, ptr %31, align 8, !tbaa !18
  store i32 %32, ptr %10, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %28, %23
  br label %34

34:                                               ; preds = %33, %15
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.45, i32 noundef %35)
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.46, i32 noundef %37)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %79, %34
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = icmp ult i32 %40, %41
  br i1 %42, label %43, label %82

43:                                               ; preds = %39
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = mul nsw i32 %45, 1
  %47 = add i32 %44, %46
  store i32 %47, ptr %11, align 4, !tbaa !9
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = call i32 @fseek(ptr noundef %48, i64 noundef %50, i32 noundef 0)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call i64 @fread(ptr noundef %8, i64 noundef 1, i64 noundef 1, ptr noundef %52)
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %43
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  br label %79

60:                                               ; preds = %56, %43
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %66

63:                                               ; preds = %60
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.47, i32 noundef %64)
  br label %77

66:                                               ; preds = %60
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %76

69:                                               ; preds = %66
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %69
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %9, align 4, !tbaa !9
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.48, i32 noundef %74)
  br label %76

76:                                               ; preds = %72, %69, %66
  br label %77

77:                                               ; preds = %76, %63
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78, %59
  %80 = load i32, ptr %7, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %7, align 4, !tbaa !9
  br label %39, !llvm.loop !19

82:                                               ; preds = %39
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, 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
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 28}
!12 = !{!"DataOffest", !10, i64 0, !13, i64 4, !10, i64 8, !13, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !13, i64 48, !10, i64 52, !10, i64 56}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !10, i64 36}
!16 = !{!12, !10, i64 32}
!17 = !{!12, !10, i64 44}
!18 = !{!12, !10, i64 40}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%struct.DataOffest = type { i32, i16, i32, i16, i32, i32, i32, i32, i32, i32, i32, i32, i16, i32, i32 }

@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [10 x i8], align 1

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @parseStrSection(ptr nocapture noundef %0, ptr nocapture noundef readonly byval(%struct.DataOffest) align 8 %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  switch i32 %2, label %6 [
    i32 1, label %7
    i32 2, label %5
  ]

5:                                                ; preds = %3
  br label %7

6:                                                ; preds = %3
  br label %7

7:                                                ; preds = %3, %5, %6
  %.sink29 = phi i64 [ 36, %5 ], [ 44, %6 ], [ 28, %3 ]
  %.sink = phi i64 [ 32, %5 ], [ 40, %6 ], [ 24, %3 ]
  %8 = getelementptr inbounds i8, ptr %1, i64 %.sink29
  %9 = getelementptr inbounds i8, ptr %1, i64 %.sink
  %.0 = load i32, ptr %8, align 4, !tbaa !5
  %.018 = load i32, ptr %9, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.45, i32 noundef %.018)
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.46, i32 noundef %2)
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %wide.trip.count = zext i32 %.0 to i64
  %12 = zext i32 %.018 to i64
  %13 = tail call i32 @fseek(ptr noundef %0, i64 noundef %12, i32 noundef 0)
  %14 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 1, i64 noundef 1, ptr noundef %0)
  %15 = load i32, ptr %4, align 4
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %19, label %17

17:                                               ; preds = %.lr.ph.preheader
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.47, i32 noundef %15)
  br label %19

19:                                               ; preds = %17, %.lr.ph.preheader
  %exitcond.peel.not = icmp eq i32 %.0, 1
  br i1 %exitcond.peel.not, label %._crit_edge, label %.lr.ph.peel.next

.lr.ph.peel.next:                                 ; preds = %19, %32
  %indvars.iv = phi i64 [ %indvars.iv.next, %32 ], [ 1, %19 ]
  %.01923 = phi i32 [ %.1, %32 ], [ 1, %19 ]
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  %21 = add i32 %.018, %20
  %22 = zext i32 %21 to i64
  %23 = tail call i32 @fseek(ptr noundef %0, i64 noundef %22, i32 noundef 0)
  %24 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 1, i64 noundef 1, ptr noundef %0)
  %25 = load i32, ptr %4, align 4
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %29, label %27

27:                                               ; preds = %.lr.ph.peel.next
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.47, i32 noundef %25)
  br label %32

29:                                               ; preds = %.lr.ph.peel.next
  %30 = add nsw i32 %.01923, 1
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.48, i32 noundef %30)
  br label %32

32:                                               ; preds = %29, %27
  %.1 = phi i32 [ %.01923, %27 ], [ %30, %29 ]
  %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 %._crit_edge, label %.lr.ph.peel.next, !llvm.loop !9

._crit_edge:                                      ; preds = %32, %19, %7
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass