; LLVM IR from IOsonata/IOsonata :: fatfs (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], ptr }
%struct.FFOBJID = type { ptr, i16, i8, i8, i32, i32 }
%struct.FATFS = type { i8, i8, i8, i8, i8, i16, i16, i16, 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: 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 i32 @follow_path(ptr noundef, ptr noundef) #1

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

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

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

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

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

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

11:                                               ; preds = %1
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %14 = getelementptr inbounds %struct.FFOBJID, ptr %13, i32 0, i32 0
  store ptr %12, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call i32 @follow_path(ptr noundef %4, ptr noundef %15)
  store i32 %16, ptr %3, align 4, !tbaa !9
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %27

19:                                               ; preds = %11
  %20 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 5
  %21 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 11
  %22 = load i8, ptr %21, align 1, !tbaa !15
  %23 = zext i8 %22 to i32
  %24 = and i32 %23, 32
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  store i32 6, ptr %3, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %26, %19, %11
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %113

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

37:                                               ; preds = %30
  store i32 6, ptr %3, align 4, !tbaa !9
  br label %47

38:                                               ; preds = %30
  %39 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %40 = getelementptr inbounds %struct.FFOBJID, ptr %39, i32 0, i32 2
  %41 = load i8, ptr %40, align 2, !tbaa !16
  %42 = zext i8 %41 to i32
  %43 = and i32 %42, 1
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %38
  store i32 7, ptr %3, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %45, %38
  br label %47

47:                                               ; preds = %46, %37
  %48 = load i32, ptr %3, align 4, !tbaa !9
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %91

50:                                               ; preds = %47
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = call i32 @ld_clust(ptr noundef %51, ptr noundef %53)
  store i32 %54, ptr %6, align 4, !tbaa !9
  %55 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %56 = getelementptr inbounds %struct.FFOBJID, ptr %55, i32 0, i32 2
  %57 = load i8, ptr %56, align 2, !tbaa !16
  %58 = zext i8 %57 to i32
  %59 = and i32 %58, 16
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %90

61:                                               ; preds = %50
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.FATFS, ptr %63, i32 0, i32 10
  %65 = load i32, ptr %64, align 4, !tbaa !18
  %66 = icmp eq i32 %62, %65
  br i1 %66, label %67, label %68

67:                                               ; preds = %61
  store i32 7, ptr %3, align 4, !tbaa !9
  br label %89

68:                                               ; preds = %61
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 0
  %71 = getelementptr inbounds %struct.FFOBJID, ptr %70, i32 0, i32 0
  store ptr %69, ptr %71, align 8, !tbaa !11
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 0
  %74 = getelementptr inbounds %struct.FFOBJID, ptr %73, i32 0, i32 4
  store i32 %72, ptr %74, align 4, !tbaa !20
  %75 = call i32 @dir_sdi(ptr noundef %5, i32 noundef 0)
  store i32 %75, ptr %3, align 4, !tbaa !9
  %76 = load i32, ptr %3, align 4, !tbaa !9
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %78, label %88

78:                                               ; preds = %68
  %79 = call i32 @dir_read(ptr noundef %5, i32 noundef 0)
  store i32 %79, ptr %3, align 4, !tbaa !9
  %80 = load i32, ptr %3, align 4, !tbaa !9
  %81 = icmp eq i32 %80, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %78
  store i32 7, ptr %3, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %82, %78
  %84 = load i32, ptr %3, align 4, !tbaa !9
  %85 = icmp eq i32 %84, 4
  br i1 %85, label %86, label %87

86:                                               ; preds = %83
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %86, %83
  br label %88

88:                                               ; preds = %87, %68
  br label %89

89:                                               ; preds = %88, %67
  br label %90

90:                                               ; preds = %89, %50
  br label %91

91:                                               ; preds = %90, %47
  %92 = load i32, ptr %3, align 4, !tbaa !9
  %93 = icmp eq i32 %92, 0
  br i1 %93, label %94, label %112

94:                                               ; preds = %91
  %95 = call i32 @dir_remove(ptr noundef %4)
  store i32 %95, ptr %3, align 4, !tbaa !9
  %96 = load i32, ptr %3, align 4, !tbaa !9
  %97 = icmp eq i32 %96, 0
  br i1 %97, label %98, label %105

98:                                               ; preds = %94
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = icmp ne i32 %99, 0
  br i1 %100, label %101, label %105

101:                                              ; preds = %98
  %102 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = call i32 @remove_chain(ptr noundef %102, i32 noundef %103, i32 noundef 0)
  store i32 %104, ptr %3, align 4, !tbaa !9
  br label %105

105:                                              ; preds = %101, %98, %94
  %106 = load i32, ptr %3, align 4, !tbaa !9
  %107 = icmp eq i32 %106, 0
  br i1 %107, label %108, label %111

108:                                              ; preds = %105
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = call i32 @sync_fs(ptr noundef %109)
  store i32 %110, ptr %3, align 4, !tbaa !9
  br label %111

111:                                              ; preds = %108, %105
  br label %112

112:                                              ; preds = %111, %91
  br label %113

113:                                              ; preds = %112, %27
  br label %114

114:                                              ; preds = %113, %1
  %115 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 72, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 72, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %115
}

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

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


; 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], ptr }
%struct.FFOBJID = type { ptr, i16, i8, i8, 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: 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 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

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

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

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

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

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

8:                                                ; preds = %1
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %9, ptr %3, align 8, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i32 @follow_path(ptr noundef nonnull %3, ptr noundef %10)
  %12 = icmp eq i32 %11, 0
  %13 = getelementptr inbounds i8, ptr %3, i64 59
  %14 = load i8, ptr %13, align 1
  %15 = and i8 %14, 32
  %.not = icmp eq i8 %15, 0
  %spec.select = select i1 %.not, i32 0, i32 6
  %.017 = select i1 %12, i32 %spec.select, i32 %11
  %16 = select i1 %12, i1 %.not, i1 false
  br i1 %16, label %17, label %.thread30

17:                                               ; preds = %8
  %.not24 = icmp sgt i8 %14, -1
  br i1 %.not24, label %18, label %.thread30

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %3, i64 10
  %20 = load i8, ptr %19, align 2, !tbaa !14
  %21 = and i8 %20, 1
  %.not25 = icmp eq i8 %21, 0
  br i1 %.not25, label %22, label %.thread30

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %3, i64 40
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = call i32 @ld_clust(ptr noundef %23, ptr noundef %25)
  %27 = load i8, ptr %19, align 2, !tbaa !14
  %28 = and i8 %27, 16
  %.not26 = icmp eq i8 %28, 0
  br i1 %.not26, label %.thread34, label %29

29:                                               ; preds = %22
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 20
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = icmp eq i32 %26, %32
  br i1 %33, label %.thread30, label %34

34:                                               ; preds = %29
  store ptr %30, ptr %4, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %4, i64 12
  store i32 %26, ptr %35, align 4, !tbaa !18
  %36 = call i32 @dir_sdi(ptr noundef nonnull %4, i32 noundef 0)
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %.thread30

38:                                               ; preds = %34
  %39 = call i32 @dir_read(ptr noundef nonnull %4, i32 noundef 0)
  %40 = icmp eq i32 %39, 0
  %spec.store.select = select i1 %40, i32 7, i32 %39
  %41 = icmp eq i32 %spec.store.select, 4
  br i1 %41, label %.thread34, label %.thread30

.thread34:                                        ; preds = %38, %22
  %42 = call i32 @dir_remove(ptr noundef nonnull %3)
  %43 = icmp eq i32 %42, 0
  %44 = icmp ne i32 %26, 0
  %or.cond = select i1 %43, i1 %44, i1 false
  br i1 %or.cond, label %45, label %47

45:                                               ; preds = %.thread34
  %46 = call i32 @remove_chain(ptr noundef nonnull %3, i32 noundef %26, i32 noundef 0)
  br label %47

47:                                               ; preds = %45, %.thread34
  %.3 = phi i32 [ %46, %45 ], [ %42, %.thread34 ]
  %48 = icmp eq i32 %.3, 0
  br i1 %48, label %49, label %.thread30

49:                                               ; preds = %47
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = call i32 @sync_fs(ptr noundef %50)
  br label %.thread30

.thread30:                                        ; preds = %18, %17, %29, %34, %38, %8, %47, %49, %1
  %.4 = phi i32 [ %51, %49 ], [ %.3, %47 ], [ %.017, %8 ], [ %6, %1 ], [ 7, %29 ], [ %36, %34 ], [ %spec.store.select, %38 ], [ 6, %17 ], [ 7, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #2
  ret i32 %.4
}

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

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


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