; LLVM IR from likle/cwalk :: test (normalize_test)

; 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.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [22 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 void @cwk_path_set_style(i32 noundef) #1

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; 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 i32 @normalize_terminated() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca [4096 x i8], align 16
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4096, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  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 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @cwk_path_set_style(i32 noundef 1)
  store ptr @.str.12, ptr %4, align 8, !tbaa !5
  store ptr @.str.8, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call i64 @strlen(ptr noundef %10) #6
  store i64 %11, ptr %7, align 8, !tbaa !9
  %12 = getelementptr inbounds [4096 x i8], ptr %3, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 1, i64 4096, i1 false)
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %54, %0
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ult i64 %14, 7
  br i1 %15, label %16, label %57

16:                                               ; preds = %13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds [4096 x i8], ptr %3, i64 0, i64 0
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = call i64 @cwk_path_normalize(ptr noundef %17, ptr noundef %18, i64 noundef %19)
  store i64 %20, ptr %2, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %16
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %28, ptr %8, align 8, !tbaa !9
  br label %32

29:                                               ; preds = %23, %16
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = sub i64 %30, 1
  store i64 %31, ptr %8, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %29, %27
  %33 = load i64, ptr %2, align 8, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call i64 @strlen(ptr noundef %34) #6
  %36 = icmp ne i64 %33, %35
  br i1 %36, label %52, label %37

37:                                               ; preds = %32
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = icmp ugt i64 %38, 0
  br i1 %39, label %40, label %53

40:                                               ; preds = %37
  %41 = getelementptr inbounds [4096 x i8], ptr %3, i64 0, i64 0
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = call i32 @strncmp(ptr noundef %41, ptr noundef %42, i64 noundef %43) #6
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %52, label %46

46:                                               ; preds = %40
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds [4096 x i8], ptr %3, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %46, %40, %32
  store i32 1, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %58

53:                                               ; preds = %46, %37
  br label %54

54:                                               ; preds = %53
  %55 = load i64, ptr %6, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %6, align 8, !tbaa !9
  br label %13, !llvm.loop !12

57:                                               ; preds = %13
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %58

58:                                               ; preds = %57, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4096, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %59 = load i32, ptr %1, align 4
  ret i32 %59
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #2

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 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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [22 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

declare void @cwk_path_set_style(i32 noundef) local_unnamed_addr #1

declare i64 @cwk_path_normalize(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; 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
define dso_local range(i32 0, 2) i32 @normalize_terminated() local_unnamed_addr #3 {
  %1 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %1) #6
  tail call void @cwk_path_set_style(i32 noundef 1) #6
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.8) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4096) %1, i8 1, i64 4096, i1 false)
  %3 = call i64 @cwk_path_normalize(ptr noundef nonnull @.str.12, ptr noundef nonnull %1, i64 noundef 0) #6
  %.not19 = icmp eq i64 %3, %2
  br i1 %.not19, label %4, label %43

4:                                                ; preds = %0
  %5 = call i64 @cwk_path_normalize(ptr noundef nonnull @.str.12, ptr noundef nonnull %1, i64 noundef 1) #6
  %.not19.1 = icmp eq i64 %5, %2
  %6 = load i8, ptr %1, align 16
  %.not22.1 = icmp eq i8 %6, 0
  %or.cond = select i1 %.not19.1, i1 %.not22.1, i1 false
  br i1 %or.cond, label %7, label %43

7:                                                ; preds = %4
  %8 = call i64 @cwk_path_normalize(ptr noundef nonnull @.str.12, ptr noundef nonnull %1, i64 noundef 2) #6
  %9 = icmp ne i64 %2, 0
  %.0.2 = zext i1 %9 to i64
  %.not19.2 = icmp eq i64 %8, %2
  br i1 %.not19.2, label %10, label %43

10:                                               ; preds = %7
  %11 = call i32 @strncmp(ptr noundef nonnull %1, ptr noundef nonnull @.str.8, i64 noundef %.0.2) #7
  %.not21.2 = icmp eq i32 %11, 0
  br i1 %.not21.2, label %12, label %43

12:                                               ; preds = %10
  %13 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 %.0.2
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %.not22.2 = icmp eq i8 %14, 0
  br i1 %.not22.2, label %15, label %43

15:                                               ; preds = %12
  %16 = call i64 @cwk_path_normalize(ptr noundef nonnull @.str.12, ptr noundef nonnull %1, i64 noundef 3) #6
  %.0.3 = call i64 @llvm.umin.i64(i64 %2, i64 2)
  %.not19.3 = icmp eq i64 %16, %2
  br i1 %.not19.3, label %17, label %43

17:                                               ; preds = %15
  %18 = call i32 @strncmp(ptr noundef nonnull %1, ptr noundef nonnull @.str.8, i64 noundef %.0.3) #7
  %.not21.3 = icmp eq i32 %18, 0
  br i1 %.not21.3, label %19, label %43

19:                                               ; preds = %17
  %20 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 %.0.3
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %.not22.3 = icmp eq i8 %21, 0
  br i1 %.not22.3, label %22, label %43

22:                                               ; preds = %19
  %23 = call i64 @cwk_path_normalize(ptr noundef nonnull @.str.12, ptr noundef nonnull %1, i64 noundef 4) #6
  %.0.4 = call i64 @llvm.umin.i64(i64 %2, i64 3)
  %.not19.4 = icmp eq i64 %23, %2
  br i1 %.not19.4, label %24, label %43

24:                                               ; preds = %22
  %25 = call i32 @strncmp(ptr noundef nonnull %1, ptr noundef nonnull @.str.8, i64 noundef %.0.4) #7
  %.not21.4 = icmp eq i32 %25, 0
  br i1 %.not21.4, label %26, label %43

26:                                               ; preds = %24
  %27 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 %.0.4
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %.not22.4 = icmp eq i8 %28, 0
  br i1 %.not22.4, label %29, label %43

29:                                               ; preds = %26
  %30 = call i64 @cwk_path_normalize(ptr noundef nonnull @.str.12, ptr noundef nonnull %1, i64 noundef 5) #6
  %.0.5 = call i64 @llvm.umin.i64(i64 %2, i64 4)
  %.not19.5 = icmp eq i64 %30, %2
  br i1 %.not19.5, label %31, label %43

31:                                               ; preds = %29
  %32 = call i32 @strncmp(ptr noundef nonnull %1, ptr noundef nonnull @.str.8, i64 noundef %.0.5) #7
  %.not21.5 = icmp eq i32 %32, 0
  br i1 %.not21.5, label %33, label %43

33:                                               ; preds = %31
  %34 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 %.0.5
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %.not22.5 = icmp eq i8 %35, 0
  br i1 %.not22.5, label %36, label %43

36:                                               ; preds = %33
  %37 = call i64 @cwk_path_normalize(ptr noundef nonnull @.str.12, ptr noundef nonnull %1, i64 noundef 6) #6
  %.0.6 = call i64 @llvm.umin.i64(i64 %2, i64 5)
  %.not19.6 = icmp eq i64 %37, %2
  br i1 %.not19.6, label %38, label %43

38:                                               ; preds = %36
  %39 = call i32 @strncmp(ptr noundef nonnull %1, ptr noundef nonnull @.str.8, i64 noundef %.0.6) #7
  %.not21.6 = icmp eq i32 %39, 0
  br i1 %.not21.6, label %40, label %43

40:                                               ; preds = %38
  %41 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 %.0.6
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %.not22.6 = icmp ne i8 %42, 0
  %spec.select = zext i1 %.not22.6 to i32
  br label %43

43:                                               ; preds = %40, %38, %36, %33, %31, %29, %26, %24, %22, %19, %17, %15, %12, %10, %7, %4, %0
  %.016 = phi i32 [ 1, %0 ], [ 1, %4 ], [ 1, %7 ], [ 1, %10 ], [ 1, %12 ], [ 1, %15 ], [ 1, %17 ], [ 1, %19 ], [ 1, %22 ], [ 1, %24 ], [ 1, %26 ], [ 1, %29 ], [ 1, %31 ], [ 1, %33 ], [ 1, %36 ], [ 1, %38 ], [ %spec.select, %40 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %1) #6
  ret i32 %.016
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #5

attributes #0 = { mustprogress 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 = { 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 #3 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass