; 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.26 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [58 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: nounwind uwtable
define dso_local ptr @read_id_table(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.squashfs_super_block, ptr %15, i32 0, i32 8
  %17 = load i16, ptr %16, align 2, !tbaa !11
  %18 = zext i16 %17 to i64
  %19 = mul i64 %18, 4
  %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 %6, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = call ptr @llvm.stacksave.p0()
  store ptr %26, ptr %7, align 8
  %27 = alloca i64, i64 %25, align 16
  store i64 %25, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.squashfs_super_block, ptr %28, i32 0, i32 8
  %30 = load i16, ptr %29, align 2, !tbaa !11
  %31 = zext i16 %30 to i64
  %32 = mul i64 %31, 4
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = call noalias ptr @malloc(i64 noundef %35) #7
  store ptr %36, ptr %10, align 8, !tbaa !9
  %37 = load ptr, ptr %10, align 8, !tbaa !9
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %45

39:                                               ; preds = %2
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr @stderr, align 8, !tbaa !9
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str.26) #6
  br label %43

43:                                               ; preds = %40
  br label %44

44:                                               ; preds = %43
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %124

45:                                               ; preds = %2
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.squashfs_super_block, ptr %47, i32 0, i32 13
  %49 = load i64, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.squashfs_super_block, ptr %50, i32 0, i32 8
  %52 = load i16, ptr %51, align 2, !tbaa !11
  %53 = zext i16 %52 to i64
  %54 = mul i64 %53, 4
  %55 = add i64 %54, 8192
  %56 = sub i64 %55, 1
  %57 = udiv i64 %56, 8192
  %58 = mul i64 %57, 8
  %59 = trunc i64 %58 to i32
  %60 = call i32 @read_fs_bytes(i32 noundef %46, i64 noundef %49, i32 noundef %59, ptr noundef %27)
  store i32 %60, ptr %11, align 4, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %65

63:                                               ; preds = %45
  %64 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %64) #6
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %124

65:                                               ; preds = %45
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %101, %65
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %70, label %104

70:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i64, ptr %27, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !16
  %76 = load ptr, ptr %10, align 8, !tbaa !9
  %77 = load i32, ptr %12, align 4, !tbaa !5
  %78 = mul nsw i32 %77, 8192
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i8, ptr %76, i64 %79
  %81 = call i32 @read_block(i32 noundef %71, i64 noundef %75, ptr noundef null, ptr noundef %80)
  store i32 %81, ptr %14, align 4, !tbaa !5
  %82 = load i32, ptr %14, align 4, !tbaa !5
  %83 = icmp eq i32 %82, 0
  br i1 %83, label %84, label %97

84:                                               ; preds = %70
  br label %85

85:                                               ; preds = %84
  %86 = load ptr, ptr @stderr, align 8, !tbaa !9
  %87 = load i32, ptr %12, align 4, !tbaa !5
  %88 = load i32, ptr %12, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i64, ptr %27, i64 %89
  %91 = load i64, ptr %90, align 8, !tbaa !16
  %92 = load i32, ptr %14, align 4, !tbaa !5
  %93 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %86, ptr noundef @.str.27, i32 noundef %87, i64 noundef %91, i32 noundef %92) #6
  br label %94

94:                                               ; preds = %85
  br label %95

95:                                               ; preds = %94
  %96 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %96) #6
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %98

97:                                               ; preds = %70
  store i32 0, ptr %13, align 4
  br label %98

98:                                               ; preds = %97, %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  %99 = load i32, ptr %13, align 4
  switch i32 %99, label %124 [
    i32 0, label %100
  ]

100:                                              ; preds = %98
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %12, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %12, align 4, !tbaa !5
  br label %66, !llvm.loop !17

104:                                              ; preds = %66
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %105

105:                                              ; preds = %119, %104
  %106 = load i32, ptr %12, align 4, !tbaa !5
  %107 = load ptr, ptr %5, align 8, !tbaa !9
  %108 = getelementptr inbounds %struct.squashfs_super_block, ptr %107, i32 0, i32 8
  %109 = load i16, ptr %108, align 2, !tbaa !11
  %110 = zext i16 %109 to i32
  %111 = icmp slt i32 %106, %110
  br i1 %111, label %112, label %122

112:                                              ; preds = %105
  %113 = load ptr, ptr %10, align 8, !tbaa !9
  %114 = load i32, ptr %12, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds i32, ptr %113, i64 %115
  %117 = load i32, ptr %116, align 4, !tbaa !5
  %118 = call ptr @create_id(i32 noundef %117)
  br label %119

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

122:                                              ; preds = %105
  %123 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %123, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %124

124:                                              ; preds = %122, %98, %63, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  %125 = load ptr, ptr %7, align 8
  call void @llvm.stackrestore.p0(ptr %125)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %126 = load ptr, ptr %3, align 8
  ret ptr %126
}

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

declare ptr @create_id(i32 noundef) #2

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

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, !13, i64 26}
!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 48}
!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.26 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [58 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 ptr @read_id_table(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 26
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = shl nuw nsw i32 %5, 2
  %7 = add nuw nsw i32 %6, 8191
  %8 = lshr i32 %7, 13
  %9 = zext nneg i32 %8 to i64
  %10 = alloca i64, i64 %9, align 16
  %11 = zext i16 %4 to i64
  %12 = shl nuw nsw i64 %11, 2
  %13 = tail call noalias ptr @malloc(i64 noundef %12) #5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %18

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

18:                                               ; preds = %2
  %19 = getelementptr inbounds i8, ptr %1, i64 48
  %20 = load i64, ptr %19, align 8, !tbaa !14
  %21 = lshr i32 %7, 10
  %22 = and i32 %21, 504
  %23 = call i32 @read_fs_bytes(i32 noundef %0, i64 noundef %20, i32 noundef %22, ptr noundef nonnull %10) #7
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %.preheader35

.preheader35:                                     ; preds = %18
  %.not41 = icmp eq i16 %4, 0
  br i1 %.not41, label %.preheader, label %.lr.ph

25:                                               ; preds = %18
  call void @free(ptr noundef nonnull %13) #7
  br label %.loopexit

.preheader:                                       ; preds = %.critedge, %.preheader35
  %26 = load i16, ptr %3, align 2, !tbaa !5
  %.not42 = icmp eq i16 %26, 0
  br i1 %.not42, label %.loopexit, label %.lr.ph40

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

32:                                               ; preds = %.lr.ph
  %33 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  %34 = trunc nuw nsw i64 %indvars.iv to i32
  %35 = load ptr, ptr @stderr, align 8, !tbaa !12
  %36 = load i64, ptr %33, align 8, !tbaa !15
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str.27, i32 noundef %34, i64 noundef %36, i32 noundef 0) #6
  call void @free(ptr noundef %13) #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 %.preheader, label %.lr.ph, !llvm.loop !16

.lr.ph40:                                         ; preds = %.preheader, %.lr.ph40
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %.lr.ph40 ], [ 0, %.preheader ]
  %38 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv46
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = call ptr @create_id(i32 noundef %39) #7
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %41 = load i16, ptr %3, align 2, !tbaa !5
  %42 = zext i16 %41 to i64
  %43 = icmp ult i64 %indvars.iv.next47, %42
  br i1 %43, label %.lr.ph40, label %.loopexit, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph40, %.preheader, %32, %25, %15
  %.2 = phi ptr [ null, %15 ], [ null, %25 ], [ null, %32 ], [ %13, %.preheader ], [ %13, %.lr.ph40 ]
  ret ptr %.2
}

declare ptr @create_id(i32 noundef) local_unnamed_addr #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 = { "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, !10, i64 26}
!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 48}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !17}


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