; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/1224_xmas_2015/A.ll (Z10transposed6matrix)

; 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.matrix = type { i32, i32, %"class.std::valarray" }
%"class.std::valarray" = type { i64, ptr }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #1 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10transposed6matrix(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 8 %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  store i1 false, ptr %5, align 1
  %9 = getelementptr inbounds %struct.matrix, ptr %1, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = getelementptr inbounds %struct.matrix, ptr %1, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !14
  call void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %10, i32 noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !15
  br label %13

13:                                               ; preds = %50, %2
  %14 = load i32, ptr %6, align 4, !tbaa !15
  %15 = getelementptr inbounds %struct.matrix, ptr %0, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %53

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %20

20:                                               ; preds = %46, %19
  %21 = load i32, ptr %8, align 4, !tbaa !15
  %22 = getelementptr inbounds %struct.matrix, ptr %0, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %49

26:                                               ; preds = %20
  %27 = getelementptr inbounds %struct.matrix, ptr %1, i32 0, i32 2
  %28 = load i32, ptr %8, align 4, !tbaa !15
  %29 = getelementptr inbounds %struct.matrix, ptr %1, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = mul nsw i32 %28, %30
  %32 = load i32, ptr %6, align 4, !tbaa !15
  %33 = add nsw i32 %31, %32
  %34 = sext i32 %33 to i64
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIxEixEm(ptr noundef nonnull align 8 dereferenceable(16) %27, i64 noundef %34) #3
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = getelementptr inbounds %struct.matrix, ptr %0, i32 0, i32 2
  %38 = load i32, ptr %6, align 4, !tbaa !15
  %39 = getelementptr inbounds %struct.matrix, ptr %0, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = mul nsw i32 %38, %40
  %42 = load i32, ptr %8, align 4, !tbaa !15
  %43 = add nsw i32 %41, %42
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIxEixEm(ptr noundef nonnull align 8 dereferenceable(16) %37, i64 noundef %44) #3
  store i64 %36, ptr %45, align 8, !tbaa !16
  br label %46

46:                                               ; preds = %26
  %47 = load i32, ptr %8, align 4, !tbaa !15
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !15
  br label %20, !llvm.loop !18

49:                                               ; preds = %25
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %6, align 4, !tbaa !15
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !15
  br label %13, !llvm.loop !20

53:                                               ; preds = %18
  store i1 true, ptr %5, align 1
  store i32 1, ptr %7, align 4
  %54 = load i1, ptr %5, align 1
  br i1 %54, label %56, label %55

55:                                               ; preds = %53
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  br label %56

56:                                               ; preds = %55, %53
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 #3 = { 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, !11, i64 4}
!10 = !{!"_ZTS6matrix", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt8valarrayIxE", !13, i64 0, !6, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

%struct.matrix = type { i32, i32, %"class.std::valarray" }
%"class.std::valarray" = type { i64, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIxEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10transposed6matrix(ptr dead_on_unwind noalias nonnull writable sret(%struct.matrix) align 8 %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %1, align 8, !tbaa !13
  tail call void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %4, i32 noundef %5)
  %6 = load i32, ptr %0, align 8, !tbaa !13
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.lr.ph, label %._crit_edge11

.preheader.lr.ph:                                 ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %8, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.preheader, label %._crit_edge11

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %13 = phi i32 [ %16, %._crit_edge ], [ %6, %.preheader.lr.ph ]
  %14 = phi i32 [ %17, %._crit_edge ], [ %11, %.preheader.lr.ph ]
  %.0810 = phi i32 [ %18, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %0, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %16 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %13, %.preheader ]
  %17 = phi i32 [ %32, %._crit_edge.loopexit ], [ %14, %.preheader ]
  %18 = add nuw nsw i32 %.0810, 1
  %19 = icmp slt i32 %18, %16
  br i1 %19, label %.preheader, label %._crit_edge11, !llvm.loop !14

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.09 = phi i32 [ %31, %.lr.ph ], [ 0, %.preheader ]
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = mul nsw i32 %20, %.09
  %22 = add nsw i32 %21, %.0810
  %23 = sext i32 %22 to i64
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIxEixEm(ptr noundef nonnull align 8 dereferenceable(16) %9, i64 noundef %23) #2
  %25 = load i64, ptr %24, align 8, !tbaa !17
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = mul nsw i32 %26, %.0810
  %28 = add nsw i32 %27, %.09
  %29 = sext i32 %28 to i64
  %30 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIxEixEm(ptr noundef nonnull align 8 dereferenceable(16) %10, i64 noundef %29) #2
  store i64 %25, ptr %30, align 8, !tbaa !17
  %31 = add nuw nsw i32 %.09, 1
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !19

._crit_edge11:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %2
  ret void
}

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 = { inlinehint 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 #2 = { 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, !7, i64 4}
!6 = !{!"_ZTS6matrix", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt8valarrayIxE", !11, i64 0, !12, i64 8}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15, !16}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.unswitch.partial.disable"}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !8, i64 0}
!19 = distinct !{!19, !15}


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