; LLVM IR from ctlst-tech/catpilot :: os/fatfs/core (ff)

; 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.DIR = type { %struct.FFOBJID, i32, i32, i32, ptr, [12 x i8], i32, ptr }
%struct.FFOBJID = type { ptr, i16, i8, i8, i32, i32, i32 }
%struct.FATFS = type { i8, i8, i8, i8, i8, i8, i16, i16, i16, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [512 x i8] }

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

; Function Attrs: nounwind uwtable
declare hidden i32 @mount_volume(ptr noundef, ptr noundef, i8 noundef zeroext) #1

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

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

declare ptr @ff_memalloc(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @follow_path(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @ld_clust(ptr noundef, ptr noundef) #1

declare void @ff_memfree(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @f_chdir(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.DIR, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 72, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = call i32 @mount_volume(ptr noundef %3, ptr noundef %6, i8 noundef zeroext 0)
  store i32 %9, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %65

12:                                               ; preds = %1
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 0
  %15 = getelementptr inbounds %struct.FFOBJID, ptr %14, i32 0, i32 0
  store ptr %13, ptr %15, align 8, !tbaa !11
  %16 = call ptr @ff_memalloc(i32 noundef 512)
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %21, label %19

19:                                               ; preds = %12
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  call void @unlock_volume(ptr noundef %20, i32 noundef 17)
  store i32 17, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %69

21:                                               ; preds = %12
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.FATFS, ptr %23, i32 0, i32 9
  store ptr %22, ptr %24, align 8, !tbaa !15
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call i32 @follow_path(ptr noundef %5, ptr noundef %25)
  store i32 %26, ptr %4, align 4, !tbaa !9
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %59

29:                                               ; preds = %21
  %30 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 5
  %31 = getelementptr inbounds [12 x i8], ptr %30, i64 0, i64 11
  %32 = load i8, ptr %31, align 1, !tbaa !17
  %33 = zext i8 %32 to i32
  %34 = and i32 %33, 128
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %42

36:                                               ; preds = %29
  %37 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 0
  %38 = getelementptr inbounds %struct.FFOBJID, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.FATFS, ptr %40, i32 0, i32 12
  store i32 %39, ptr %41, align 8, !tbaa !19
  br label %58

42:                                               ; preds = %29
  %43 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 0
  %44 = getelementptr inbounds %struct.FFOBJID, ptr %43, i32 0, i32 2
  %45 = load i8, ptr %44, align 2, !tbaa !20
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 16
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %56

49:                                               ; preds = %42
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = call i32 @ld_clust(ptr noundef %50, ptr noundef %52)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.FATFS, ptr %54, i32 0, i32 12
  store i32 %53, ptr %55, align 8, !tbaa !19
  br label %57

56:                                               ; preds = %42
  store i32 5, ptr %4, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %56, %49
  br label %58

58:                                               ; preds = %57, %36
  br label %59

59:                                               ; preds = %58, %21
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ff_memfree(ptr noundef %60)
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = icmp eq i32 %61, 4
  br i1 %62, label %63, label %64

63:                                               ; preds = %59
  store i32 5, ptr %4, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %63, %59
  br label %65

65:                                               ; preds = %64, %1
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !9
  call void @unlock_volume(ptr noundef %66, i32 noundef %67)
  %68 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %68, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %69

69:                                               ; preds = %65, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %70 = load i32, ptr %2, align 4
  ret i32 %70
}

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 = { "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 }

!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, !6, i64 0}
!12 = !{!"", !13, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !7, i64 48, !10, i64 60, !6, i64 64}
!13 = !{!"", !6, i64 0, !14, i64 8, !7, i64 10, !7, i64 11, !10, i64 12, !10, i64 16, !10, i64 20}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !6, i64 16}
!16 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !14, i64 6, !14, i64 8, !14, i64 10, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !7, i64 64}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !10, i64 12}
!19 = !{!16, !10, i64 32}
!20 = !{!12, !7, i64 10}
!21 = !{!12, !6, i64 40}


; 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.DIR = type { %struct.FFOBJID, i32, i32, i32, ptr, [12 x i8], i32, ptr }
%struct.FFOBJID = type { ptr, i16, i8, i8, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
declare hidden i32 @mount_volume(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

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

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

declare ptr @ff_memalloc(i32 noundef) local_unnamed_addr #2

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

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

declare void @ff_memfree(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @f_chdir(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.DIR, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = call i32 @mount_volume(ptr noundef nonnull %2, ptr noundef nonnull %4, i8 noundef zeroext 0)
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %35

7:                                                ; preds = %1
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %8, ptr %3, align 8, !tbaa !9
  %9 = call ptr @ff_memalloc(i32 noundef 512) #3
  %.not = icmp eq ptr %9, null
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  br i1 %.not, label %11, label %12

11:                                               ; preds = %7
  call void @unlock_volume(ptr noundef %10, i32 noundef 17)
  br label %37

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %9, ptr %13, align 8, !tbaa !14
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i32 @follow_path(ptr noundef nonnull %3, ptr noundef %14)
  %.fr = freeze i32 %15
  %16 = icmp eq i32 %.fr, 0
  br i1 %16, label %17, label %33

17:                                               ; preds = %12
  %18 = getelementptr inbounds i8, ptr %3, i64 59
  %19 = load i8, ptr %18, align 1, !tbaa !16
  %.not13 = icmp sgt i8 %19, -1
  br i1 %.not13, label %23, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %3, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !17
  br label %.thread.sink.split

23:                                               ; preds = %17
  %24 = getelementptr inbounds i8, ptr %3, i64 10
  %25 = load i8, ptr %24, align 2, !tbaa !18
  %26 = and i8 %25, 16
  %.not14 = icmp eq i8 %26, 0
  br i1 %.not14, label %.thread, label %27

27:                                               ; preds = %23
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %3, i64 40
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = call i32 @ld_clust(ptr noundef %28, ptr noundef %30)
  br label %.thread.sink.split

.thread.sink.split:                               ; preds = %27, %20
  %.sink = phi i32 [ %22, %20 ], [ %31, %27 ]
  %.sink18 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.sink18, i64 32
  store i32 %.sink, ptr %32, align 8, !tbaa !20
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %23
  %.08.ph = phi i32 [ 5, %23 ], [ 0, %.thread.sink.split ]
  call void @ff_memfree(ptr noundef nonnull %9) #3
  br label %35

33:                                               ; preds = %12
  call void @ff_memfree(ptr noundef nonnull %9) #3
  %34 = icmp eq i32 %.fr, 4
  %spec.select = select i1 %34, i32 5, i32 %.fr
  br label %35

35:                                               ; preds = %33, %.thread, %1
  %.1 = phi i32 [ %5, %1 ], [ %.08.ph, %.thread ], [ %spec.select, %33 ]
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  call void @unlock_volume(ptr noundef %36, i32 noundef %.1)
  br label %37

37:                                               ; preds = %35, %11
  %.0 = phi i32 [ %.1, %35 ], [ 17, %11 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #3
  ret i32 %.0
}

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 = { "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 }

!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, !6, i64 0}
!10 = !{!"", !11, i64 0, !13, i64 24, !13, i64 28, !13, i64 32, !6, i64 40, !7, i64 48, !13, i64 60, !6, i64 64}
!11 = !{!"", !6, i64 0, !12, i64 8, !7, i64 10, !7, i64 11, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !12, i64 6, !12, i64 8, !12, i64 10, !6, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !7, i64 64}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !13, i64 12}
!18 = !{!10, !7, i64 10}
!19 = !{!10, !6, i64 40}
!20 = !{!15, !13, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass