; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/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, ptr, ptr, ptr, ptr, 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 [8192 x i8], align 16
  %14 = alloca i32, align 4
  %15 = 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) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = call i32 @read_fs_bytes(i32 noundef %16, i64 noundef %17, i32 noundef 2, ptr noundef %10)
  store i32 %18, ptr %11, align 4, !tbaa !5
  %19 = load i32, ptr %11, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %118

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

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8192, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %28 = load i16, ptr %10, align 2, !tbaa !13
  %29 = zext i16 %28 to i32
  %30 = and i32 %29, -32769
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %36

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

36:                                               ; preds = %27
  br label %37

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

49:                                               ; preds = %37
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

50:                                               ; preds = %37
  %51 = load ptr, ptr @comp, align 8, !tbaa !11
  %52 = load ptr, ptr %9, align 8, !tbaa !11
  %53 = getelementptr inbounds [8192 x i8], ptr %13, i64 0, i64 0
  %54 = load i16, ptr %10, align 2, !tbaa !13
  %55 = zext i16 %54 to i32
  %56 = call i32 @compressor_uncompress(ptr noundef %51, ptr noundef %52, ptr noundef %53, i32 noundef %55, i32 noundef 8192, ptr noundef %14)
  store i32 %56, ptr %15, align 4, !tbaa !5
  %57 = load i32, ptr %15, align 4, !tbaa !5
  %58 = icmp eq i32 %57, -1
  br i1 %58, label %59, label %69

59:                                               ; preds = %50
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr @stderr, align 8, !tbaa !11
  %62 = load ptr, ptr @comp, align 8, !tbaa !11
  %63 = getelementptr inbounds %struct.compressor, ptr %62, i32 0, i32 9
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load i32, ptr %14, align 4, !tbaa !5
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str, ptr noundef %64, i32 noundef %65) #5
  br label %67

67:                                               ; preds = %60
  br label %68

68:                                               ; preds = %67
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

69:                                               ; preds = %50
  %70 = load ptr, ptr %8, align 8, !tbaa !11
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %79

72:                                               ; preds = %69
  %73 = load i64, ptr %7, align 8, !tbaa !9
  %74 = add nsw i64 %73, 2
  %75 = load i16, ptr %10, align 2, !tbaa !13
  %76 = zext i16 %75 to i64
  %77 = add nsw i64 %74, %76
  %78 = load ptr, ptr %8, align 8, !tbaa !11
  store i64 %77, ptr %78, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %72, %69
  %80 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %80, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

81:                                               ; preds = %79, %68, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8192, ptr %13) #5
  br label %118

82:                                               ; preds = %22
  %83 = load i16, ptr %10, align 2, !tbaa !13
  %84 = zext i16 %83 to i32
  %85 = and i32 %84, -32769
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %91

87:                                               ; preds = %82
  %88 = load i16, ptr %10, align 2, !tbaa !13
  %89 = zext i16 %88 to i32
  %90 = and i32 %89, -32769
  br label %92

91:                                               ; preds = %82
  br label %92

92:                                               ; preds = %91, %87
  %93 = phi i32 [ %90, %87 ], [ 32768, %91 ]
  %94 = trunc i32 %93 to i16
  store i16 %94, ptr %10, align 2, !tbaa !13
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = load i64, ptr %7, align 8, !tbaa !9
  %97 = add nsw i64 %96, 2
  %98 = load i16, ptr %10, align 2, !tbaa !13
  %99 = zext i16 %98 to i32
  %100 = load ptr, ptr %9, align 8, !tbaa !11
  %101 = call i32 @read_fs_bytes(i32 noundef %95, i64 noundef %97, i32 noundef %99, ptr noundef %100)
  store i32 %101, ptr %11, align 4, !tbaa !5
  %102 = load i32, ptr %11, align 4, !tbaa !5
  %103 = icmp eq i32 %102, 0
  br i1 %103, label %104, label %105

104:                                              ; preds = %92
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %118

105:                                              ; preds = %92
  %106 = load ptr, ptr %8, align 8, !tbaa !11
  %107 = icmp ne ptr %106, null
  br i1 %107, label %108, label %115

108:                                              ; preds = %105
  %109 = load i64, ptr %7, align 8, !tbaa !9
  %110 = add nsw i64 %109, 2
  %111 = load i16, ptr %10, align 2, !tbaa !13
  %112 = zext i16 %111 to i64
  %113 = add nsw i64 %110, %112
  %114 = load ptr, ptr %8, align 8, !tbaa !11
  store i64 %113, ptr %114, align 8, !tbaa !9
  br label %115

115:                                              ; preds = %108, %105
  %116 = load i16, ptr %10, align 2, !tbaa !13
  %117 = zext i16 %116 to i32
  store i32 %117, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %118

118:                                              ; preds = %115, %104, %81, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #5
  %119 = load i32, ptr %5, align 4
  ret i32 %119
}

; 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: inlinehint nounwind uwtable
declare hidden i32 @compressor_uncompress(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #3

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

; 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 = { inlinehint 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 #4 = { 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 #5 = { 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 72}
!16 = !{!"compressor", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !6, i64 64, !12, i64 72, !6, i64 80}


; 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) #5
  %8 = call i32 @read_fs_bytes(i32 noundef %0, i64 noundef %1, i32 noundef 2, ptr noundef nonnull %5) #5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %48, label %10

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

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #5
  %.not22 = icmp eq i16 %11, 0
  %narrow = select i1 %.not22, 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) #5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %35, label %17

17:                                               ; preds = %12
  %18 = load ptr, ptr @comp, align 8, !tbaa !9
  %19 = load i16, ptr %5, align 2, !tbaa !5
  %20 = zext i16 %19 to i32
  %21 = call i32 @compressor_uncompress(ptr noundef %18, ptr noundef %3, ptr noundef nonnull %6, i32 noundef %20, i32 noundef 8192, ptr noundef nonnull %7)
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %30

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

30:                                               ; preds = %17
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %35, label %31

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

35:                                               ; preds = %30, %31, %12, %23
  %.0 = phi i32 [ 0, %23 ], [ 0, %12 ], [ %21, %31 ], [ %21, %30 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %6) #5
  br label %48

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

42:                                               ; preds = %36
  %.not26 = icmp eq ptr %2, null
  %.pre = load i16, ptr %5, align 2, !tbaa !5
  br i1 %.not26, label %46, label %43

43:                                               ; preds = %42
  %44 = zext i16 %.pre to i64
  %45 = add nsw i64 %38, %44
  store i64 %45, ptr %2, align 8, !tbaa !15
  br label %46

46:                                               ; preds = %43, %42
  %47 = zext i16 %.pre to i32
  br label %48

48:                                               ; preds = %36, %4, %46, %35
  %.1 = phi i32 [ %47, %46 ], [ %.0, %35 ], [ 0, %4 ], [ 0, %36 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #5
  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: inlinehint nounwind uwtable
declare hidden i32 @compressor_uncompress(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

; 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 = { inlinehint 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 72}
!12 = !{!"compressor", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !13, i64 64, !10, i64 72, !13, i64 80}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}


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