; LLVM IR from likle/cwalk :: src (cwalk)

; 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.cwk_segment = type { ptr, ptr, ptr, ptr, i64 }

@separators = external hidden global [2 x ptr], align 16

; 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 uwtable
declare hidden void @cwk_path_get_root_windows(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cwk_path_get_last_segment(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @cwk_path_guess_style(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca %struct.cwk_segment, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  call void @cwk_path_get_root_windows(ptr noundef %8, ptr noundef %5)
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp ugt i64 %9, 1
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %70

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %13, ptr %4, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %38, %12
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %41

18:                                               ; preds = %14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  %22 = load ptr, ptr getelementptr inbounds ([2 x ptr], ptr @separators, i64 0, i64 1), align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %21, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %70

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = sext i8 %29 to i32
  %31 = load ptr, ptr @separators, align 16, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %30, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %70

36:                                               ; preds = %27
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i32 1
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %14, !llvm.loop !12

41:                                               ; preds = %14
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call zeroext i1 @cwk_path_get_last_segment(ptr noundef %42, ptr noundef %6)
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %70

45:                                               ; preds = %41
  %46 = getelementptr inbounds %struct.cwk_segment, ptr %6, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 46
  br i1 %50, label %51, label %52

51:                                               ; preds = %45
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %70

52:                                               ; preds = %45
  %53 = getelementptr inbounds %struct.cwk_segment, ptr %6, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  store ptr %54, ptr %4, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %66, %52
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = icmp ne i8 %57, 0
  br i1 %58, label %59, label %69

59:                                               ; preds = %55
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = icmp eq i32 %62, 46
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %70

65:                                               ; preds = %59
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i32 1
  store ptr %68, ptr %4, align 8, !tbaa !5
  br label %55, !llvm.loop !16

69:                                               ; preds = %55
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %70

70:                                               ; preds = %69, %64, %51, %44, %35, %26, %11
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %71 = load i32, ptr %2, align 4
  ret i32 %71
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 16}
!15 = !{!"cwk_segment", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!16 = distinct !{!16, !13}


; 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.cwk_segment = type { ptr, ptr, ptr, ptr, i64 }

@separators = external hidden local_unnamed_addr global [2 x ptr], align 16

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

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

; Function Attrs: nounwind uwtable
declare hidden void @cwk_path_get_root_windows(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cwk_path_get_last_segment(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @cwk_path_guess_style(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  %3 = alloca %struct.cwk_segment, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #2
  call void @cwk_path_get_root_windows(ptr noundef %0, ptr noundef nonnull %2)
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = icmp ugt i64 %4, 1
  br i1 %5, label %.loopexit16, label %.preheader15

.preheader15:                                     ; preds = %1
  %6 = load i8, ptr %0, align 1, !tbaa !9
  %.not17 = icmp eq i8 %6, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader15
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @separators, i64 8), align 8, !tbaa !10
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = load ptr, ptr @separators, align 16
  br label %13

10:                                               ; preds = %16
  %11 = getelementptr inbounds i8, ptr %.018, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %.not = icmp eq i8 %12, 0
  br i1 %.not, label %._crit_edge, label %13, !llvm.loop !12

13:                                               ; preds = %.lr.ph, %10
  %14 = phi i8 [ %6, %.lr.ph ], [ %12, %10 ]
  %.018 = phi ptr [ %0, %.lr.ph ], [ %11, %10 ]
  %15 = icmp eq i8 %14, %8
  br i1 %15, label %.loopexit16, label %16

16:                                               ; preds = %13
  %17 = load i8, ptr %9, align 1, !tbaa !9
  %18 = icmp eq i8 %14, %17
  br i1 %18, label %.loopexit16, label %10

._crit_edge:                                      ; preds = %10, %.preheader15
  %19 = call zeroext i1 @cwk_path_get_last_segment(ptr noundef nonnull %0, ptr noundef nonnull %3)
  br i1 %19, label %20, label %.loopexit16

20:                                               ; preds = %._crit_edge
  %21 = getelementptr inbounds i8, ptr %3, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = icmp eq i8 %23, 46
  br i1 %24, label %.loopexit16, label %.preheader

.preheader:                                       ; preds = %20, %26
  %25 = phi i8 [ %.pr, %26 ], [ %23, %20 ]
  %.1 = phi ptr [ %27, %26 ], [ %22, %20 ]
  switch i8 %25, label %26 [
    i8 0, label %.loopexit16
    i8 46, label %.loopexit16.loopexit23
  ]

26:                                               ; preds = %.preheader
  %27 = getelementptr inbounds i8, ptr %.1, i64 1
  %.pr = load i8, ptr %27, align 1, !tbaa !9
  br label %.preheader, !llvm.loop !16

.loopexit16.loopexit23:                           ; preds = %.preheader
  br label %.loopexit16

.loopexit16:                                      ; preds = %16, %13, %.preheader, %.loopexit16.loopexit23, %20, %._crit_edge, %1
  %.010 = phi i32 [ 0, %1 ], [ 1, %._crit_edge ], [ 1, %20 ], [ 0, %.loopexit16.loopexit23 ], [ 1, %.preheader ], [ 0, %16 ], [ 1, %13 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #2
  ret i32 %.010
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !11, i64 16}
!15 = !{!"cwk_segment", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!16 = distinct !{!16, !13}


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