; 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] }

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; 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 uwtable
declare dso_local i32 @tf_fclose(ptr noundef) #1

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

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #2

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

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

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

13:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %73

14:                                               ; preds = %1
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i32 @tf_fclose(ptr noundef %15)
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call ptr @tf_parent(ptr noundef %17, ptr noundef @.str.2, i32 noundef 0)
  store ptr %18, ptr %4, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %22, %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call i32 @tf_fread(ptr noundef %5, i32 noundef 32, ptr noundef %20)
  br label %22

22:                                               ; preds = %19
  %23 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 0
  %24 = getelementptr inbounds [8 x i8], ptr %23, i64 0, i64 0
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %19, label %28, !llvm.loop !10

28:                                               ; preds = %22
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.struct_TFFILE, ptr %30, i32 0, i32 6
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = zext i32 %32 to i64
  %34 = call i32 @tf_fseek(ptr noundef %29, i32 noundef -32, i64 noundef %33)
  %35 = call i32 @tf_find_free_cluster()
  store i32 %35, ptr %6, align 4, !tbaa !16
  %36 = load i32, ptr %6, align 4, !tbaa !16
  %37 = call i32 @tf_set_fat_entry(i32 noundef %36, i32 noundef 268435448)
  %38 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 2
  store i8 0, ptr %38, align 1, !tbaa !9
  %39 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 4
  store i8 37, ptr %39, align 1, !tbaa !9
  %40 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 5
  store i16 32316, ptr %40, align 1, !tbaa !9
  %41 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 6
  store i16 16994, ptr %41, align 1, !tbaa !9
  %42 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 7
  store i16 16994, ptr %42, align 1, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !16
  %44 = lshr i32 %43, 16
  %45 = and i32 %44, 65535
  %46 = trunc i32 %45 to i16
  %47 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 8
  store i16 %46, ptr %47, align 1, !tbaa !9
  %48 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 9
  store i16 32316, ptr %48, align 1, !tbaa !9
  %49 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 10
  store i16 16994, ptr %49, align 1, !tbaa !9
  %50 = load i32, ptr %6, align 4, !tbaa !16
  %51 = and i32 %50, 65535
  %52 = trunc i32 %51 to i16
  %53 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 11
  store i16 %52, ptr %53, align 1, !tbaa !9
  %54 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 12
  store i32 0, ptr %54, align 1, !tbaa !9
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = call ptr @strrchr(ptr noundef %55, i32 noundef 47) #5
  %57 = getelementptr inbounds i8, ptr %56, i64 1
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 0
  %59 = getelementptr inbounds [8 x i8], ptr %58, i64 0, i64 0
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  call void @tf_choose_sfn(ptr noundef %59, ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 0
  %65 = getelementptr inbounds [8 x i8], ptr %64, i64 0, i64 0
  %66 = call i32 @tf_place_lfn_chain(ptr noundef %62, ptr noundef %63, ptr noundef %65)
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = call i32 @tf_fwrite(ptr noundef %5, i32 noundef 32, i32 noundef 1, ptr noundef %67)
  call void @llvm.memset.p0.i64(ptr align 1 %5, i8 0, i64 32, i1 false)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = call i32 @tf_fwrite(ptr noundef %5, i32 noundef 32, i32 noundef 1, ptr noundef %69)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = call i32 @tf_fclose(ptr noundef %71)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %73

73:                                               ; preds = %28, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %74 = load i32, ptr %2, align 4
  ret i32 %74
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @tf_find_free_cluster() #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 20}
!13 = !{!"struct_TFFILE", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !15, i64 16, !15, i64 18, !14, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !14, i64 28, !7, i64 32}
!14 = !{!"int", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !14, i64 0}


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

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; 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: nounwind uwtable
declare dso_local i32 @tf_fclose(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strrchr(ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @tf_create(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %union.struct_FatFileEntry, align 1
  %3 = tail call ptr @tf_parent(ptr noundef %0, ptr noundef nonnull @.str.4, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #4
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %36, label %4

4:                                                ; preds = %1
  %5 = tail call i32 @tf_fclose(ptr noundef nonnull %3)
  %6 = tail call ptr @tf_parent(ptr noundef %0, ptr noundef nonnull @.str.2, i32 noundef 0)
  br label %7

7:                                                ; preds = %7, %4
  %8 = call i32 @tf_fread(ptr noundef nonnull %2, i32 noundef 32, ptr noundef %6)
  %9 = load i8, ptr %2, align 1, !tbaa !5
  %.not19 = icmp eq i8 %9, 0
  br i1 %.not19, label %10, label %7, !llvm.loop !8

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %6, i64 20
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = zext i32 %12 to i64
  %14 = call i32 @tf_fseek(ptr noundef %6, i32 noundef -32, i64 noundef %13)
  %15 = call i32 @tf_find_free_cluster()
  %16 = call i32 @tf_set_fat_entry(i32 noundef %15, i32 noundef 268435448)
  %17 = getelementptr inbounds i8, ptr %2, i64 11
  store i8 0, ptr %17, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %2, i64 13
  store i8 37, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %2, i64 14
  store i16 32316, ptr %19, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  store i16 16994, ptr %20, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %2, i64 18
  store i16 16994, ptr %21, align 1, !tbaa !5
  %22 = lshr i32 %15, 16
  %23 = trunc nuw i32 %22 to i16
  %24 = getelementptr inbounds i8, ptr %2, i64 20
  store i16 %23, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %2, i64 22
  store i16 32316, ptr %25, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %2, i64 24
  store i16 16994, ptr %26, align 1, !tbaa !5
  %27 = trunc i32 %15 to i16
  %28 = getelementptr inbounds i8, ptr %2, i64 26
  store i16 %27, ptr %28, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %2, i64 28
  store i32 0, ptr %29, align 1, !tbaa !5
  %30 = call ptr @strrchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef 47) #5
  %31 = getelementptr inbounds i8, ptr %30, i64 1
  call void @tf_choose_sfn(ptr noundef nonnull %2, ptr noundef nonnull %31, ptr noundef %6)
  %32 = call i32 @tf_place_lfn_chain(ptr noundef %6, ptr noundef nonnull %31, ptr noundef nonnull %2)
  %33 = call i32 @tf_fwrite(ptr noundef nonnull %2, i32 noundef 32, i32 noundef 1, ptr noundef %6)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %2, i8 0, i64 32, i1 false)
  %34 = call i32 @tf_fwrite(ptr noundef nonnull %2, i32 noundef 32, i32 noundef 1, ptr noundef %6)
  %35 = call i32 @tf_fclose(ptr noundef %6)
  br label %36

36:                                               ; preds = %1, %10
  %.0 = phi i32 [ 0, %10 ], [ 1, %1 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  ret i32 %.0
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @tf_find_free_cluster() 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !12, i64 20}
!11 = !{!"struct_TFFILE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !13, i64 16, !13, i64 18, !12, i64 20, !6, i64 24, !6, i64 25, !6, i64 26, !12, i64 28, !6, i64 32}
!12 = !{!"int", !6, i64 0}
!13 = !{!"short", !6, i64 0}


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