; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

; 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: 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @r8mat_flip_cols_new(i32 noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = mul nsw i32 %10, %11
  %13 = sext i32 %12 to i64
  %14 = mul i64 %13, 8
  %15 = call noalias ptr @malloc(i64 noundef %14) #4
  store ptr %15, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %50, %3
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %53

20:                                               ; preds = %16
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %46, %20
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %49

25:                                               ; preds = %21
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = mul nsw i32 %28, %29
  %31 = add nsw i32 %27, %30
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %26, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = mul nsw i32 %40, %41
  %43 = add nsw i32 %36, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %35, i64 %44
  store double %34, ptr %45, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %25
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !5
  br label %21, !llvm.loop !13

49:                                               ; preds = %21
  br label %50

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

53:                                               ; preds = %16
  %54 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %54
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 }
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 = !{!"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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local noalias noundef ptr @r8mat_flip_cols_new(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = mul nsw i32 %1, %0
  %5 = sext i32 %4 to i64
  %6 = shl nsw i64 %5, 3
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #3
  %8 = icmp sgt i32 %1, 0
  %9 = icmp sgt i32 %0, 0
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge22

.preheader.us.preheader:                          ; preds = %3
  %10 = zext nneg i32 %0 to i64
  %11 = shl nuw nsw i64 %10, 3
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %12 = icmp eq i32 %1, 1
  br i1 %12, label %._crit_edge22.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.us.preheader.new
  %indvar = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvar.next.1, %.preheader.us ]
  %niter = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter.next.1, %.preheader.us ]
  %13 = trunc nuw nsw i64 %indvar to i32
  %14 = xor i32 %13, -1
  %15 = add i32 %14, %1
  %16 = mul i32 %15, %0
  %17 = sext i32 %16 to i64
  %18 = shl nsw i64 %17, 3
  %scevgep = getelementptr i8, ptr %7, i64 %18
  %19 = mul i64 %11, %indvar
  %scevgep24 = getelementptr i8, ptr %2, i64 %19
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %scevgep, ptr align 8 %scevgep24, i64 %11, i1 false), !tbaa !5
  %indvar.next = or disjoint i64 %indvar, 1
  %20 = trunc nuw nsw i64 %indvar.next to i32
  %21 = xor i32 %20, -1
  %22 = add i32 %21, %1
  %23 = mul i32 %22, %0
  %24 = sext i32 %23 to i64
  %25 = shl nsw i64 %24, 3
  %scevgep.1 = getelementptr i8, ptr %7, i64 %25
  %26 = mul i64 %11, %indvar.next
  %scevgep24.1 = getelementptr i8, ptr %2, i64 %26
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %scevgep.1, ptr align 8 %scevgep24.1, i64 %11, i1 false), !tbaa !5
  %indvar.next.1 = add nuw nsw i64 %indvar, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge22.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !9

._crit_edge22.loopexit.unr-lcssa:                 ; preds = %.preheader.us, %.preheader.us.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvar.next.1, %.preheader.us ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge22, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge22.loopexit.unr-lcssa
  %27 = trunc nuw nsw i64 %indvar.unr to i32
  %28 = xor i32 %27, -1
  %29 = add i32 %28, %1
  %30 = mul i32 %29, %0
  %31 = sext i32 %30 to i64
  %32 = shl nsw i64 %31, 3
  %scevgep.epil = getelementptr i8, ptr %7, i64 %32
  %33 = mul i64 %11, %indvar.unr
  %scevgep24.epil = getelementptr i8, ptr %2, i64 %33
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %scevgep.epil, ptr align 8 %scevgep24.epil, i64 %11, i1 false), !tbaa !5
  br label %._crit_edge22

._crit_edge22:                                    ; preds = %.preheader.us.epil, %._crit_edge22.loopexit.unr-lcssa, %3
  ret ptr %7
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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