; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/squashfs-2.1-r2 (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, i32, i32, i64, i16, i8, i32, i64, i32, i32, i32 }>

@swap = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [44 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @read_block(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i16, align 2
  %13 = alloca i32, align 4
  %14 = alloca [8192 x i8], align 16
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 2, ptr %13, align 4, !tbaa !5
  %18 = load i32, ptr @swap, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %32

20:                                               ; preds = %5
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = load ptr, ptr %10, align 8, !tbaa !9
  call void @read_bytes(i32 noundef %21, i32 noundef %22, i32 noundef 2, ptr noundef %23)
  %24 = load ptr, ptr %10, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %12, i64 1
  store i8 %26, ptr %27, align 1, !tbaa !11
  %28 = load ptr, ptr %10, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %28, i64 1
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %12, i64 0
  store i8 %30, ptr %31, align 2, !tbaa !11
  br label %35

32:                                               ; preds = %5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  call void @read_bytes(i32 noundef %33, i32 noundef %34, i32 noundef 2, ptr noundef %12)
  br label %35

35:                                               ; preds = %32, %20
  %36 = load ptr, ptr %11, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.squashfs_super_block, ptr %36, i32 0, i32 8
  %38 = load i16, ptr %37, align 1
  %39 = and i16 %38, 255
  %40 = zext i16 %39 to i32
  %41 = ashr i32 %40, 2
  %42 = and i32 %41, 1
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %35
  store i32 3, ptr %13, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %44, %35
  %46 = load i16, ptr %12, align 2, !tbaa !12
  %47 = zext i16 %46 to i32
  %48 = and i32 %47, 32768
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %109, label %50

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8192, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store i64 8192, ptr %16, align 8, !tbaa !14
  %51 = load i16, ptr %12, align 2, !tbaa !12
  %52 = zext i16 %51 to i32
  %53 = and i32 %52, -32769
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %59

55:                                               ; preds = %50
  %56 = load i16, ptr %12, align 2, !tbaa !12
  %57 = zext i16 %56 to i32
  %58 = and i32 %57, -32769
  br label %60

59:                                               ; preds = %50
  br label %60

60:                                               ; preds = %59, %55
  %61 = phi i32 [ %58, %55 ], [ 32768, %59 ]
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr %12, align 2, !tbaa !12
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = load i32, ptr %13, align 4, !tbaa !5
  %66 = add nsw i32 %64, %65
  %67 = load i16, ptr %12, align 2, !tbaa !12
  %68 = zext i16 %67 to i32
  %69 = getelementptr inbounds [8192 x i8], ptr %14, i64 0, i64 0
  call void @read_bytes(i32 noundef %63, i32 noundef %66, i32 noundef %68, ptr noundef %69)
  %70 = load ptr, ptr %10, align 8, !tbaa !9
  %71 = getelementptr inbounds [8192 x i8], ptr %14, i64 0, i64 0
  %72 = load i16, ptr %12, align 2, !tbaa !12
  %73 = zext i16 %72 to i64
  %74 = call i32 @uncompress(ptr noundef %70, ptr noundef %16, ptr noundef %71, i64 noundef %73)
  store i32 %74, ptr %15, align 4, !tbaa !5
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %94

76:                                               ; preds = %60
  %77 = load i32, ptr %15, align 4, !tbaa !5
  %78 = icmp eq i32 %77, -4
  br i1 %78, label %79, label %82

79:                                               ; preds = %76
  %80 = load ptr, ptr @stderr, align 8, !tbaa !9
  %81 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef @.str) #4
  br label %93

82:                                               ; preds = %76
  %83 = load i32, ptr %15, align 4, !tbaa !5
  %84 = icmp eq i32 %83, -5
  br i1 %84, label %85, label %88

85:                                               ; preds = %82
  %86 = load ptr, ptr @stderr, align 8, !tbaa !9
  %87 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %86, ptr noundef @.str.1) #4
  br label %92

88:                                               ; preds = %82
  %89 = load ptr, ptr @stderr, align 8, !tbaa !9
  %90 = load i32, ptr %15, align 4, !tbaa !5
  %91 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %89, ptr noundef @.str.2, i32 noundef %90) #4
  br label %92

92:                                               ; preds = %88, %85
  br label %93

93:                                               ; preds = %92, %79
  store i32 0, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %108

94:                                               ; preds = %60
  %95 = load ptr, ptr %9, align 8, !tbaa !9
  %96 = icmp ne ptr %95, null
  br i1 %96, label %97, label %105

97:                                               ; preds = %94
  %98 = load i32, ptr %8, align 4, !tbaa !5
  %99 = load i32, ptr %13, align 4, !tbaa !5
  %100 = add nsw i32 %98, %99
  %101 = load i16, ptr %12, align 2, !tbaa !12
  %102 = zext i16 %101 to i32
  %103 = add nsw i32 %100, %102
  %104 = load ptr, ptr %9, align 8, !tbaa !9
  store i32 %103, ptr %104, align 4, !tbaa !5
  br label %105

105:                                              ; preds = %97, %94
  %106 = load i64, ptr %16, align 8, !tbaa !14
  %107 = trunc i64 %106 to i32
  store i32 %107, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %108

108:                                              ; preds = %105, %93
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8192, ptr %14) #4
  br label %142

109:                                              ; preds = %45
  %110 = load i16, ptr %12, align 2, !tbaa !12
  %111 = zext i16 %110 to i32
  %112 = and i32 %111, -32769
  %113 = icmp ne i32 %112, 0
  br i1 %113, label %114, label %118

114:                                              ; preds = %109
  %115 = load i16, ptr %12, align 2, !tbaa !12
  %116 = zext i16 %115 to i32
  %117 = and i32 %116, -32769
  br label %119

118:                                              ; preds = %109
  br label %119

119:                                              ; preds = %118, %114
  %120 = phi i32 [ %117, %114 ], [ 32768, %118 ]
  %121 = trunc i32 %120 to i16
  store i16 %121, ptr %12, align 2, !tbaa !12
  %122 = load i32, ptr %7, align 4, !tbaa !5
  %123 = load i32, ptr %8, align 4, !tbaa !5
  %124 = load i32, ptr %13, align 4, !tbaa !5
  %125 = add nsw i32 %123, %124
  %126 = load i16, ptr %12, align 2, !tbaa !12
  %127 = zext i16 %126 to i32
  %128 = load ptr, ptr %10, align 8, !tbaa !9
  call void @read_bytes(i32 noundef %122, i32 noundef %125, i32 noundef %127, ptr noundef %128)
  %129 = load ptr, ptr %9, align 8, !tbaa !9
  %130 = icmp ne ptr %129, null
  br i1 %130, label %131, label %139

131:                                              ; preds = %119
  %132 = load i32, ptr %8, align 4, !tbaa !5
  %133 = load i32, ptr %13, align 4, !tbaa !5
  %134 = add nsw i32 %132, %133
  %135 = load i16, ptr %12, align 2, !tbaa !12
  %136 = zext i16 %135 to i32
  %137 = add nsw i32 %134, %136
  %138 = load ptr, ptr %9, align 8, !tbaa !9
  store i32 %137, ptr %138, align 4, !tbaa !5
  br label %139

139:                                              ; preds = %131, %119
  %140 = load i16, ptr %12, align 2, !tbaa !12
  %141 = zext i16 %140 to i32
  store i32 %141, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %142

142:                                              ; preds = %139, %108
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  %143 = load i32, ptr %6, align 4
  ret i32 %143
}

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

declare void @read_bytes(i32 noundef, i32 noundef, i32 noundef, ptr noundef) #2

declare i32 @uncompress(ptr noundef, ptr noundef, ptr noundef, i64 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

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 }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !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"

@swap = external dso_local local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [44 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @read_block(i32 noundef %0, i32 noundef %1, ptr noundef writeonly %2, ptr noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = alloca i16, align 2
  %7 = alloca [8192 x i8], align 16
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #4
  %9 = load i32, ptr @swap, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %15, label %10

10:                                               ; preds = %5
  tail call void @read_bytes(i32 noundef %0, i32 noundef %1, i32 noundef 2, ptr noundef %3) #4
  %11 = load i8, ptr %3, align 1, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %6, i64 1
  store i8 %11, ptr %12, align 1, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %3, i64 1
  %14 = load i8, ptr %13, align 1, !tbaa !9
  store i8 %14, ptr %6, align 2, !tbaa !9
  br label %16

15:                                               ; preds = %5
  call void @read_bytes(i32 noundef %0, i32 noundef %1, i32 noundef 2, ptr noundef nonnull %6) #4
  br label %16

16:                                               ; preds = %15, %10
  %17 = getelementptr inbounds i8, ptr %4, i64 36
  %18 = load i16, ptr %17, align 1
  %19 = and i16 %18, 4
  %.not31 = icmp eq i16 %19, 0
  %spec.select = select i1 %.not31, i32 2, i32 3
  %20 = load i16, ptr %6, align 2
  %.not32 = icmp sgt i16 %20, -1
  br i1 %.not32, label %21, label %45

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  store i64 8192, ptr %8, align 8, !tbaa !10
  %.not33 = icmp eq i16 %20, 0
  %narrow = select i1 %.not33, i16 -32768, i16 %20
  store i16 %narrow, ptr %6, align 2, !tbaa !12
  %22 = add nsw i32 %spec.select, %1
  %23 = zext i16 %narrow to i32
  call void @read_bytes(i32 noundef %0, i32 noundef %22, i32 noundef %23, ptr noundef nonnull %7) #4
  %24 = load i16, ptr %6, align 2, !tbaa !12
  %25 = zext i16 %24 to i64
  %26 = call i32 @uncompress(ptr noundef %3, ptr noundef nonnull %8, ptr noundef nonnull %7, i64 noundef %25) #4
  switch i32 %26, label %33 [
    i32 0, label %36
    i32 -4, label %27
    i32 -5, label %30
  ]

27:                                               ; preds = %21
  %28 = load ptr, ptr @stderr, align 8, !tbaa !14
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str) #5
  br label %44

30:                                               ; preds = %21
  %31 = load ptr, ptr @stderr, align 8, !tbaa !14
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.1) #5
  br label %44

33:                                               ; preds = %21
  %34 = load ptr, ptr @stderr, align 8, !tbaa !14
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.2, i32 noundef %26) #5
  br label %44

36:                                               ; preds = %21
  %.not35 = icmp eq ptr %2, null
  br i1 %.not35, label %41, label %37

37:                                               ; preds = %36
  %38 = load i16, ptr %6, align 2, !tbaa !12
  %39 = zext i16 %38 to i32
  %40 = add nsw i32 %22, %39
  store i32 %40, ptr %2, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %37, %36
  %42 = load i64, ptr %8, align 8, !tbaa !10
  %43 = trunc i64 %42 to i32
  br label %44

44:                                               ; preds = %27, %33, %30, %41
  %.0 = phi i32 [ %43, %41 ], [ 0, %30 ], [ 0, %33 ], [ 0, %27 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %7) #4
  br label %._crit_edge

45:                                               ; preds = %16
  %46 = and i16 %20, 32767
  %.not36 = icmp eq i16 %46, 0
  %narrow37 = select i1 %.not36, i16 -32768, i16 %46
  store i16 %narrow37, ptr %6, align 2, !tbaa !12
  %47 = add nsw i32 %spec.select, %1
  %48 = zext i16 %narrow37 to i32
  call void @read_bytes(i32 noundef %0, i32 noundef %47, i32 noundef %48, ptr noundef %3) #4
  %.not38 = icmp eq ptr %2, null
  %.pre = load i16, ptr %6, align 2, !tbaa !12
  %.pre39 = zext i16 %.pre to i32
  br i1 %.not38, label %._crit_edge, label %49

49:                                               ; preds = %45
  %50 = add nsw i32 %47, %.pre39
  store i32 %50, ptr %2, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %45, %49, %44
  %.1 = phi i32 [ %.0, %44 ], [ %.pre39, %49 ], [ %.pre39, %45 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #4
  ret i32 %.1
}

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

declare void @read_bytes(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @uncompress(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

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

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 = { mustprogress 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 = { 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 #4 = { nounwind }
attributes #5 = { cold 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass