; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (867)

; 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: nounwind uwtable
define dso_local ptr @transpose(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = mul i64 %19, 8
  %21 = call noalias ptr @malloc(i64 noundef %20) #4
  store ptr %21, ptr %12, align 8, !tbaa !5
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = mul i64 %23, 4
  %25 = call noalias ptr @malloc(i64 noundef %24) #4
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %25, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %74, %5
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %77

32:                                               ; preds = %27
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = mul i64 %34, 4
  %36 = call noalias ptr @malloc(i64 noundef %35) #4
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %37, i64 %39
  store ptr %36, ptr %40, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  store i32 %41, ptr %46, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %70, %32
  %48 = load i32, ptr %15, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %73

52:                                               ; preds = %47
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %15, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %53, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds ptr, ptr %62, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = load i32, ptr %15, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  store i32 %61, ptr %69, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %52
  %71 = load i32, ptr %15, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %15, align 4, !tbaa !9
  br label %47, !llvm.loop !11

73:                                               ; preds = %51
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %13, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %13, align 4, !tbaa !9
  br label %27, !llvm.loop !13

77:                                               ; preds = %31
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %78, ptr %79, align 4, !tbaa !9
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret ptr %80
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; 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 = { 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 #3 = { nounwind }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: nofree nounwind uwtable
define dso_local noalias noundef ptr @transpose(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 3
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #2
  %10 = shl nsw i64 %7, 2
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #2
  store ptr %11, ptr %4, align 8, !tbaa !9
  %12 = icmp sgt i32 %6, 0
  br i1 %12, label %.lr.ph29, label %._crit_edge30

.lr.ph29:                                         ; preds = %5
  %13 = sext i32 %1 to i64
  %14 = shl nsw i64 %13, 2
  %15 = icmp sgt i32 %1, 0
  %wide.trip.count41 = zext nneg i32 %6 to i64
  br i1 %15, label %.lr.ph.us.preheader, label %.lr.ph29.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph29
  %wide.trip.count36 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count36, 3
  %16 = icmp ult i32 %1, 4
  %unroll_iter = and i64 %wide.trip.count36, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv38 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next39, %._crit_edge.us ]
  %17 = tail call noalias ptr @malloc(i64 noundef %14) #2
  %18 = getelementptr inbounds ptr, ptr %9, i64 %indvars.iv38
  store ptr %17, ptr %18, align 8, !tbaa !9
  %19 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv38
  store i32 %1, ptr %19, align 4, !tbaa !5
  br i1 %16, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %indvars.iv33 = phi i64 [ %indvars.iv.next34.3, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.3, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %20 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv33
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv38
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv33
  store i32 %23, ptr %24, align 4, !tbaa !5
  %indvars.iv.next34 = or disjoint i64 %indvars.iv33, 1
  %25 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next34
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds i32, ptr %26, i64 %indvars.iv38
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv.next34
  store i32 %28, ptr %29, align 4, !tbaa !5
  %indvars.iv.next34.1 = or disjoint i64 %indvars.iv33, 2
  %30 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next34.1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds i32, ptr %31, i64 %indvars.iv38
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv.next34.1
  store i32 %33, ptr %34, align 4, !tbaa !5
  %indvars.iv.next34.2 = or disjoint i64 %indvars.iv33, 3
  %35 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next34.2
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds i32, ptr %36, i64 %indvars.iv38
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv.next34.2
  store i32 %38, ptr %39, align 4, !tbaa !5
  %indvars.iv.next34.3 = add nuw nsw i64 %indvars.iv33, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !11

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %indvars.iv33.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next34.3, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv33.epil = phi i64 [ %indvars.iv.next34.epil, %.epil.preheader ], [ %indvars.iv33.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %40 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv33.epil
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds i32, ptr %41, i64 %indvars.iv38
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv33.epil
  store i32 %43, ptr %44, align 4, !tbaa !5
  %indvars.iv.next34.epil = add nuw nsw i64 %indvars.iv33.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !13

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge30, label %.lr.ph.us, !llvm.loop !15

._crit_edge30:                                    ; preds = %.lr.ph29.split, %._crit_edge.us, %5
  store i32 %6, ptr %3, align 4, !tbaa !5
  ret ptr %9

.lr.ph29.split:                                   ; preds = %.lr.ph29, %.lr.ph29.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph29.split ], [ 0, %.lr.ph29 ]
  %45 = tail call noalias ptr @malloc(i64 noundef %14) #2
  %46 = getelementptr inbounds ptr, ptr %9, i64 %indvars.iv
  store ptr %45, ptr %46, align 8, !tbaa !9
  %47 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv
  store i32 %1, ptr %47, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count41
  br i1 %exitcond.not, label %._crit_edge30, label %.lr.ph29.split, !llvm.loop !15
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 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 #2 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !12}


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