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

; 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
define dso_local ptr @tf_walk(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %union.struct_FatFileEntry, align 1
  %7 = 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 32, ptr %6) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = icmp eq i32 %10, 47
  br i1 %11, label %12, label %21

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i32 1
  store ptr %14, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %12
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %118

20:                                               ; preds = %12
  br label %21

21:                                               ; preds = %20, %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %117

26:                                               ; preds = %21
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call i32 @tf_find_file(ptr noundef %27, ptr noundef %28)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %26
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.struct_TFFILE, ptr %32, i32 0, i32 7
  store i8 -1, ptr %33, align 4, !tbaa !10
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %118

34:                                               ; preds = %26
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @tf_fread(ptr noundef %6, i32 noundef 32, ptr noundef %35)
  br label %37

37:                                               ; preds = %49, %34
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = zext i8 %39 to i32
  %41 = icmp ne i32 %40, 47
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = icmp ne i32 %45, 0
  br label %47

47:                                               ; preds = %42, %37
  %48 = phi i1 [ false, %37 ], [ %46, %42 ]
  br i1 %48, label %49, label %52

49:                                               ; preds = %47
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 1
  store ptr %51, ptr %4, align 8, !tbaa !5
  br label %37, !llvm.loop !14

52:                                               ; preds = %47
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load i8, ptr %53, align 1, !tbaa !9
  %55 = zext i8 %54 to i32
  %56 = icmp eq i32 %55, 47
  br i1 %56, label %57, label %60

57:                                               ; preds = %52
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 1
  store ptr %59, ptr %4, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %57, %52
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.struct_TFFILE, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !16
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.struct_TFFILE, ptr %64, i32 0, i32 0
  store i32 %63, ptr %65, align 4, !tbaa !17
  %66 = getelementptr inbounds %struct.struct_FatFile83, ptr %6, i32 0, i32 8
  %67 = load i16, ptr %66, align 1, !tbaa !9
  %68 = zext i16 %67 to i32
  %69 = and i32 %68, 65535
  %70 = shl i32 %69, 16
  %71 = getelementptr inbounds %struct.struct_FatFile83, ptr %6, i32 0, i32 11
  %72 = load i16, ptr %71, align 1, !tbaa !9
  %73 = zext i16 %72 to i32
  %74 = and i32 %73, 65535
  %75 = or i32 %70, %74
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.struct_TFFILE, ptr %76, i32 0, i32 1
  store i32 %75, ptr %77, align 4, !tbaa !16
  %78 = getelementptr inbounds %struct.struct_FatFile83, ptr %6, i32 0, i32 2
  %79 = load i8, ptr %78, align 1, !tbaa !9
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.struct_TFFILE, ptr %80, i32 0, i32 8
  store i8 %79, ptr %81, align 1, !tbaa !18
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.struct_TFFILE, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %83, align 4, !tbaa !16
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.struct_TFFILE, ptr %85, i32 0, i32 3
  store i32 %84, ptr %86, align 4, !tbaa !19
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.struct_TFFILE, ptr %87, i32 0, i32 2
  store i32 0, ptr %88, align 4, !tbaa !20
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.struct_TFFILE, ptr %89, i32 0, i32 4
  store i16 0, ptr %90, align 4, !tbaa !21
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.struct_TFFILE, ptr %91, i32 0, i32 5
  store i16 0, ptr %92, align 2, !tbaa !22
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.struct_TFFILE, ptr %93, i32 0, i32 6
  store i32 0, ptr %94, align 4, !tbaa !23
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.struct_TFFILE, ptr %95, i32 0, i32 7
  store i8 2, ptr %96, align 4, !tbaa !10
  %97 = getelementptr inbounds %struct.struct_FatFile83, ptr %6, i32 0, i32 2
  %98 = load i8, ptr %97, align 1, !tbaa !9
  %99 = zext i8 %98 to i32
  %100 = and i32 %99, 16
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %103

102:                                              ; preds = %60
  br label %106

103:                                              ; preds = %60
  %104 = getelementptr inbounds %struct.struct_FatFile83, ptr %6, i32 0, i32 12
  %105 = load i32, ptr %104, align 1, !tbaa !9
  br label %106

106:                                              ; preds = %103, %102
  %107 = phi i32 [ -1, %102 ], [ %105, %103 ]
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.struct_TFFILE, ptr %108, i32 0, i32 10
  store i32 %107, ptr %109, align 4, !tbaa !24
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = load i8, ptr %110, align 1, !tbaa !9
  %112 = zext i8 %111 to i32
  %113 = icmp eq i32 %112, 0
  br i1 %113, label %114, label %115

114:                                              ; preds = %106
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %118

115:                                              ; preds = %106
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %116, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %118

117:                                              ; preds = %21
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %118

118:                                              ; preds = %117, %115, %114, %31, %19
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #2
  %119 = load ptr, ptr %3, align 8
  ret ptr %119
}

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

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


; 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: nounwind uwtable
define dso_local ptr @tf_walk(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) #2
  %4 = load i8, ptr %0, align 1, !tbaa !5
  switch i8 %4, label %.thread [
    i8 47, label %5
    i8 0, label %43
  ]

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = icmp eq i8 %7, 0
  br i1 %8, label %43, label %.thread

.thread:                                          ; preds = %2, %5
  %.02837 = phi ptr [ %6, %5 ], [ %0, %2 ]
  %9 = tail call i32 @tf_find_file(ptr noundef %1, ptr noundef nonnull %.02837)
  %.not30 = icmp eq i32 %9, 0
  br i1 %.not30, label %12, label %10

10:                                               ; preds = %.thread
  %11 = getelementptr inbounds i8, ptr %1, i64 24
  store i8 -1, ptr %11, align 4, !tbaa !8
  br label %43

12:                                               ; preds = %.thread
  %13 = call i32 @tf_fread(ptr noundef nonnull %3, i32 noundef 32, ptr noundef %1)
  br label %14

14:                                               ; preds = %16, %12
  %.1 = phi ptr [ %.02837, %12 ], [ %17, %16 ]
  %15 = load i8, ptr %.1, align 1, !tbaa !5
  switch i8 %15, label %16 [
    i8 47, label %.critedge
    i8 0, label %.critedge
  ]

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %.1, i64 1
  br label %14, !llvm.loop !12

.critedge:                                        ; preds = %14, %14
  %18 = icmp eq i8 %15, 47
  %spec.select.idx = zext i1 %18 to i64
  %spec.select = getelementptr inbounds i8, ptr %.1, i64 %spec.select.idx
  %19 = getelementptr inbounds i8, ptr %1, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !14
  store i32 %20, ptr %1, align 4, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %3, i64 20
  %22 = load i16, ptr %21, align 1, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = shl nuw i32 %23, 16
  %25 = getelementptr inbounds i8, ptr %3, i64 26
  %26 = load i16, ptr %25, align 1, !tbaa !5
  %27 = zext i16 %26 to i32
  %28 = or disjoint i32 %24, %27
  store i32 %28, ptr %19, align 4, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %3, i64 11
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %1, i64 25
  store i8 %30, ptr %31, align 1, !tbaa !16
  %32 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %28, ptr %32, align 4, !tbaa !17
  %33 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 0, ptr %33, align 4, !tbaa !18
  %34 = getelementptr inbounds i8, ptr %1, i64 16
  %35 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 0, ptr %34, align 4
  store i8 2, ptr %35, align 4, !tbaa !8
  %36 = and i8 %30, 16
  %.not33 = icmp eq i8 %36, 0
  %37 = getelementptr inbounds i8, ptr %3, i64 28
  %38 = load i32, ptr %37, align 1
  %39 = select i1 %.not33, i32 %38, i32 -1
  %40 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 %39, ptr %40, align 4, !tbaa !19
  %41 = load i8, ptr %spec.select, align 1, !tbaa !5
  %42 = icmp eq i8 %41, 0
  %spec.select34 = select i1 %42, ptr null, ptr %spec.select
  br label %43

43:                                               ; preds = %2, %.critedge, %5, %10
  %.0 = phi ptr [ null, %10 ], [ null, %5 ], [ %spec.select34, %.critedge ], [ null, %2 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #2
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @tf_find_file(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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 24}
!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"}
!14 = !{!9, !10, i64 4}
!15 = !{!9, !10, i64 0}
!16 = !{!9, !6, i64 25}
!17 = !{!9, !10, i64 12}
!18 = !{!9, !10, i64 8}
!19 = !{!9, !10, i64 28}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass