; 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.compressor = type { ptr, ptr, i32, ptr, i32 }

@comp = external hidden global ptr, align 8
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [41 x i8], align 1

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

22:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %129

23:                                               ; preds = %4
  %24 = load i16, ptr %10, align 2, !tbaa !13
  %25 = zext i16 %24 to i32
  %26 = and i32 %25, 32768
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %89, label %28

28:                                               ; preds = %23
  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 4, ptr %16) #4
  %29 = load i16, ptr %10, align 2, !tbaa !13
  %30 = zext i16 %29 to i32
  %31 = and i32 %30, -32769
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %37

33:                                               ; preds = %28
  %34 = load i16, ptr %10, align 2, !tbaa !13
  %35 = zext i16 %34 to i32
  %36 = and i32 %35, -32769
  br label %38

37:                                               ; preds = %28
  br label %38

38:                                               ; preds = %37, %33
  %39 = phi i32 [ %36, %33 ], [ 32768, %37 ]
  %40 = trunc i32 %39 to i16
  store i16 %40, ptr %10, align 2, !tbaa !13
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = add nsw i64 %42, %44
  %46 = load i16, ptr %10, align 2, !tbaa !13
  %47 = zext i16 %46 to i32
  %48 = getelementptr inbounds [8192 x i8], ptr %14, i64 0, i64 0
  %49 = call i32 @read_fs_bytes(i32 noundef %41, i64 noundef %45, i32 noundef %47, ptr noundef %48)
  store i32 %49, ptr %16, align 4, !tbaa !5
  %50 = load i32, ptr %16, align 4, !tbaa !5
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %38
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %88

53:                                               ; preds = %38
  %54 = load ptr, ptr @comp, align 8, !tbaa !11
  %55 = getelementptr inbounds %struct.compressor, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = load ptr, ptr %9, align 8, !tbaa !11
  %58 = getelementptr inbounds [8192 x i8], ptr %14, i64 0, i64 0
  %59 = load i16, ptr %10, align 2, !tbaa !13
  %60 = zext i16 %59 to i32
  %61 = call i32 %56(ptr noundef %57, ptr noundef %58, i32 noundef %60, i32 noundef 8192, ptr noundef %15)
  store i32 %61, ptr %16, align 4, !tbaa !5
  %62 = load i32, ptr %16, align 4, !tbaa !5
  %63 = icmp eq i32 %62, -1
  br i1 %63, label %64, label %74

64:                                               ; preds = %53
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr @stderr, align 8, !tbaa !11
  %67 = load ptr, ptr @comp, align 8, !tbaa !11
  %68 = getelementptr inbounds %struct.compressor, ptr %67, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = load i32, ptr %15, align 4, !tbaa !5
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %66, ptr noundef @.str, ptr noundef %69, i32 noundef %70) #4
  br label %72

72:                                               ; preds = %65
  br label %73

73:                                               ; preds = %72
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %88

74:                                               ; preds = %53
  %75 = load ptr, ptr %8, align 8, !tbaa !11
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %86

77:                                               ; preds = %74
  %78 = load i64, ptr %7, align 8, !tbaa !9
  %79 = load i32, ptr %12, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = add nsw i64 %78, %80
  %82 = load i16, ptr %10, align 2, !tbaa !13
  %83 = zext i16 %82 to i64
  %84 = add nsw i64 %81, %83
  %85 = load ptr, ptr %8, align 8, !tbaa !11
  store i64 %84, ptr %85, align 8, !tbaa !9
  br label %86

86:                                               ; preds = %77, %74
  %87 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %87, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %88

88:                                               ; preds = %86, %73, %52
  call void @llvm.lifetime.end.p0(i64 4, 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 %129

89:                                               ; preds = %23
  %90 = load i16, ptr %10, align 2, !tbaa !13
  %91 = zext i16 %90 to i32
  %92 = and i32 %91, -32769
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %98

94:                                               ; preds = %89
  %95 = load i16, ptr %10, align 2, !tbaa !13
  %96 = zext i16 %95 to i32
  %97 = and i32 %96, -32769
  br label %99

98:                                               ; preds = %89
  br label %99

99:                                               ; preds = %98, %94
  %100 = phi i32 [ %97, %94 ], [ 32768, %98 ]
  %101 = trunc i32 %100 to i16
  store i16 %101, ptr %10, align 2, !tbaa !13
  %102 = load i32, ptr %6, align 4, !tbaa !5
  %103 = load i64, ptr %7, align 8, !tbaa !9
  %104 = load i32, ptr %12, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = add nsw i64 %103, %105
  %107 = load i16, ptr %10, align 2, !tbaa !13
  %108 = zext i16 %107 to i32
  %109 = load ptr, ptr %9, align 8, !tbaa !11
  %110 = call i32 @read_fs_bytes(i32 noundef %102, i64 noundef %106, i32 noundef %108, ptr noundef %109)
  store i32 %110, ptr %11, align 4, !tbaa !5
  %111 = load i32, ptr %11, align 4, !tbaa !5
  %112 = icmp eq i32 %111, 0
  br i1 %112, label %113, label %114

113:                                              ; preds = %99
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %129

114:                                              ; preds = %99
  %115 = load ptr, ptr %8, align 8, !tbaa !11
  %116 = icmp ne ptr %115, null
  br i1 %116, label %117, label %126

117:                                              ; preds = %114
  %118 = load i64, ptr %7, align 8, !tbaa !9
  %119 = load i32, ptr %12, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = add nsw i64 %118, %120
  %122 = load i16, ptr %10, align 2, !tbaa !13
  %123 = zext i16 %122 to i64
  %124 = add nsw i64 %121, %123
  %125 = load ptr, ptr %8, align 8, !tbaa !11
  store i64 %124, ptr %125, align 8, !tbaa !9
  br label %126

126:                                              ; preds = %117, %114
  %127 = load i16, ptr %10, align 2, !tbaa !13
  %128 = zext i16 %127 to i32
  store i32 %128, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %129

129:                                              ; preds = %126, %113, %88, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #4
  %130 = load i32, ptr %5, align 4
  ret i32 %130
}

; 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

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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !12, i64 8}
!16 = !{!"compressor", !12, i64 0, !12, i64 8, !6, i64 16, !12, i64 24, !6, i64 32}
!17 = !{!16, !12, 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"

@comp = external hidden local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [41 x i8], align 1

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

10:                                               ; preds = %4
  %11 = load i16, ptr %5, align 2
  %.not = icmp sgt i16 %11, -1
  br i1 %.not, label %12, label %38

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  %.not26 = icmp eq i16 %11, 0
  %narrow = select i1 %.not26, i16 -32768, i16 %11
  store i16 %narrow, ptr %5, align 2, !tbaa !5
  %13 = add nsw i64 %1, 2
  %14 = zext i16 %narrow to i32
  %15 = call i32 @read_fs_bytes(i32 noundef %0, i64 noundef %13, i32 noundef %14, ptr noundef nonnull %6) #4
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %37, label %17

17:                                               ; preds = %12
  %18 = load ptr, ptr @comp, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = load i16, ptr %5, align 2, !tbaa !5
  %22 = zext i16 %21 to i32
  %23 = call i32 %20(ptr noundef %3, ptr noundef nonnull %6, i32 noundef %22, i32 noundef 8192, ptr noundef nonnull %7) #4
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %25, label %32

25:                                               ; preds = %17
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = load ptr, ptr @comp, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load i32, ptr %7, align 4, !tbaa !15
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str, ptr noundef %29, i32 noundef %30) #5
  br label %37

32:                                               ; preds = %17
  %.not27 = icmp eq ptr %2, null
  br i1 %.not27, label %37, label %33

33:                                               ; preds = %32
  %34 = load i16, ptr %5, align 2, !tbaa !5
  %35 = zext i16 %34 to i64
  %36 = add nsw i64 %13, %35
  store i64 %36, ptr %2, align 8, !tbaa !16
  br label %37

37:                                               ; preds = %32, %33, %12, %25
  %.0 = phi i32 [ 0, %25 ], [ 0, %12 ], [ %23, %33 ], [ %23, %32 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %6) #4
  br label %50

38:                                               ; preds = %10
  %39 = and i16 %11, 32767
  %.not28 = icmp eq i16 %39, 0
  %narrow29 = select i1 %.not28, i16 -32768, i16 %39
  store i16 %narrow29, ptr %5, align 2, !tbaa !5
  %40 = add nsw i64 %1, 2
  %41 = zext i16 %narrow29 to i32
  %42 = call i32 @read_fs_bytes(i32 noundef %0, i64 noundef %40, i32 noundef %41, ptr noundef %3) #4
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %50, label %44

44:                                               ; preds = %38
  %.not30 = icmp eq ptr %2, null
  %.pre = load i16, ptr %5, align 2, !tbaa !5
  br i1 %.not30, label %48, label %45

45:                                               ; preds = %44
  %46 = zext i16 %.pre to i64
  %47 = add nsw i64 %40, %46
  store i64 %47, ptr %2, align 8, !tbaa !16
  br label %48

48:                                               ; preds = %45, %44
  %49 = zext i16 %.pre to i32
  br label %50

50:                                               ; preds = %38, %4, %48, %37
  %.1 = phi i32 [ %49, %48 ], [ %.0, %37 ], [ 0, %4 ], [ 0, %38 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #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 i32 @read_fs_bytes(i32 noundef, i64 noundef, i32 noundef, ptr 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 = !{!"short", !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, !10, i64 8}
!12 = !{!"compressor", !10, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !13, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}


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