; LLVM IR from ryansturmer/thinfat32 :: src (thinfat32)

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

%union.struct_FatFileEntry = type { %struct.struct_FatFile83 }
%struct.struct_FatFile83 = type { [8 x i8], [3 x i8], i8, i8, i8, i16, i16, i16, i16, i16, i16, i16, i32 }
%struct.struct_TFFILE = type { i32, i32, i32, i32, i16, i16, i32, i8, i8, i8, i32, [256 x i8] }
%struct.struct_FatFileLFN = type <{ i8, [5 x i16], i8, i8, i8, [6 x i16], i16, [2 x i16] }>

; 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 dso_local i32 @tf_fread(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tf_compare_filename(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %union.struct_FatFileEntry, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %13, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i32 @tf_fread(ptr noundef %9, i32 noundef 32, ptr noundef %14)
  %16 = getelementptr inbounds %struct.struct_FatFile83, ptr %9, i32 0, i32 0
  %17 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %119

22:                                               ; preds = %2
  %23 = getelementptr inbounds %struct.struct_FatFile83, ptr %9, i32 0, i32 2
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = icmp ne i32 %25, 15
  br i1 %26, label %27, label %39

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 @tf_compare_filename_segment(ptr noundef %9, ptr noundef %28)
  %30 = icmp eq i32 1, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %27
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.struct_TFFILE, ptr %33, i32 0, i32 6
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = zext i32 %35 to i64
  %37 = call i32 @tf_fseek(ptr noundef %32, i32 noundef -32, i64 noundef %36)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %119

38:                                               ; preds = %27
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %119

39:                                               ; preds = %22
  %40 = getelementptr inbounds %struct.struct_FatFileLFN, ptr %9, i32 0, i32 0
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = and i32 %42, 192
  %44 = icmp eq i32 %43, 64
  br i1 %44, label %45, label %117

45:                                               ; preds = %39
  %46 = getelementptr inbounds %struct.struct_FatFileLFN, ptr %9, i32 0, i32 0
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = zext i8 %47 to i32
  %49 = and i32 %48, -65
  store i32 %49, ptr %11, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = sub i32 %51, 1
  %53 = mul i32 32, %52
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.struct_TFFILE, ptr %54, i32 0, i32 6
  %56 = load i32, ptr %55, align 4, !tbaa !12
  %57 = zext i32 %56 to i64
  %58 = call i32 @tf_fseek(ptr noundef %50, i32 noundef %53, i64 noundef %57)
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = call i64 @strlen(ptr noundef %59) #4
  %61 = trunc i64 %60 to i32
  store i32 %61, ptr %8, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = add i32 %62, 12
  %64 = udiv i32 %63, 13
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = icmp ne i32 %64, %65
  br i1 %66, label %67, label %68

67:                                               ; preds = %45
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %119

68:                                               ; preds = %45
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %105, %68
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = icmp ult i32 %70, %71
  br i1 %72, label %73, label %108

73:                                               ; preds = %69
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.struct_TFFILE, ptr %75, i32 0, i32 6
  %77 = load i32, ptr %76, align 4, !tbaa !12
  %78 = zext i32 %77 to i64
  %79 = call i32 @tf_fseek(ptr noundef %74, i32 noundef -32, i64 noundef %78)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = call i32 @tf_fread(ptr noundef %9, i32 noundef 32, ptr noundef %80)
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = call i32 @tf_compare_filename_segment(ptr noundef %9, ptr noundef %82)
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %96, label %85

85:                                               ; preds = %73
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load i32, ptr %6, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = mul i64 %88, 32
  %90 = trunc i64 %89 to i32
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.struct_TFFILE, ptr %91, i32 0, i32 6
  %93 = load i32, ptr %92, align 4, !tbaa !12
  %94 = zext i32 %93 to i64
  %95 = call i32 @tf_fseek(ptr noundef %86, i32 noundef %90, i64 noundef %94)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %119

96:                                               ; preds = %73
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.struct_TFFILE, ptr %98, i32 0, i32 6
  %100 = load i32, ptr %99, align 4, !tbaa !12
  %101 = zext i32 %100 to i64
  %102 = call i32 @tf_fseek(ptr noundef %97, i32 noundef -32, i64 noundef %101)
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 13
  store ptr %104, ptr %10, align 8, !tbaa !5
  br label %105

105:                                              ; preds = %96
  %106 = load i32, ptr %6, align 4, !tbaa !9
  %107 = add i32 %106, 1
  store i32 %107, ptr %6, align 4, !tbaa !9
  br label %69, !llvm.loop !15

108:                                              ; preds = %69
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = load i32, ptr %11, align 4, !tbaa !9
  %111 = mul i32 32, %110
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.struct_TFFILE, ptr %112, i32 0, i32 6
  %114 = load i32, ptr %113, align 4, !tbaa !12
  %115 = zext i32 %114 to i64
  %116 = call i32 @tf_fseek(ptr noundef %109, i32 noundef %111, i64 noundef %115)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %119

117:                                              ; preds = %39
  br label %118

118:                                              ; preds = %117
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %119

119:                                              ; preds = %118, %108, %85, %67, %38, %31, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %120 = load i32, ptr %3, align 4
  ret i32 %120
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @tf_compare_filename_segment(ptr noundef, 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 willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 20}
!13 = !{!"struct_TFFILE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !14, i64 16, !14, i64 18, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 28, !7, i64 32}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

%union.struct_FatFileEntry = type { %struct.struct_FatFile83 }
%struct.struct_FatFile83 = type { [8 x i8], [3 x i8], i8, i8, i8, i16, i16, i16, i16, i16, i16, i16, 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: 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 dso_local i32 @tf_fread(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tf_compare_filename(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %union.struct_FatFileEntry, align 1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  %4 = call i32 @tf_fread(ptr noundef nonnull %3, i32 noundef 32, ptr noundef %0)
  %5 = load i8, ptr %3, align 1, !tbaa !5
  %6 = zext i8 %5 to i32
  %7 = icmp eq i8 %5, 0
  br i1 %7, label %53, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %3, i64 11
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not = icmp eq i8 %10, 15
  br i1 %.not, label %19, label %11

11:                                               ; preds = %8
  %12 = call i32 @tf_compare_filename_segment(ptr noundef nonnull %3, ptr noundef %1)
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %53

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %0, i64 20
  %16 = load i32, ptr %15, align 4, !tbaa !8
  %17 = zext i32 %16 to i64
  %18 = call i32 @tf_fseek(ptr noundef %0, i32 noundef -32, i64 noundef %17)
  br label %53

19:                                               ; preds = %8
  %20 = and i32 %6, 192
  %21 = icmp eq i32 %20, 64
  br i1 %21, label %22, label %53

22:                                               ; preds = %19
  %23 = and i32 %6, 63
  %24 = shl nuw nsw i32 %23, 5
  %25 = add nsw i32 %24, -32
  %26 = getelementptr inbounds i8, ptr %0, i64 20
  %27 = load i32, ptr %26, align 4, !tbaa !8
  %28 = zext i32 %27 to i64
  %29 = call i32 @tf_fseek(ptr noundef %0, i32 noundef %25, i64 noundef %28)
  %30 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %31 = trunc i64 %30 to i32
  %32 = add i32 %31, 12
  %33 = udiv i32 %32, 13
  %.not31 = icmp eq i32 %33, %23
  br i1 %.not31, label %.preheader, label %53

.preheader:                                       ; preds = %22
  %.not36 = icmp eq i32 %23, 0
  br i1 %.not36, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %44
  %.02735 = phi ptr [ %48, %44 ], [ %1, %.preheader ]
  %.02834 = phi i32 [ %49, %44 ], [ 0, %.preheader ]
  %34 = load i32, ptr %26, align 4, !tbaa !8
  %35 = zext i32 %34 to i64
  %36 = call i32 @tf_fseek(ptr noundef nonnull %0, i32 noundef -32, i64 noundef %35)
  %37 = call i32 @tf_fread(ptr noundef nonnull %3, i32 noundef 32, ptr noundef nonnull %0)
  %38 = call i32 @tf_compare_filename_segment(ptr noundef nonnull %3, ptr noundef %.02735)
  %.not32 = icmp eq i32 %38, 0
  br i1 %.not32, label %39, label %44

39:                                               ; preds = %.lr.ph
  %40 = shl i32 %.02834, 5
  %41 = load i32, ptr %26, align 4, !tbaa !8
  %42 = zext i32 %41 to i64
  %43 = call i32 @tf_fseek(ptr noundef nonnull %0, i32 noundef %40, i64 noundef %42)
  br label %53

44:                                               ; preds = %.lr.ph
  %45 = load i32, ptr %26, align 4, !tbaa !8
  %46 = zext i32 %45 to i64
  %47 = call i32 @tf_fseek(ptr noundef nonnull %0, i32 noundef -32, i64 noundef %46)
  %48 = getelementptr inbounds i8, ptr %.02735, i64 13
  %49 = add nuw nsw i32 %.02834, 1
  %exitcond.not = icmp eq i32 %49, %23
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %44, %.preheader
  %50 = load i32, ptr %26, align 4, !tbaa !8
  %51 = zext i32 %50 to i64
  %52 = call i32 @tf_fseek(ptr noundef nonnull %0, i32 noundef %24, i64 noundef %51)
  br label %53

53:                                               ; preds = %19, %22, %11, %2, %._crit_edge, %39, %14
  %.0 = phi i32 [ 1, %14 ], [ 0, %39 ], [ 1, %._crit_edge ], [ -1, %2 ], [ 0, %11 ], [ 0, %22 ], [ -1, %19 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @tf_compare_filename_segment(ptr noundef, 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 20}
!9 = !{!"struct_TFFILE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !11, i64 16, !11, i64 18, !10, i64 20, !6, i64 24, !6, i64 25, !6, i64 26, !10, i64 28, !6, i64 32}
!10 = !{!"int", !6, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass