; LLVM IR from HANDS-FREE/OpenRE :: 3_OS/STM32F1/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 @validate(ptr noundef, i16 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @f_readdir(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [12 x i8], align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.DIR, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.DIR, ptr %10, i32 0, i32 1
  %12 = load i16, ptr %11, align 8, !tbaa !13
  %13 = call i32 @validate(ptr noundef %9, i16 noundef zeroext %12)
  store i32 %13, ptr %5, align 4, !tbaa !14
  %14 = load i32, ptr %5, align 4, !tbaa !14
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %49

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call i32 @dir_sdi(ptr noundef %20, i16 noundef zeroext 0)
  store i32 %21, ptr %5, align 4, !tbaa !14
  br label %48

22:                                               ; preds = %16
  %23 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 0
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.DIR, ptr %24, i32 0, i32 7
  store ptr %23, ptr %25, align 8, !tbaa !16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call i32 @dir_read(ptr noundef %26)
  store i32 %27, ptr %5, align 4, !tbaa !14
  %28 = load i32, ptr %5, align 4, !tbaa !14
  %29 = icmp eq i32 %28, 4
  br i1 %29, label %30, label %33

30:                                               ; preds = %22
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.DIR, ptr %31, i32 0, i32 5
  store i64 0, ptr %32, align 8, !tbaa !17
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %30, %22
  %34 = load i32, ptr %5, align 4, !tbaa !14
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %47

36:                                               ; preds = %33
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @get_fileinfo(ptr noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call i32 @dir_next(ptr noundef %39, i32 noundef 0)
  store i32 %40, ptr %5, align 4, !tbaa !14
  %41 = load i32, ptr %5, align 4, !tbaa !14
  %42 = icmp eq i32 %41, 4
  br i1 %42, label %43, label %46

43:                                               ; preds = %36
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.DIR, ptr %44, i32 0, i32 5
  store i64 0, ptr %45, align 8, !tbaa !17
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %46

46:                                               ; preds = %43, %36
  br label %47

47:                                               ; preds = %46, %33
  br label %48

48:                                               ; preds = %47, %19
  br label %49

49:                                               ; preds = %48, %2
  %50 = load i32, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %50
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @dir_next(ptr noundef, i32 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, !6, i64 0}
!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, !11, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !6, i64 48}
!17 = !{!10, !12, i64 32}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @f_readdir(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [12 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #2
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i16, ptr %5, align 8, !tbaa !12
  %7 = tail call i32 @validate(ptr noundef %4, i16 noundef zeroext %6)
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %21

9:                                                ; preds = %2
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %10, label %12

10:                                               ; preds = %9
  %11 = tail call i32 @dir_sdi(ptr noundef nonnull %0, i16 noundef zeroext 0)
  br label %21

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %3, ptr %13, align 8, !tbaa !13
  %14 = call i32 @dir_read(ptr noundef nonnull %0)
  switch i32 %14, label %21 [
    i32 4, label %.thread
    i32 0, label %16
  ]

.thread:                                          ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 0, ptr %15, align 8, !tbaa !14
  br label %16

16:                                               ; preds = %12, %.thread
  call void @get_fileinfo(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %17 = call i32 @dir_next(ptr noundef nonnull %0, i32 noundef 0)
  %18 = icmp eq i32 %17, 4
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 0, ptr %20, align 8, !tbaa !14
  br label %21

21:                                               ; preds = %12, %10, %16, %19, %2
  %.1 = phi i32 [ 0, %19 ], [ %17, %16 ], [ %11, %10 ], [ %7, %2 ], [ %14, %12 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #2
  ret i32 %.1
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @dir_next(ptr noundef, i32 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 10, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 48}
!14 = !{!6, !11, i64 32}


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