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

; 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_find_file(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_fwrite(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tf_remove(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 i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call ptr @tf_fopen(ptr noundef %9, ptr noundef @.str.4)
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

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

14:                                               ; preds = %1
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.struct_TFFILE, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %7, align 4, !tbaa !13
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call i32 @tf_fclose(ptr noundef %18)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call ptr @tf_parent(ptr noundef %20, ptr noundef @.str.2, i32 noundef 0)
  store ptr %21, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call ptr @strrchr(ptr noundef %23, i32 noundef 47) #4
  %25 = getelementptr inbounds i8, ptr %24, i64 1
  %26 = call i32 @tf_find_file(ptr noundef %22, ptr noundef %25)
  store i32 %26, ptr %6, align 4, !tbaa !13
  %27 = load i32, ptr %6, align 4, !tbaa !13
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %72, label %29

29:                                               ; preds = %14
  br label %30

30:                                               ; preds = %58, %29
  br label %31

31:                                               ; preds = %30
  %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 !14
  %36 = zext i32 %35 to i64
  %37 = call i32 @tf_fseek(ptr noundef %32, i32 noundef 32, i64 noundef %36)
  store i32 %37, ptr %6, align 4, !tbaa !13
  %38 = load i32, ptr %6, align 4, !tbaa !13
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %31
  br label %59

41:                                               ; preds = %31
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call i32 @tf_fread(ptr noundef %5, i32 noundef 32, ptr noundef %42)
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.struct_TFFILE, ptr %45, i32 0, i32 6
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = zext i32 %47 to i64
  %49 = call i32 @tf_fseek(ptr noundef %44, i32 noundef -64, i64 noundef %48)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call i32 @tf_fwrite(ptr noundef %5, i32 noundef 32, i32 noundef 1, ptr noundef %50)
  %52 = getelementptr inbounds %struct.struct_FatFile83, ptr %5, i32 0, i32 0
  %53 = getelementptr inbounds [8 x i8], ptr %52, i64 0, i64 0
  %54 = load i8, ptr %53, align 1, !tbaa !15
  %55 = zext i8 %54 to i32
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %41
  br label %59

58:                                               ; preds = %41
  br label %30

59:                                               ; preds = %57, %40
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.struct_TFFILE, ptr %60, i32 0, i32 10
  %62 = load i32, ptr %61, align 4, !tbaa !16
  %63 = zext i32 %62 to i64
  %64 = sub i64 %63, 32
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %61, align 4, !tbaa !16
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.struct_TFFILE, ptr %66, i32 0, i32 7
  %68 = load i8, ptr %67, align 4, !tbaa !17
  %69 = zext i8 %68 to i32
  %70 = or i32 %69, 4
  %71 = trunc i32 %70 to i8
  store i8 %71, ptr %67, align 4, !tbaa !17
  br label %72

72:                                               ; preds = %59, %14
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = call i32 @tf_fclose(ptr noundef %73)
  %75 = load i32, ptr %7, align 4, !tbaa !13
  %76 = call i32 @tf_free_clusterchain(i32 noundef %75)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %77

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

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


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

; 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_find_file(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_fwrite(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = tail call i32 @tf_fclose(ptr noundef nonnull %3)
  %9 = tail call ptr @tf_parent(ptr noundef %0, ptr noundef nonnull @.str.2, i32 noundef 0)
  %10 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef 47) #4
  %11 = getelementptr inbounds i8, ptr %10, i64 1
  %12 = tail call i32 @tf_find_file(ptr noundef %9, ptr noundef nonnull %11)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %.preheader, label %33

.preheader:                                       ; preds = %5
  %13 = getelementptr inbounds i8, ptr %9, i64 20
  br label %14

14:                                               ; preds = %.preheader, %18
  %15 = load i32, ptr %13, align 4, !tbaa !11
  %16 = zext i32 %15 to i64
  %17 = call i32 @tf_fseek(ptr noundef %9, i32 noundef 32, i64 noundef %16)
  %.not20 = icmp eq i32 %17, 0
  br i1 %.not20, label %18, label %26

18:                                               ; preds = %14
  %19 = call i32 @tf_fread(ptr noundef nonnull %2, i32 noundef 32, ptr noundef nonnull %9)
  %20 = load i32, ptr %13, align 4, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = call i32 @tf_fseek(ptr noundef nonnull %9, i32 noundef -64, i64 noundef %21)
  %23 = call i32 @tf_fwrite(ptr noundef nonnull %2, i32 noundef 32, i32 noundef 1, ptr noundef nonnull %9)
  %24 = load i8, ptr %2, align 1, !tbaa !12
  %25 = icmp eq i8 %24, 0
  br i1 %25, label %26, label %14

26:                                               ; preds = %18, %14
  %27 = getelementptr inbounds i8, ptr %9, i64 28
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = add i32 %28, -32
  store i32 %29, ptr %27, align 4, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %9, i64 24
  %31 = load i8, ptr %30, align 4, !tbaa !14
  %32 = or i8 %31, 4
  store i8 %32, ptr %30, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %26, %5
  %34 = call i32 @tf_fclose(ptr noundef %9)
  %35 = call i32 @tf_free_clusterchain(i32 noundef %7)
  br label %36

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

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


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