; LLVM IR from ChaCheeChoo/GAAS-Engine :: GWDGenSource (main)

; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%struct.ToCblock = type { i32, i32, i32, i32 }
%struct.Path = type { [512 x i8] }
%struct.dirent = type { i64, i64, i16, i8, [256 x i8] }

@e = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@fileindex = external dso_local global ptr, align 8
@filepath = external dso_local global ptr, align 8

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

declare ptr @opendir(ptr noundef) #2

declare ptr @readdir(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @lstat(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #3

declare i32 @closedir(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @genindex(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.stat, align 8
  %8 = alloca [256 x i8], align 16
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 144, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 256, ptr %8) #5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call ptr @opendir(ptr noundef %10)
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %31

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call i32 @crc32(ptr noundef %14)
  %16 = load ptr, ptr @fileindex, align 8, !tbaa !5
  %17 = load i32, ptr @e, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.ToCblock, ptr %16, i64 %18
  %20 = getelementptr inbounds %struct.ToCblock, ptr %19, i32 0, i32 1
  store i32 %15, ptr %20, align 4, !tbaa !11
  %21 = load ptr, ptr @filepath, align 8, !tbaa !5
  %22 = load i32, ptr @e, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %struct.Path, ptr %21, i64 %23
  %25 = getelementptr inbounds %struct.Path, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [512 x i8], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call ptr @strcpy(ptr noundef %26, ptr noundef %27) #5
  %29 = load i32, ptr @e, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @e, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  br label %69

31:                                               ; preds = %2
  br label %32

32:                                               ; preds = %53, %52, %31
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call ptr @readdir(ptr noundef %33)
  store ptr %34, ptr %6, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %66

36:                                               ; preds = %32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.dirent, ptr %37, i32 0, i32 4
  %39 = getelementptr inbounds [256 x i8], ptr %38, i64 0, i64 0
  %40 = call i32 @lstat(ptr noundef %39, ptr noundef %7) #5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.dirent, ptr %41, i32 0, i32 4
  %43 = getelementptr inbounds [256 x i8], ptr %42, i64 0, i64 0
  %44 = call i32 @strcmp(ptr noundef @.str, ptr noundef %43) #6
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %52, label %46

46:                                               ; preds = %36
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.dirent, ptr %47, i32 0, i32 4
  %49 = getelementptr inbounds [256 x i8], ptr %48, i64 0, i64 0
  %50 = call i32 @strcmp(ptr noundef @.str.1, ptr noundef %49) #6
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %46, %36
  br label %32, !llvm.loop !13

53:                                               ; preds = %46
  %54 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = call ptr @strcpy(ptr noundef %54, ptr noundef %55) #5
  %57 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  %58 = call ptr @strcat(ptr noundef %57, ptr noundef @.str.2) #5
  %59 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.dirent, ptr %60, i32 0, i32 4
  %62 = getelementptr inbounds [256 x i8], ptr %61, i64 0, i64 0
  %63 = call ptr @strcat(ptr noundef %59, ptr noundef %62) #5
  %64 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  %65 = load i32, ptr %4, align 4, !tbaa !9
  call void @genindex(ptr noundef %64, i32 noundef %65)
  br label %32, !llvm.loop !13

66:                                               ; preds = %32
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = call i32 @closedir(ptr noundef %67)
  store i32 0, ptr %9, align 4
  br label %69

69:                                               ; preds = %66, %13
  call void @llvm.lifetime.end.p0(i64 256, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %70 = load i32, ptr %9, align 4
  switch i32 %70, label %72 [
    i32 0, label %71
    i32 1, label %71
  ]

71:                                               ; preds = %69, %69
  ret void

72:                                               ; preds = %69
  unreachable
}

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 "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 willreturn memory(read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"ToCblock", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = distinct !{!13, !14}
!14 = !{!"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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%struct.ToCblock = type { i32, i32, i32, i32 }
%struct.Path = type { [512 x i8] }

@e = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@fileindex = external dso_local local_unnamed_addr global ptr, align 8
@filepath = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @crc32(ptr 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: nofree nounwind
declare noalias noundef ptr @opendir(ptr nocapture noundef readonly) local_unnamed_addr #2

declare ptr @readdir(ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #5

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #5

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

; Function Attrs: nounwind uwtable
define dso_local void @genindex(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.stat, align 8
  %4 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #6
  %5 = tail call ptr @opendir(ptr noundef %0)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %8, label %.preheader

.preheader:                                       ; preds = %2
  %7 = tail call ptr @readdir(ptr noundef nonnull %5) #6
  %.not10 = icmp eq ptr %7, null
  br i1 %.not10, label %._crit_edge, label %.lr.ph

8:                                                ; preds = %2
  %9 = tail call i32 @crc32(ptr noundef %0)
  %10 = load ptr, ptr @fileindex, align 8, !tbaa !5
  %11 = load i32, ptr @e, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds %struct.ToCblock, ptr %10, i64 %12, i32 1
  store i32 %9, ptr %13, align 4, !tbaa !11
  %14 = load ptr, ptr @filepath, align 8, !tbaa !5
  %15 = load i32, ptr @e, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %struct.Path, ptr %14, i64 %16
  %18 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %17, ptr noundef nonnull dereferenceable(1) %0) #6
  %19 = load i32, ptr @e, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @e, align 4, !tbaa !9
  br label %35

.lr.ph:                                           ; preds = %.preheader, %.backedge
  %21 = phi ptr [ %29, %.backedge ], [ %7, %.preheader ]
  %22 = getelementptr inbounds i8, ptr %21, i64 19
  %23 = call i32 @lstat(ptr noundef nonnull %22, ptr noundef nonnull %3) #6
  %24 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull dereferenceable(1) %22) #7
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %.backedge, label %26

26:                                               ; preds = %.lr.ph
  %27 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull dereferenceable(1) %22) #7
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %.backedge, label %30

.backedge:                                        ; preds = %.lr.ph, %26, %30
  %29 = call ptr @readdir(ptr noundef nonnull %5) #6
  %.not = icmp eq ptr %29, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

30:                                               ; preds = %26
  %31 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) %0) #6
  %32 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) @.str.2) #6
  %33 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) %22) #6
  call void @genindex(ptr noundef nonnull %4, i32 noundef %1)
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge, %.preheader
  %34 = call i32 @closedir(ptr noundef nonnull %5)
  br label %35

35:                                               ; preds = %._crit_edge, %8
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %3) #6
  ret void
}

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 = { "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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #5 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!"ToCblock", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass