; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.1/squashfs-tools (read_fs)

; 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.squashfs_super_block = type { i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i64, i64, i64, i64, i64, i64, i64, i64 }

@stderr = external global ptr, align 8
@.str.28 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [64 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @read_fs_bytes(i32 noundef, i64 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #5

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @read_fragment_table(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %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 i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.squashfs_super_block, ptr %15, i32 0, i32 4
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = mul i64 %18, 16
  %20 = add i64 %19, 8192
  %21 = sub i64 %20, 1
  %22 = udiv i64 %21, 8192
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %10, align 4, !tbaa !5
  %24 = load i32, ptr %10, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = call ptr @llvm.stacksave.p0()
  store ptr %26, ptr %11, align 8
  %27 = alloca i64, i64 %25, align 16
  store i64 %25, ptr %12, align 8
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.squashfs_super_block, ptr %28, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %124

33:                                               ; preds = %3
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.squashfs_super_block, ptr %34, i32 0, i32 4
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = mul i64 %37, 16
  %39 = call noalias ptr @malloc(i64 noundef %38) #7
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %39, ptr %40, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %50

44:                                               ; preds = %33
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr @stderr, align 8, !tbaa !9
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.28) #6
  br label %48

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %48
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %124

50:                                               ; preds = %33
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.squashfs_super_block, ptr %52, i32 0, i32 17
  %54 = load i64, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %6, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.squashfs_super_block, ptr %55, i32 0, i32 4
  %57 = load i32, ptr %56, align 8, !tbaa !11
  %58 = zext i32 %57 to i64
  %59 = mul i64 %58, 16
  %60 = add i64 %59, 8192
  %61 = sub i64 %60, 1
  %62 = udiv i64 %61, 8192
  %63 = mul i64 %62, 8
  %64 = trunc i64 %63 to i32
  %65 = call i32 @read_fs_bytes(i32 noundef %51, i64 noundef %54, i32 noundef %64, ptr noundef %27)
  store i32 %65, ptr %8, align 4, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %71

68:                                               ; preds = %50
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  call void @free(ptr noundef %70) #6
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %124

71:                                               ; preds = %50
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %109, %71
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = load i32, ptr %10, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %112

76:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i64, ptr %27, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !16
  %82 = load ptr, ptr %7, align 8, !tbaa !9
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  %84 = load i32, ptr %9, align 4, !tbaa !5
  %85 = mul nsw i32 %84, 8192
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i8, ptr %83, i64 %86
  %88 = call i32 @read_block(i32 noundef %77, i64 noundef %81, ptr noundef null, ptr noundef %87)
  store i32 %88, ptr %14, align 4, !tbaa !5
  %89 = load i32, ptr %14, align 4, !tbaa !5
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %105

91:                                               ; preds = %76
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr @stderr, align 8, !tbaa !9
  %94 = load i32, ptr %9, align 4, !tbaa !5
  %95 = load i32, ptr %9, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds i64, ptr %27, i64 %96
  %98 = load i64, ptr %97, align 8, !tbaa !16
  %99 = load i32, ptr %14, align 4, !tbaa !5
  %100 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %93, ptr noundef @.str.29, i32 noundef %94, i64 noundef %98, i32 noundef %99) #6
  br label %101

101:                                              ; preds = %92
  br label %102

102:                                              ; preds = %101
  %103 = load ptr, ptr %7, align 8, !tbaa !9
  %104 = load ptr, ptr %103, align 8, !tbaa !9
  call void @free(ptr noundef %104) #6
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %106

105:                                              ; preds = %76
  store i32 0, ptr %13, align 4
  br label %106

106:                                              ; preds = %105, %102
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  %107 = load i32, ptr %13, align 4
  switch i32 %107, label %124 [
    i32 0, label %108
  ]

108:                                              ; preds = %106
  br label %109

109:                                              ; preds = %108
  %110 = load i32, ptr %9, align 4, !tbaa !5
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %9, align 4, !tbaa !5
  br label %72, !llvm.loop !17

112:                                              ; preds = %72
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %113

113:                                              ; preds = %120, %112
  %114 = load i32, ptr %9, align 4, !tbaa !5
  %115 = load ptr, ptr %6, align 8, !tbaa !9
  %116 = getelementptr inbounds %struct.squashfs_super_block, ptr %115, i32 0, i32 4
  %117 = load i32, ptr %116, align 8, !tbaa !11
  %118 = icmp ult i32 %114, %117
  br i1 %118, label %119, label %123

119:                                              ; preds = %113
  br label %120

120:                                              ; preds = %119
  %121 = load i32, ptr %9, align 4, !tbaa !5
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %9, align 4, !tbaa !5
  br label %113, !llvm.loop !19

123:                                              ; preds = %113
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %124

124:                                              ; preds = %123, %106, %68, %49, %32
  %125 = load ptr, ptr %11, align 8
  call void @llvm.stackrestore.p0(ptr %125)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %126 = load i32, ptr %4, align 4
  ret i32 %126
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 "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 #4 = { nounwind allocsize(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 #5 = { nocallback nofree nosync nounwind willreturn }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"squashfs_super_block", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !13, i64 20, !13, i64 22, !13, i64 24, !13, i64 26, !13, i64 28, !13, i64 30, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!12, !14, i64 80}
!16 = !{!14, !14, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.28 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [64 x i8], align 1

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

declare i32 @read_fs_bytes(i32 noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @read_fragment_table(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = shl nuw nsw i64 %6, 4
  %8 = add nuw nsw i64 %7, 8191
  %9 = lshr i64 %8, 13
  %10 = alloca i64, i64 %9, align 16
  %11 = icmp eq i32 %5, 0
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %3
  %13 = tail call noalias ptr @malloc(i64 noundef %7) #5
  store ptr %13, ptr %2, align 8, !tbaa !12
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  %16 = load ptr, ptr @stderr, align 8, !tbaa !12
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.28) #6
  br label %.loopexit

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %1, i64 80
  %20 = load i64, ptr %19, align 8, !tbaa !14
  %21 = lshr i64 %8, 10
  %22 = trunc nuw nsw i64 %21 to i32
  %23 = and i32 %22, 134217720
  %24 = call i32 @read_fs_bytes(i32 noundef %0, i64 noundef %20, i32 noundef %23, ptr noundef nonnull %10) #7
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %.lr.ph

26:                                               ; preds = %18
  %27 = load ptr, ptr %2, align 8, !tbaa !12
  call void @free(ptr noundef %27) #7
  br label %.loopexit

.lr.ph:                                           ; preds = %18, %.critedge
  %indvars.iv = phi i64 [ %indvars.iv.next, %.critedge ], [ 0, %18 ]
  %28 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %2, align 8, !tbaa !12
  %31 = shl nsw i64 %indvars.iv, 13
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  %33 = call i32 @read_block(i32 noundef %0, i64 noundef %29, ptr noundef null, ptr noundef %32)
  %.not = icmp eq i32 %33, 0
  br i1 %.not, label %34, label %.critedge

34:                                               ; preds = %.lr.ph
  %35 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  %36 = trunc nuw nsw i64 %indvars.iv to i32
  %37 = load ptr, ptr @stderr, align 8, !tbaa !12
  %38 = load i64, ptr %35, align 8, !tbaa !15
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str.29, i32 noundef %36, i64 noundef %38, i32 noundef 0) #6
  %40 = load ptr, ptr %2, align 8, !tbaa !12
  call void @free(ptr noundef %40) #7
  br label %.loopexit

.critedge:                                        ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %9
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %.critedge, %34, %3, %26, %15
  %.2 = phi i32 [ 0, %15 ], [ 0, %26 ], [ 0, %34 ], [ 1, %3 ], [ 1, %.critedge ]
  ret i32 %.2
}

attributes #0 = { 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 #1 = { "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 = { nofree nounwind "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { nounwind allocsize(0) }
attributes #6 = { cold nounwind }
attributes #7 = { 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, !7, i64 16}
!6 = !{!"squashfs_super_block", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !10, i64 30, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !11, i64 80}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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