; LLVM IR from cvra/robot-software :: lib/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 { ptr, i16, i16, i64, i64, i64, ptr, ptr }

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

; 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 @find_volume(ptr noundef, ptr noundef, i8 noundef zeroext) #1

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @mem_cpy(ptr noundef, ptr 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 ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca [12 x i8], align 1
  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 56, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 56, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 12, ptr %8) #2
  %9 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %10 = call i32 @find_volume(ptr noundef %9, ptr noundef %2, i8 noundef zeroext 1)
  store i32 %10, ptr %3, align 4, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %97

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

20:                                               ; preds = %13
  %21 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  store ptr %22, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  store i32 6, ptr %3, align 4, !tbaa !9
  br label %35

26:                                               ; preds = %20
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 11
  %29 = load i8, ptr %28, align 1, !tbaa !16
  %30 = zext i8 %29 to i32
  %31 = and i32 %30, 1
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  store i32 7, ptr %3, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %33, %26
  br label %35

35:                                               ; preds = %34, %25
  %36 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call i64 @ld_clust(ptr noundef %37, ptr noundef %38)
  store i64 %39, ptr %7, align 8, !tbaa !18
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %71

42:                                               ; preds = %35
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 11
  %45 = load i8, ptr %44, align 1, !tbaa !16
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 16
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %71

49:                                               ; preds = %42
  %50 = load i64, ptr %7, align 8, !tbaa !18
  %51 = icmp ult i64 %50, 2
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  store i32 2, ptr %3, align 4, !tbaa !9
  br label %70

53:                                               ; preds = %49
  call void @mem_cpy(ptr noundef %5, ptr noundef %4, i32 noundef 56)
  %54 = load i64, ptr %7, align 8, !tbaa !18
  %55 = getelementptr inbounds %struct.DIR, ptr %5, i32 0, i32 3
  store i64 %54, ptr %55, align 8, !tbaa !19
  %56 = call i32 @dir_sdi(ptr noundef %5, i32 noundef 2)
  store i32 %56, ptr %3, align 4, !tbaa !9
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %69

59:                                               ; preds = %53
  %60 = call i32 @dir_read(ptr noundef %5, i32 noundef 0)
  store i32 %60, ptr %3, align 4, !tbaa !9
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %64

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

64:                                               ; preds = %63, %59
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = icmp eq i32 %65, 4
  br i1 %66, label %67, label %68

67:                                               ; preds = %64
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %67, %64
  br label %69

69:                                               ; preds = %68, %53
  br label %70

70:                                               ; preds = %69, %52
  br label %71

71:                                               ; preds = %70, %42, %35
  %72 = load i32, ptr %3, align 4, !tbaa !9
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %95

74:                                               ; preds = %71
  %75 = call i32 @dir_remove(ptr noundef %4)
  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 %94

78:                                               ; preds = %74
  %79 = load i64, ptr %7, align 8, !tbaa !18
  %80 = icmp ne i64 %79, 0
  br i1 %80, label %81, label %86

81:                                               ; preds = %78
  %82 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !17
  %84 = load i64, ptr %7, align 8, !tbaa !18
  %85 = call i32 @remove_chain(ptr noundef %83, i64 noundef %84)
  store i32 %85, ptr %3, align 4, !tbaa !9
  br label %86

86:                                               ; preds = %81, %78
  %87 = load i32, ptr %3, align 4, !tbaa !9
  %88 = icmp eq i32 %87, 0
  br i1 %88, label %89, label %93

89:                                               ; preds = %86
  %90 = getelementptr inbounds %struct.DIR, ptr %4, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !17
  %92 = call i32 @sync_fs(ptr noundef %91)
  store i32 %92, ptr %3, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %89, %86
  br label %94

94:                                               ; preds = %93, %74
  br label %95

95:                                               ; preds = %94, %71
  br label %96

96:                                               ; preds = %95, %13
  br label %97

97:                                               ; preds = %96, %1
  %98 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 12, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 56, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 56, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %98
}

; 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 48}
!12 = !{!"", !6, i64 0, !13, i64 8, !13, i64 10, !14, i64 16, !14, i64 24, !14, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 40}
!16 = !{!7, !7, i64 0}
!17 = !{!12, !6, i64 0}
!18 = !{!14, !14, i64 0}
!19 = !{!12, !14, i64 16}


; 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 { ptr, i16, i16, i64, i64, i64, ptr, ptr }

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

; 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 @find_volume(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @mem_cpy(ptr noundef, ptr 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 [12 x i8], align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %3) #2
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #2
  %6 = call i32 @find_volume(ptr noundef nonnull %3, ptr noundef nonnull %2, i8 noundef zeroext 1)
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %.thread32

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %3, i64 48
  store ptr %5, ptr %9, 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
  br i1 %12, label %13, label %.thread32

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %3, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %.thread, label %18

.thread:                                          ; preds = %13
  %16 = load ptr, ptr %3, align 8, !tbaa !14
  %17 = call i64 @ld_clust(ptr noundef %16, ptr noundef null)
  br label %.thread32

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %15, i64 11
  %20 = load i8, ptr %19, align 1, !tbaa !15
  %21 = and i8 %20, 1
  %.not27 = icmp eq i8 %21, 0
  %22 = load ptr, ptr %3, align 8, !tbaa !14
  %23 = call i64 @ld_clust(ptr noundef %22, ptr noundef nonnull %15)
  br i1 %.not27, label %24, label %.thread32

24:                                               ; preds = %18
  %25 = load i8, ptr %19, align 1, !tbaa !15
  %26 = and i8 %25, 16
  %.not28 = icmp eq i8 %26, 0
  br i1 %.not28, label %.thread35, label %27

27:                                               ; preds = %24
  %28 = icmp ult i64 %23, 2
  br i1 %28, label %.thread32, label %29

29:                                               ; preds = %27
  call void @mem_cpy(ptr noundef nonnull %4, ptr noundef nonnull %3, i32 noundef 56)
  %30 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 %23, ptr %30, align 8, !tbaa !16
  %31 = call i32 @dir_sdi(ptr noundef nonnull %4, i32 noundef 2)
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %.thread32

33:                                               ; preds = %29
  %34 = call i32 @dir_read(ptr noundef nonnull %4, i32 noundef 0)
  %35 = icmp eq i32 %34, 0
  %spec.store.select = select i1 %35, i32 7, i32 %34
  %36 = icmp eq i32 %spec.store.select, 4
  br i1 %36, label %.thread35, label %.thread32

.thread35:                                        ; preds = %33, %24
  %37 = call i32 @dir_remove(ptr noundef nonnull %3)
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %.thread32

39:                                               ; preds = %.thread35
  %.not29 = icmp eq i64 %23, 0
  br i1 %.not29, label %.thread37, label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %3, align 8, !tbaa !14
  %42 = call i32 @remove_chain(ptr noundef %41, i64 noundef %23)
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %.thread37, label %.thread32

.thread37:                                        ; preds = %39, %40
  %44 = load ptr, ptr %3, align 8, !tbaa !14
  %45 = call i32 @sync_fs(ptr noundef %44)
  br label %.thread32

.thread32:                                        ; preds = %18, %.thread, %27, %29, %33, %8, %.thread35, %.thread37, %40, %1
  %.3 = phi i32 [ %45, %.thread37 ], [ %42, %40 ], [ %37, %.thread35 ], [ %11, %8 ], [ %6, %1 ], [ 6, %.thread ], [ 2, %27 ], [ %31, %29 ], [ %spec.store.select, %33 ], [ 7, %18 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %3) #2
  ret i32 %.3
}

; 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 48}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 10, !12, i64 16, !12, i64 24, !12, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 40}
!14 = !{!10, !6, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !12, i64 16}


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