; 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_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 ptr @tf_create_lfn_entry(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @tf_lfn_checksum(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @tf_place_lfn_chain(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca %union.struct_FatFileEntry, align 1
  %13 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  br label %16

16:                                               ; preds = %20, %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call ptr @tf_create_lfn_entry(ptr noundef %17, ptr noundef %12)
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %21, ptr %11, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !11

24:                                               ; preds = %16
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = or i32 %25, 64
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %13, align 1, !tbaa !13
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %49, %24
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %52

32:                                               ; preds = %28
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = call ptr @tf_create_lfn_entry(ptr noundef %33, ptr noundef %12)
  %35 = load i8, ptr %13, align 1, !tbaa !13
  %36 = getelementptr inbounds %struct.struct_FatFileLFN, ptr %12, i32 0, i32 0
  store i8 %35, ptr %36, align 1, !tbaa !13
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call zeroext i8 @tf_lfn_checksum(ptr noundef %37)
  %39 = getelementptr inbounds %struct.struct_FatFileLFN, ptr %12, i32 0, i32 4
  store i8 %38, ptr %39, align 1, !tbaa !13
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = call i32 @tf_fwrite(ptr noundef %12, i32 noundef 32, i32 noundef 1, ptr noundef %40)
  %42 = load i8, ptr %13, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = and i32 %43, -65
  %45 = sub nsw i32 %44, 1
  %46 = trunc i32 %45 to i8
  store i8 %46, ptr %13, align 1, !tbaa !13
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 -13
  store ptr %48, ptr %11, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %32
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %28, !llvm.loop !14

52:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @tf_fwrite(ptr noundef, i32 noundef, i32 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 }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !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"

%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 ptr @tf_create_lfn_entry(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @tf_lfn_checksum(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @tf_place_lfn_chain(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %union.struct_FatFileEntry, align 1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #2
  br label %5

5:                                                ; preds = %5, %3
  %.017 = phi i32 [ 1, %3 ], [ %7, %5 ]
  %.014 = phi ptr [ %1, %3 ], [ %6, %5 ]
  %6 = call ptr @tf_create_lfn_entry(ptr noundef %.014, ptr noundef nonnull %4)
  %.not = icmp eq ptr %6, null
  %7 = add nuw nsw i32 %.017, 1
  br i1 %.not, label %8, label %5, !llvm.loop !5

8:                                                ; preds = %5
  %9 = trunc i32 %.017 to i8
  %10 = or i8 %9, 64
  %11 = getelementptr inbounds i8, ptr %4, i64 13
  br label %12

12:                                               ; preds = %8, %12
  %.021 = phi i8 [ %10, %8 ], [ %17, %12 ]
  %.120 = phi ptr [ %.014, %8 ], [ %18, %12 ]
  %.01619 = phi i32 [ 0, %8 ], [ %19, %12 ]
  %13 = call ptr @tf_create_lfn_entry(ptr noundef %.120, ptr noundef nonnull %4)
  store i8 %.021, ptr %4, align 1, !tbaa !7
  %14 = call zeroext i8 @tf_lfn_checksum(ptr noundef %2)
  store i8 %14, ptr %11, align 1, !tbaa !7
  %15 = call i32 @tf_fwrite(ptr noundef nonnull %4, i32 noundef 32, i32 noundef 1, ptr noundef %0)
  %16 = and i8 %.021, -65
  %17 = add i8 %16, -1
  %18 = getelementptr inbounds i8, ptr %.120, i64 -13
  %19 = add nuw nsw i32 %.01619, 1
  %exitcond.not = icmp eq i32 %19, %.017
  br i1 %exitcond.not, label %20, label %12, !llvm.loop !10

20:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #2
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @tf_fwrite(ptr noundef, i32 noundef, i32 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass