; LLVM IR from ihucos/plash :: mount (prepare_lowerdir)

; 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 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@constinit = external hidden constant [3 x ptr], align 8
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @prepare_lowerdir(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [3 x ptr], align 8
  %6 = alloca ptr, align 8
  %7 = alloca [4 x ptr], align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store ptr @.str, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 @constinit, i64 24, i1 false), !tbaa.struct !9
  %11 = getelementptr inbounds [3 x ptr], ptr %5, i64 0, i64 0
  %12 = call ptr @pl_check_output(ptr noundef %11)
  %13 = call ptr @pl_firstline(ptr noundef %12)
  store ptr %13, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store ptr @.str.1, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds ptr, ptr %7, i64 1
  store ptr @.str.3, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds ptr, ptr %7, i64 2
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %16, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds ptr, ptr %7, i64 3
  store ptr null, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds [4 x ptr], ptr %7, i64 0, i64 0
  %19 = call ptr @pl_check_output(ptr noundef %18)
  %20 = call ptr @pl_firstline(ptr noundef %19)
  store ptr %20, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i64 @strlen(ptr noundef %21) #7
  %23 = add i64 %22, 7
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr %8, align 4, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i64 @strlen(ptr noundef %25) #7
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %30, label %32

30:                                               ; preds = %1
  %31 = call i32 (ptr, ...) @pl_fatal(ptr noundef @.str.4)
  br label %32

32:                                               ; preds = %30, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  store ptr %36, ptr %10, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %49, %32
  %38 = call ptr @strsep(ptr noundef %10, ptr noundef @.str.5) #6
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %52

40:                                               ; preds = %37
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %3, ptr noundef @.str.6, ptr noundef %41, ptr noundef %42, ptr noundef %43) #6
  %45 = icmp ne i32 %44, -1
  br i1 %45, label %49, label %46

46:                                               ; preds = %40
  %47 = call i32 (ptr, ...) @pl_fatal(ptr noundef @.str.7)
  %48 = icmp ne i32 %47, 0
  br label %49

49:                                               ; preds = %46, %40
  %50 = phi i1 [ true, %40 ], [ %48, %46 ]
  %51 = zext i1 %50 to i32
  br label %37, !llvm.loop !13

52:                                               ; preds = %37
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = call i64 @strlen(ptr noundef %54) #7
  %56 = sub i64 %55, 1
  %57 = getelementptr inbounds i8, ptr %53, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !10
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret ptr %58
}

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

declare ptr @pl_firstline(ptr noundef) #2

declare ptr @pl_check_output(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

declare i32 @pl_fatal(ptr noundef, ...) #2

; Function Attrs: nounwind
declare ptr @strsep(ptr noundef, ptr noundef) #5

; Function Attrs: nounwind
declare i32 @asprintf(ptr noundef, ptr noundef, ...) #5

; 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 "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 = !{i64 0, i64 24, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!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"

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@constinit = external hidden local_unnamed_addr constant [3 x ptr], align 8
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @prepare_lowerdir(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [3 x ptr], align 8
  %4 = alloca [4 x ptr], align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store ptr @.str, ptr %2, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) @constinit, i64 24, i1 false), !tbaa.struct !9
  %6 = call ptr @pl_check_output(ptr noundef nonnull %3) #6
  %7 = call ptr @pl_firstline(ptr noundef %6) #6
  store ptr @.str.1, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr @.str.3, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %0, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr null, ptr %10, align 8, !tbaa !5
  %11 = call ptr @pl_check_output(ptr noundef nonnull %4) #6
  %12 = call ptr @pl_firstline(ptr noundef %11) #6
  %13 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %7) #7
  %14 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %12) #7
  %15 = shl i64 %13, 32
  %sext = add i64 %15, 30064771072
  %16 = ashr exact i64 %sext, 32
  %17 = icmp ult i64 %14, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %1
  %19 = call i32 (ptr, ...) @pl_fatal(ptr noundef nonnull @.str.4) #6
  br label %20

20:                                               ; preds = %18, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  %21 = getelementptr inbounds i8, ptr %12, i64 %16
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = call ptr @strsep(ptr noundef nonnull %5, ptr noundef nonnull @.str.5) #6
  %.not8 = icmp eq ptr %22, null
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %20, %28
  %23 = phi ptr [ %29, %28 ], [ %22, %20 ]
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %2, ptr noundef nonnull @.str.6, ptr noundef %7, ptr noundef nonnull %23, ptr noundef %24) #6
  %.not7 = icmp eq i32 %25, -1
  br i1 %.not7, label %26, label %28

26:                                               ; preds = %.lr.ph
  %27 = call i32 (ptr, ...) @pl_fatal(ptr noundef nonnull @.str.7) #6
  br label %28

28:                                               ; preds = %26, %.lr.ph
  %29 = call ptr @strsep(ptr noundef nonnull %5, ptr noundef nonnull @.str.5) #6
  %.not = icmp eq ptr %29, null
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %28
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %20
  %30 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ @.str, %20 ]
  %31 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %30) #7
  %32 = getelementptr i8, ptr %30, i64 %31
  %33 = getelementptr i8, ptr %32, i64 -1
  store i8 0, ptr %33, align 1, !tbaa !10
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  ret ptr %34
}

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

declare ptr @pl_firstline(ptr noundef) local_unnamed_addr #2

declare ptr @pl_check_output(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

declare i32 @pl_fatal(ptr noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @strsep(ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind
declare i32 @asprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #5

; 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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{i64 0, i64 24, !10}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass