; LLVM IR from misa-md/MISA-MD :: tools/dump2text/out_convert.ll (Z9readBytesRSt14basic_ifstreamIcSt11char_traitsIcEEPcmii)

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

%"class.std::fpos" = type { i64, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon.0 }
%union.anon.0 = type { i32 }

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgElSt12_Ios_Seekdir(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i32 noundef) #1

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9readBytesRSt14basic_ifstreamIcSt11char_traitsIcEEPcmii(ptr noundef nonnull align 8 dereferenceable(256) %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca %"class.std::fpos", align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca %"class.std::fpos", align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  store i32 %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call { i64, i64 } @_ZNSi5tellgEv(ptr noundef nonnull align 8 dereferenceable(16) %20)
  %22 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 0
  %23 = extractvalue { i64, i64 } %21, 0
  store i64 %23, ptr %22, align 8
  %24 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 1
  %25 = extractvalue { i64, i64 } %21, 1
  store i64 %25, ptr %24, align 8
  %26 = call noundef i64 @_ZNKSt4fposI11__mbstate_tEcvlEv(ptr noundef nonnull align 8 dereferenceable(16) %12)
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  store i64 %26, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = mul nsw i32 128, %27
  %29 = add nsw i32 128, %28
  %30 = sext i32 %29 to i64
  store i64 %30, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = sub nsw i64 %31, %32
  %34 = sdiv i64 %33, 73728
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = sdiv i64 %34, %36
  store i64 %37, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %38 = load i64, ptr %13, align 8, !tbaa !9
  %39 = load i32, ptr %9, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = load i64, ptr %14, align 8, !tbaa !9
  %42 = add nsw i64 %41, 1
  %43 = mul nsw i64 %40, %42
  %44 = load i32, ptr %10, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = add nsw i64 %43, %45
  %47 = mul nsw i64 %46, 73728
  %48 = add nsw i64 %38, %47
  store i64 %48, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %49 = load i64, ptr %13, align 8, !tbaa !9
  %50 = load i32, ptr %9, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = load i64, ptr %14, align 8, !tbaa !9
  %53 = mul nsw i64 %51, %52
  %54 = load i32, ptr %10, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = add nsw i64 %53, %55
  %57 = add nsw i64 %56, 1
  %58 = mul nsw i64 %57, 73728
  %59 = add nsw i64 %49, %58
  store i64 %59, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %60 = load i64, ptr %16, align 8, !tbaa !9
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = sub nsw i64 %60, %61
  %63 = load i64, ptr %8, align 8, !tbaa !9
  %64 = icmp ugt i64 %62, %63
  br i1 %64, label %65, label %67

65:                                               ; preds = %5
  %66 = load i64, ptr %8, align 8, !tbaa !9
  br label %71

67:                                               ; preds = %5
  %68 = load i64, ptr %16, align 8, !tbaa !9
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = sub nsw i64 %68, %69
  br label %71

71:                                               ; preds = %67, %65
  %72 = phi i64 [ %66, %65 ], [ %70, %67 ]
  store i64 %72, ptr %17, align 8, !tbaa !9
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i64, ptr %17, align 8, !tbaa !9
  %76 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %73, ptr noundef %74, i64 noundef %75)
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %77 = load i32, ptr %10, align 4, !tbaa !11
  %78 = add nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = mul nsw i64 73728, %79
  %81 = urem i64 %80, 72
  %82 = sub i64 72, %81
  %83 = trunc i64 %82 to i32
  store i32 %83, ptr %18, align 4, !tbaa !11
  %84 = load i64, ptr %17, align 8, !tbaa !9
  %85 = load i64, ptr %8, align 8, !tbaa !9
  %86 = icmp ult i64 %84, %85
  br i1 %86, label %87, label %120

87:                                               ; preds = %71
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = load i64, ptr %15, align 8, !tbaa !9
  %90 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgElSt12_Ios_Seekdir(ptr noundef nonnull align 8 dereferenceable(16) %88, i64 noundef %89, i32 noundef 0)
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = load i64, ptr %17, align 8, !tbaa !9
  %94 = getelementptr inbounds i8, ptr %92, i64 %93
  %95 = load i32, ptr %18, align 4, !tbaa !11
  %96 = sext i32 %95 to i64
  %97 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %91, ptr noundef %94, i64 noundef %96)
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = load i64, ptr %17, align 8, !tbaa !9
  %101 = getelementptr inbounds i8, ptr %99, i64 %100
  %102 = load i32, ptr %18, align 4, !tbaa !11
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i8, ptr %101, i64 %103
  %105 = load i64, ptr %8, align 8, !tbaa !9
  %106 = load i64, ptr %17, align 8, !tbaa !9
  %107 = sub i64 %105, %106
  %108 = load i32, ptr %18, align 4, !tbaa !11
  %109 = sext i32 %108 to i64
  %110 = sub i64 %107, %109
  %111 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %98, ptr noundef %104, i64 noundef %110)
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  %114 = load i64, ptr %17, align 8, !tbaa !9
  %115 = getelementptr inbounds i8, ptr %113, i64 %114
  %116 = load i64, ptr %8, align 8, !tbaa !9
  %117 = load i64, ptr %17, align 8, !tbaa !9
  %118 = sub i64 %116, %117
  %119 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %112, ptr noundef %115, i64 noundef %118)
  br label %120

120:                                              ; preds = %87, %71
  call void @llvm.lifetime.start.p0(i64 16, ptr %19) #4
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  %122 = call { i64, i64 } @_ZNSi5tellgEv(ptr noundef nonnull align 8 dereferenceable(16) %121)
  %123 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 0
  %124 = extractvalue { i64, i64 } %122, 0
  store i64 %124, ptr %123, align 8
  %125 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 1
  %126 = extractvalue { i64, i64 } %122, 1
  store i64 %126, ptr %125, align 8
  %127 = call noundef i64 @_ZNKSt4fposI11__mbstate_tEcvlEv(ptr noundef nonnull align 8 dereferenceable(16) %19)
  %128 = load i64, ptr %16, align 8, !tbaa !9
  %129 = icmp eq i64 %127, %128
  call void @llvm.lifetime.end.p0(i64 16, ptr %19) #4
  br i1 %129, label %130, label %134

130:                                              ; preds = %120
  %131 = load ptr, ptr %6, align 8, !tbaa !5
  %132 = load i64, ptr %15, align 8, !tbaa !9
  %133 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgElSt12_Ios_Seekdir(ptr noundef nonnull align 8 dereferenceable(16) %131, i64 noundef %132, i32 noundef 0)
  br label %134

134:                                              ; preds = %130, %120
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret void
}

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

declare { i64, i64 } @_ZNSi5tellgEv(ptr noundef nonnull align 8 dereferenceable(16)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt4fposI11__mbstate_tEcvlEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 #3 = { mustprogress 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 }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

%"class.std::fpos" = type { i64, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon.0 }
%union.anon.0 = type { i32 }

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgElSt12_Ios_Seekdir(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i32 noundef) local_unnamed_addr #1

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9readBytesRSt14basic_ifstreamIcSt11char_traitsIcEEPcmii(ptr noundef nonnull align 8 dereferenceable(256) %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca %"class.std::fpos", align 8
  %7 = alloca %"class.std::fpos", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #5
  %8 = tail call { i64, i64 } @_ZNSi5tellgEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %9 = extractvalue { i64, i64 } %8, 0
  store i64 %9, ptr %6, align 8
  %10 = getelementptr inbounds i8, ptr %6, i64 8
  %11 = extractvalue { i64, i64 } %8, 1
  store i64 %11, ptr %10, align 8
  %12 = call noundef i64 @_ZNKSt4fposI11__mbstate_tEcvlEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #5
  %13 = shl nsw i32 %3, 7
  %14 = add nsw i32 %13, 128
  %15 = sext i32 %14 to i64
  %16 = sub nsw i64 %12, %15
  %17 = sdiv i64 %16, 73728
  %18 = sext i32 %3 to i64
  %19 = sdiv i64 %17, %18
  %20 = add nsw i64 %19, 1
  %21 = mul nsw i64 %20, %18
  %22 = sext i32 %4 to i64
  %23 = add nsw i64 %21, %22
  %24 = mul nsw i64 %23, 73728
  %25 = add nsw i64 %24, %15
  %26 = mul nsw i64 %19, %18
  %27 = add nsw i64 %26, %22
  %28 = mul i64 %27, 73728
  %29 = add nsw i64 %15, 73728
  %30 = add i64 %29, %28
  %31 = sub nsw i64 %30, %12
  %32 = call i64 @llvm.umin.i64(i64 %31, i64 %2)
  %33 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i64 noundef %32)
  %34 = icmp ult i64 %31, %2
  br i1 %34, label %35, label %49

35:                                               ; preds = %5
  %36 = add nsw i32 %4, 1
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %37, 73728
  %39 = urem i64 %38, 72
  %40 = sub nuw nsw i64 72, %39
  %41 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgElSt12_Ios_Seekdir(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %25, i32 noundef 0)
  %42 = getelementptr inbounds i8, ptr %1, i64 %32
  %43 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %42, i64 noundef %40)
  %44 = getelementptr inbounds i8, ptr %42, i64 %40
  %45 = sub i64 %2, %32
  %46 = sub i64 %45, %40
  %47 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %44, i64 noundef %46)
  %48 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %42, i64 noundef %45)
  br label %49

49:                                               ; preds = %35, %5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  %50 = call { i64, i64 } @_ZNSi5tellgEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %51 = extractvalue { i64, i64 } %50, 0
  store i64 %51, ptr %7, align 8
  %52 = getelementptr inbounds i8, ptr %7, i64 8
  %53 = extractvalue { i64, i64 } %50, 1
  store i64 %53, ptr %52, align 8
  %54 = call noundef i64 @_ZNKSt4fposI11__mbstate_tEcvlEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %55 = icmp eq i64 %54, %30
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  br i1 %55, label %56, label %58

56:                                               ; preds = %49
  %57 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgElSt12_Ios_Seekdir(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %25, i32 noundef 0)
  br label %58

58:                                               ; preds = %56, %49
  ret void
}

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

declare { i64, i64 } @_ZNSi5tellgEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt4fposI11__mbstate_tEcvlEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 #3 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass