; 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"

@path_style = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @cwk_path_get_absolute(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca [4 x ptr], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call zeroext i1 @cwk_path_is_absolute(ptr noundef %11)
  br i1 %12, label %13, label %14

13:                                               ; preds = %4
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %22

14:                                               ; preds = %4
  %15 = load i32, ptr @path_style, align 4, !tbaa !11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 0
  store ptr @.str, ptr %18, align 16, !tbaa !5
  store i64 1, ptr %9, align 8, !tbaa !9
  br label %21

19:                                               ; preds = %14
  %20 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 0
  store ptr @.str.1, ptr %20, align 16, !tbaa !5
  store i64 1, ptr %9, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %19, %17
  br label %22

22:                                               ; preds = %21, %13
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call zeroext i1 @cwk_path_is_absolute(ptr noundef %23)
  br i1 %24, label %25, label %32

25:                                               ; preds = %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = add i64 %27, 1
  store i64 %28, ptr %9, align 8, !tbaa !9
  %29 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 %27
  store ptr %26, ptr %29, align 8, !tbaa !5
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 %30
  store ptr null, ptr %31, align 8, !tbaa !5
  br label %43

32:                                               ; preds = %22
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = add i64 %34, 1
  store i64 %35, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 %34
  store ptr %33, ptr %36, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %9, align 8, !tbaa !9
  %40 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 %38
  store ptr %37, ptr %40, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 %41
  store ptr null, ptr %42, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %32, %25
  %44 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 0
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = call i64 @cwk_path_join_and_normalize_multiple(ptr noundef %44, ptr noundef %45, i64 noundef %46)
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i64 %47
}

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cwk_path_is_absolute(ptr noundef) #0

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

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

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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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"

@path_style = external hidden 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 [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @cwk_path_get_absolute(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [4 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #2
  %6 = tail call zeroext i1 @cwk_path_is_absolute(ptr noundef %0)
  %.0.sroa.gep = getelementptr inbounds i8, ptr %5, i64 8
  br i1 %6, label %12, label %7

7:                                                ; preds = %4
  %8 = load i32, ptr @path_style, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  store ptr @.str, ptr %5, align 16, !tbaa !9
  br label %12

11:                                               ; preds = %7
  store ptr @.str.1, ptr %5, align 16, !tbaa !9
  br label %12

12:                                               ; preds = %4, %10, %11
  %.0.sroa.phi = phi ptr [ %.0.sroa.gep, %10 ], [ %.0.sroa.gep, %11 ], [ %5, %4 ]
  %.0 = phi i64 [ 1, %10 ], [ 1, %11 ], [ 0, %4 ]
  %13 = tail call zeroext i1 @cwk_path_is_absolute(ptr noundef %1)
  %14 = add nuw nsw i64 %.0, 1
  br i1 %13, label %18, label %15

15:                                               ; preds = %12
  store ptr %0, ptr %.0.sroa.phi, align 8, !tbaa !9
  %16 = or disjoint i64 %.0, 2
  %17 = getelementptr inbounds [4 x ptr], ptr %5, i64 0, i64 %14
  br label %18

18:                                               ; preds = %12, %15
  %.sink = phi ptr [ %17, %15 ], [ %.0.sroa.phi, %12 ]
  %.sink17 = phi i64 [ %16, %15 ], [ %14, %12 ]
  store ptr %1, ptr %.sink, align 8, !tbaa !9
  %19 = getelementptr inbounds [4 x ptr], ptr %5, i64 0, i64 %.sink17
  store ptr null, ptr %19, align 8, !tbaa !9
  %20 = call i64 @cwk_path_join_and_normalize_multiple(ptr noundef nonnull %5, ptr noundef %2, i64 noundef %3)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #2
  ret i64 %20
}

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cwk_path_is_absolute(ptr noundef) local_unnamed_addr #0

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

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

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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass