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

%struct.struct_tfinfo = type { i8, i8, i32, i32, i16, i32, i8, i32, [512 x i8] }
%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
@tf_info = external dso_local global %struct.struct_tfinfo, align 4

; 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_store() #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
define dso_local i32 @tf_fflush(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %union.struct_FatFileEntry, align 1
  %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 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = getelementptr inbounds %struct.struct_FatFile83, ptr %6, i32 0, i32 0
  %10 = getelementptr inbounds [8 x i8], ptr %9, i64 0, i64 0
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.struct_TFFILE, ptr %11, i32 0, i32 7
  %13 = load i8, ptr %12, align 4, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = and i32 %14, 1
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %89

18:                                               ; preds = %1
  %19 = load i8, ptr getelementptr inbounds (%struct.struct_tfinfo, ptr @tf_info, i32 0, i32 6), align 4, !tbaa !14
  %20 = zext i8 %19 to i32
  %21 = and i32 %20, 1
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %18
  %24 = call i32 @tf_store()
  store i32 %24, ptr %4, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %23, %18
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.struct_TFFILE, ptr %26, i32 0, i32 7
  %28 = load i8, ptr %27, align 4, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = and i32 %29, 4
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %81

32:                                               ; preds = %25
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.struct_TFFILE, ptr %33, i32 0, i32 8
  %35 = load i8, ptr %34, align 1, !tbaa !16
  %36 = zext i8 %35 to i32
  %37 = and i32 %36, 16
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %32
  br label %74

40:                                               ; preds = %32
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.struct_TFFILE, ptr %41, i32 0, i32 11
  %43 = getelementptr inbounds [256 x i8], ptr %42, i64 0, i64 0
  %44 = call ptr @tf_parent(ptr noundef %43, ptr noundef @.str.2, i32 noundef 0)
  store ptr %44, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = icmp eq ptr %45, inttoptr (i64 -1 to ptr)
  br i1 %46, label %47, label %48

47:                                               ; preds = %40
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %89

48:                                               ; preds = %40
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.struct_TFFILE, ptr %49, i32 0, i32 11
  %51 = getelementptr inbounds [256 x i8], ptr %50, i64 0, i64 0
  %52 = call ptr @strrchr(ptr noundef %51, i32 noundef 47) #4
  store ptr %52, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  %56 = call i32 @tf_find_file(ptr noundef %53, ptr noundef %55)
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = call i32 @tf_fread(ptr noundef %6, i32 noundef 32, ptr noundef %57)
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.struct_TFFILE, ptr %60, i32 0, i32 6
  %62 = load i32, ptr %61, align 4, !tbaa !17
  %63 = zext i32 %62 to i64
  %64 = call i32 @tf_fseek(ptr noundef %59, i32 noundef -32, i64 noundef %63)
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.struct_TFFILE, ptr %65, i32 0, i32 10
  %67 = load i32, ptr %66, align 4, !tbaa !18
  %68 = sub i32 %67, 1
  %69 = getelementptr inbounds %struct.struct_FatFile83, ptr %6, i32 0, i32 12
  store i32 %68, ptr %69, align 1, !tbaa !19
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = call i32 @tf_fwrite(ptr noundef %6, i32 noundef 32, i32 noundef 1, ptr noundef %70)
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = call i32 @tf_fclose(ptr noundef %72)
  br label %74

74:                                               ; preds = %48, %39
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.struct_TFFILE, ptr %75, i32 0, i32 7
  %77 = load i8, ptr %76, align 4, !tbaa !11
  %78 = zext i8 %77 to i32
  %79 = and i32 %78, -5
  %80 = trunc i32 %79 to i8
  store i8 %80, ptr %76, align 4, !tbaa !11
  br label %81

81:                                               ; preds = %74, %25
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.struct_TFFILE, ptr %82, i32 0, i32 7
  %84 = load i8, ptr %83, align 4, !tbaa !11
  %85 = zext i8 %84 to i32
  %86 = and i32 %85, -2
  %87 = trunc i32 %86 to i8
  store i8 %87, ptr %83, align 4, !tbaa !11
  %88 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %88, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %89

89:                                               ; preds = %81, %47, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %90 = load i32, ptr %2, align 4
  ret i32 %90
}

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

%struct.struct_tfinfo = type { i8, i8, i32, i32, i16, i32, i8, i32, [512 x i8] }
%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
@tf_info = external dso_local local_unnamed_addr global %struct.struct_tfinfo, align 4

; 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_store() 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
define dso_local i32 @tf_fflush(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 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i8, ptr %3, align 4, !tbaa !5
  %5 = and i8 %4, 1
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %43, label %6

6:                                                ; preds = %1
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @tf_info, i64 20), align 4, !tbaa !11
  %8 = and i8 %7, 1
  %.not19 = icmp eq i8 %8, 0
  br i1 %.not19, label %11, label %9

9:                                                ; preds = %6
  %10 = tail call i32 @tf_store()
  %.pre = load i8, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %9, %6
  %12 = phi i8 [ %.pre, %9 ], [ %4, %6 ]
  %.017 = phi i32 [ %10, %9 ], [ 0, %6 ]
  %13 = and i8 %12, 4
  %.not20 = icmp eq i8 %13, 0
  br i1 %.not20, label %40, label %14

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

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = tail call ptr @tf_parent(ptr noundef nonnull %19, ptr noundef nonnull @.str.2, i32 noundef 0)
  %21 = icmp eq ptr %20, inttoptr (i64 -1 to ptr)
  br i1 %21, label %43, label %22

22:                                               ; preds = %18
  %23 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) %19, i32 noundef 47) #4
  %24 = getelementptr inbounds i8, ptr %23, i64 1
  %25 = tail call i32 @tf_find_file(ptr noundef %20, ptr noundef nonnull %24)
  %26 = call i32 @tf_fread(ptr noundef nonnull %2, i32 noundef 32, ptr noundef %20)
  %27 = getelementptr inbounds i8, ptr %20, i64 20
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = zext i32 %28 to i64
  %30 = call i32 @tf_fseek(ptr noundef %20, i32 noundef -32, i64 noundef %29)
  %31 = getelementptr inbounds i8, ptr %0, i64 28
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %33 = add i32 %32, -1
  %34 = getelementptr inbounds i8, ptr %2, i64 28
  store i32 %33, ptr %34, align 1, !tbaa !16
  %35 = call i32 @tf_fwrite(ptr noundef nonnull %2, i32 noundef 32, i32 noundef 1, ptr noundef %20)
  %36 = call i32 @tf_fclose(ptr noundef %20)
  %.pre22 = load i8, ptr %3, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %14, %22
  %38 = phi i8 [ %12, %14 ], [ %.pre22, %22 ]
  %39 = and i8 %38, -5
  br label %40

40:                                               ; preds = %37, %11
  %41 = phi i8 [ %39, %37 ], [ %12, %11 ]
  %42 = and i8 %41, -2
  store i8 %42, ptr %3, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %18, %1, %40
  %.0 = phi i32 [ %.017, %40 ], [ 0, %1 ], [ -1, %18 ]
  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, !8, i64 24}
!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 = !{!12, !8, i64 20}
!12 = !{!"struct_tfinfo", !8, i64 0, !8, i64 1, !7, i64 4, !7, i64 8, !10, i64 12, !7, i64 16, !8, i64 20, !7, i64 24, !8, i64 28}
!13 = !{!6, !8, i64 25}
!14 = !{!6, !7, i64 20}
!15 = !{!6, !7, i64 28}
!16 = !{!8, !8, i64 0}


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