; LLVM IR from sp-nitech/SPTK :: src/utils/sptk_utils.ll (ZN4sptk11WriteStreamERKNS_6MatrixEPSo)

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

; Function Attrs: mustprogress uwtable
declare noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE4failEv(ptr noundef nonnull align 8 dereferenceable(264)) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6Matrix9GetNumRowEv(ptr noundef nonnull align 8 dereferenceable(64)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6Matrix12GetNumColumnEv(ptr noundef nonnull align 8 dereferenceable(64)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk11WriteStreamERKNS_6MatrixEPSo(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = call noundef i32 @_ZNK4sptk6Matrix9GetNumRowEv(ptr noundef nonnull align 8 dereferenceable(64) %6)
  %8 = icmp eq i32 0, %7
  br i1 %8, label %16, label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call noundef i32 @_ZNK4sptk6Matrix12GetNumColumnEv(ptr noundef nonnull align 8 dereferenceable(64) %10)
  %12 = icmp eq i32 0, %11
  br i1 %12, label %16, label %13

13:                                               ; preds = %9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr null, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %9, %2
  store i1 false, ptr %3, align 1
  br label %38

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call noundef ptr @_ZNK4sptk6MatrixixEi(ptr noundef nonnull align 8 dereferenceable(64) %19, i32 noundef 0)
  %21 = getelementptr inbounds double, ptr %20, i64 0
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call noundef i32 @_ZNK4sptk6Matrix9GetNumRowEv(ptr noundef nonnull align 8 dereferenceable(64) %22)
  %24 = sext i32 %23 to i64
  %25 = mul i64 8, %24
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call noundef i32 @_ZNK4sptk6Matrix12GetNumColumnEv(ptr noundef nonnull align 8 dereferenceable(64) %26)
  %28 = sext i32 %27 to i64
  %29 = mul i64 %25, %28
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSo5writeEPKcl(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef %21, i64 noundef %29)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr i8, ptr %32, i64 -24
  %34 = load i64, ptr %33, align 8
  %35 = getelementptr inbounds i8, ptr %31, i64 %34
  %36 = call noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE4failEv(ptr noundef nonnull align 8 dereferenceable(264) %35)
  %37 = xor i1 %36, true
  store i1 %37, ptr %3, align 1
  br label %38

38:                                               ; preds = %17, %16
  %39 = load i1, ptr %3, align 1
  ret i1 %39
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4sptk6MatrixixEi(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) #2 align 2

attributes #0 = { 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 #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 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" }

!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 = !{!"vtable pointer", !8, 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"

; Function Attrs: mustprogress uwtable
declare noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE4failEv(ptr noundef nonnull align 8 dereferenceable(264)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6Matrix9GetNumRowEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6Matrix12GetNumColumnEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk11WriteStreamERKNS_6MatrixEPSo(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_ZNK4sptk6Matrix9GetNumRowEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %24, label %5

5:                                                ; preds = %2
  %6 = tail call noundef i32 @_ZNK4sptk6Matrix12GetNumColumnEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %7 = icmp eq i32 %6, 0
  %8 = icmp eq ptr %1, null
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %24, label %9

9:                                                ; preds = %5
  %10 = tail call noundef ptr @_ZNK4sptk6MatrixixEi(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef 0)
  %11 = tail call noundef i32 @_ZNK4sptk6Matrix9GetNumRowEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %12 = sext i32 %11 to i64
  %13 = shl nsw i64 %12, 3
  %14 = tail call noundef i32 @_ZNK4sptk6Matrix12GetNumColumnEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %15 = sext i32 %14 to i64
  %16 = mul i64 %13, %15
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSo5writeEPKcl(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %10, i64 noundef %16)
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr i8, ptr %18, i64 -24
  %20 = load i64, ptr %19, align 8
  %21 = getelementptr inbounds i8, ptr %1, i64 %20
  %22 = tail call noundef zeroext i1 @_ZNKSt9basic_iosIcSt11char_traitsIcEE4failEv(ptr noundef nonnull align 8 dereferenceable(264) %21)
  %23 = xor i1 %22, true
  br label %24

24:                                               ; preds = %2, %5, %9
  %.0 = phi i1 [ %23, %9 ], [ false, %5 ], [ false, %2 ]
  ret i1 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4sptk6MatrixixEi(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) local_unnamed_addr #2 align 2

attributes #0 = { 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 #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 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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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