; 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 }
%struct.FATFS = type { i8, i8, i8, i8, i8, i8, i16, i16, i64, i64, i64, i64, i64, i64, i64, i64, i64, [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: 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 @chk_mounted(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
define dso_local i32 @f_opendir(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 = call i32 @chk_mounted(ptr noundef %4, ptr noundef %8, i8 noundef zeroext 0)
  store i32 %9, ptr %5, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %99

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

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

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

35:                                               ; preds = %26
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.DIR, ptr %36, i32 0, i32 6
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds i8, ptr %38, i64 20
  %40 = getelementptr inbounds i8, ptr %39, i64 1
  %41 = load i8, ptr %40, align 1, !tbaa !16
  %42 = zext i8 %41 to i16
  %43 = zext i16 %42 to i32
  %44 = shl i32 %43, 8
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.DIR, ptr %45, i32 0, i32 6
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = getelementptr inbounds i8, ptr %47, i64 20
  %49 = load i8, ptr %48, align 1, !tbaa !16
  %50 = zext i8 %49 to i16
  %51 = zext i16 %50 to i32
  %52 = or i32 %44, %51
  %53 = trunc i32 %52 to i16
  %54 = zext i16 %53 to i64
  %55 = shl i64 %54, 16
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.DIR, ptr %56, i32 0, i32 6
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds i8, ptr %58, i64 26
  %60 = getelementptr inbounds i8, ptr %59, i64 1
  %61 = load i8, ptr %60, align 1, !tbaa !16
  %62 = zext i8 %61 to i16
  %63 = zext i16 %62 to i32
  %64 = shl i32 %63, 8
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.DIR, ptr %65, i32 0, i32 6
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = getelementptr inbounds i8, ptr %67, i64 26
  %69 = load i8, ptr %68, align 1, !tbaa !16
  %70 = zext i8 %69 to i16
  %71 = zext i16 %70 to i32
  %72 = or i32 %64, %71
  %73 = trunc i32 %72 to i16
  %74 = zext i16 %73 to i64
  %75 = or i64 %55, %74
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.DIR, ptr %76, i32 0, i32 3
  store i64 %75, ptr %77, align 8, !tbaa !17
  br label %79

78:                                               ; preds = %26
  store i32 5, ptr %5, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %78, %35
  br label %80

80:                                               ; preds = %79, %21
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = icmp eq i32 %81, 0
  br i1 %82, label %83, label %93

83:                                               ; preds = %80
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.DIR, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !18
  %87 = getelementptr inbounds %struct.FATFS, ptr %86, i32 0, i32 6
  %88 = load i16, ptr %87, align 2, !tbaa !19
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.DIR, ptr %89, i32 0, i32 1
  store i16 %88, ptr %90, align 8, !tbaa !21
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = call i32 @dir_sdi(ptr noundef %91, i16 noundef zeroext 0)
  store i32 %92, ptr %5, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %83, %80
  br label %94

94:                                               ; preds = %93, %12
  %95 = load i32, ptr %5, align 4, !tbaa !9
  %96 = icmp eq i32 %95, 4
  br i1 %96, label %97, label %98

97:                                               ; preds = %94
  store i32 5, ptr %5, align 4, !tbaa !9
  br label %98

98:                                               ; preds = %97, %94
  br label %99

99:                                               ; preds = %98, %2
  %100 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %100
}

; Function Attrs: nounwind uwtable
declare hidden i32 @dir_sdi(ptr noundef, i16 noundef zeroext) #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, !14, i64 16}
!18 = !{!12, !6, i64 0}
!19 = !{!20, !13, i64 6}
!20 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !13, i64 6, !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !7, i64 88}
!21 = !{!12, !13, i64 8}


; 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 @chk_mounted(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
define dso_local i32 @f_opendir(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  %4 = alloca [12 x i8], align 1
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #2
  %5 = call i32 @chk_mounted(ptr noundef nonnull %3, ptr noundef %0, i8 noundef zeroext 0)
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %.thread23

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %4, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 @follow_path(ptr noundef %0, ptr noundef %9)
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %35

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

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %14, i64 11
  %17 = load i8, ptr %16, align 1, !tbaa !14
  %18 = and i8 %17, 16
  %.not21 = icmp eq i8 %18, 0
  br i1 %.not21, label %.thread23, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %14, i64 20
  %21 = load i16, ptr %20, align 1
  %22 = zext i16 %21 to i64
  %23 = shl nuw nsw i64 %22, 16
  %24 = getelementptr inbounds i8, ptr %14, i64 26
  %25 = load i16, ptr %24, align 1
  %26 = zext i16 %25 to i64
  %27 = or disjoint i64 %23, %26
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %27, ptr %28, align 8, !tbaa !15
  br label %29

29:                                               ; preds = %19, %12
  %30 = load ptr, ptr %0, align 8, !tbaa !16
  %31 = getelementptr inbounds i8, ptr %30, i64 6
  %32 = load i16, ptr %31, align 2, !tbaa !17
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  store i16 %32, ptr %33, align 8, !tbaa !19
  %34 = call i32 @dir_sdi(ptr noundef nonnull %0, i16 noundef zeroext 0)
  br label %35

35:                                               ; preds = %29, %7
  %.1 = phi i32 [ %34, %29 ], [ %10, %7 ]
  %.1.fr = freeze i32 %.1
  %36 = icmp eq i32 %.1.fr, 4
  %spec.select = select i1 %36, i32 5, i32 %.1.fr
  br label %.thread23

.thread23:                                        ; preds = %35, %15, %2
  %.2 = phi i32 [ %5, %2 ], [ 5, %15 ], [ %spec.select, %35 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #2
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden i32 @dir_sdi(ptr noundef, i16 noundef zeroext) 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 = !{!7, !7, i64 0}
!15 = !{!10, !12, i64 16}
!16 = !{!10, !6, i64 0}
!17 = !{!18, !11, i64 6}
!18 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !11, i64 6, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !7, i64 88}
!19 = !{!10, !11, i64 8}


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