; LLVM IR from aacoppa/flaming-flamingos :: src/matrix (matrix)

; 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, ptr }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1

; 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local { i64, ptr } @multiply_matrix(i64 %0, ptr %1, i64 %2, ptr %3) #3 {
  %5 = alloca %struct.matrix, align 8
  %6 = alloca %struct.matrix, align 8
  %7 = alloca %struct.matrix, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = getelementptr inbounds { i64, ptr }, ptr %6, i32 0, i32 0
  store i64 %0, ptr %12, align 8
  %13 = getelementptr inbounds { i64, ptr }, ptr %6, i32 0, i32 1
  store ptr %1, ptr %13, align 8
  %14 = getelementptr inbounds { i64, ptr }, ptr %7, i32 0, i32 0
  store i64 %2, ptr %14, align 8
  %15 = getelementptr inbounds { i64, ptr }, ptr %7, i32 0, i32 1
  store ptr %3, ptr %15, align 8
  %16 = getelementptr inbounds %struct.matrix, ptr %6, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp ne i32 %17, %19
  br i1 %20, label %21, label %32

21:                                               ; preds = %4
  %22 = load ptr, ptr @stderr, align 8, !tbaa !12
  %23 = getelementptr inbounds %struct.matrix, ptr %6, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.matrix, ptr %6, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.1, i32 noundef %24, i32 noundef %26, i32 noundef %28, i32 noundef %30) #4
  br label %103

32:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %33 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = mul i64 8, %35
  %37 = call noalias ptr @malloc(i64 noundef %36) #5
  store ptr %37, ptr %8, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %53, %32
  %39 = load i32, ptr %9, align 4, !tbaa !13
  %40 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !5
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %43, label %56

43:                                               ; preds = %38
  %44 = getelementptr inbounds %struct.matrix, ptr %6, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = mul i64 8, %46
  %48 = call noalias ptr @malloc(i64 noundef %47) #5
  %49 = load ptr, ptr %8, align 8, !tbaa !12
  %50 = load i32, ptr %9, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  store ptr %48, ptr %52, align 8, !tbaa !12
  br label %53

53:                                               ; preds = %43
  %54 = load i32, ptr %9, align 4, !tbaa !13
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %9, align 4, !tbaa !13
  br label %38, !llvm.loop !14

56:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !13
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %57

57:                                               ; preds = %91, %56
  %58 = load i32, ptr %10, align 4, !tbaa !13
  %59 = getelementptr inbounds %struct.matrix, ptr %6, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !11
  %61 = icmp slt i32 %58, %60
  br i1 %61, label %62, label %94

62:                                               ; preds = %57
  br label %63

63:                                               ; preds = %68, %62
  %64 = load i32, ptr %11, align 4, !tbaa !13
  %65 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !5
  %67 = icmp slt i32 %64, %66
  br i1 %67, label %68, label %91

68:                                               ; preds = %63
  %69 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !16
  %71 = load i32, ptr %11, align 4, !tbaa !13
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds ptr, ptr %70, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !12
  %75 = load i32, ptr %10, align 4, !tbaa !13
  %76 = getelementptr inbounds { i64, ptr }, ptr %6, i32 0, i32 0
  %77 = load i64, ptr %76, align 8
  %78 = getelementptr inbounds { i64, ptr }, ptr %6, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8
  %80 = call double @col_x_row(ptr noundef %74, i64 %77, ptr %79, i32 noundef %75)
  %81 = load ptr, ptr %8, align 8, !tbaa !12
  %82 = load i32, ptr %11, align 4, !tbaa !13
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds ptr, ptr %81, i64 %83
  %85 = load ptr, ptr %84, align 8, !tbaa !12
  %86 = load i32, ptr %10, align 4, !tbaa !13
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds double, ptr %85, i64 %87
  store double %80, ptr %88, align 8, !tbaa !17
  %89 = load i32, ptr %11, align 4, !tbaa !13
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %11, align 4, !tbaa !13
  br label %63, !llvm.loop !19

91:                                               ; preds = %63
  %92 = load i32, ptr %10, align 4, !tbaa !13
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %10, align 4, !tbaa !13
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %57, !llvm.loop !20

94:                                               ; preds = %57
  %95 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 0
  %96 = load i32, ptr %95, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.matrix, ptr %5, i32 0, i32 0
  store i32 %96, ptr %97, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.matrix, ptr %6, i32 0, i32 1
  %99 = load i32, ptr %98, align 4, !tbaa !11
  %100 = getelementptr inbounds %struct.matrix, ptr %5, i32 0, i32 1
  store i32 %99, ptr %100, align 4, !tbaa !11
  %101 = load ptr, ptr %8, align 8, !tbaa !12
  %102 = getelementptr inbounds %struct.matrix, ptr %5, i32 0, i32 2
  store ptr %101, ptr %102, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %103

103:                                              ; preds = %94, %21
  %104 = load { i64, ptr }, ptr %5, align 8
  ret { i64, ptr } %104
}

; Function Attrs: nounwind uwtable
declare dso_local double @col_x_row(ptr noundef, i64, ptr, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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) "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 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 }
attributes #5 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!10, !10, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !10, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !15}
!20 = distinct !{!20, !15}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; 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

; Function Attrs: nounwind uwtable
define dso_local { i64, ptr } @multiply_matrix(i64 %0, ptr %1, i64 %2, ptr nocapture readonly %3) local_unnamed_addr #2 {
  %.sroa.018.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.4.0.extract.shift = lshr i64 %0, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %.sroa.0.0.extract.trunc = trunc i64 %2 to i32
  %.sroa.6.0.extract.shift = lshr i64 %2, 32
  %.sroa.6.0.extract.trunc = trunc nuw i64 %.sroa.6.0.extract.shift to i32
  %.not = icmp eq i32 %.sroa.018.0.extract.trunc, %.sroa.6.0.extract.trunc
  br i1 %.not, label %8, label %5

5:                                                ; preds = %4
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.1, i32 noundef %.sroa.018.0.extract.trunc, i32 noundef %.sroa.4.0.extract.trunc, i32 noundef %.sroa.0.0.extract.trunc, i32 noundef %.sroa.6.0.extract.trunc) #3
  br label %.loopexit

8:                                                ; preds = %4
  %sext = shl i64 %2, 32
  %9 = ashr exact i64 %sext, 29
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #4
  %11 = icmp slt i32 %.sroa.0.0.extract.trunc, 1
  br i1 %11, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %12 = ashr i64 %0, 29
  %13 = and i64 %12, -8
  %wide.trip.count = and i64 %2, 2147483647
  br label %23

.preheader29:                                     ; preds = %23
  %14 = icmp slt i32 %.sroa.4.0.extract.trunc, 1
  %brmerge = or i1 %14, %11
  br i1 %brmerge, label %.loopexit, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader29
  %wide.trip.count39 = and i64 %2, 2147483647
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv41 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next42, %._crit_edge.us ]
  %15 = trunc nuw nsw i64 %indvars.iv41 to i32
  br label %16

16:                                               ; preds = %.preheader.us, %16
  %indvars.iv36 = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next37, %16 ]
  %17 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv36
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = tail call double @col_x_row(ptr noundef %18, i64 %0, ptr %1, i32 noundef %15)
  %20 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv36
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds double, ptr %21, i64 %indvars.iv41
  store double %19, ptr %22, align 8, !tbaa !9
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count39
  br i1 %exitcond40.not, label %._crit_edge.us, label %16, !llvm.loop !11

._crit_edge.us:                                   ; preds = %16
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %.sroa.4.0.extract.shift
  br i1 %exitcond45.not, label %.loopexit, label %.preheader.us, !llvm.loop !13

23:                                               ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %24 = tail call noalias ptr @malloc(i64 noundef %13) #4
  %25 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv
  store ptr %24, ptr %25, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader29, label %23, !llvm.loop !14

.loopexit:                                        ; preds = %._crit_edge.us, %.preheader29, %8, %5
  %.sroa.3.0 = phi ptr [ undef, %5 ], [ %10, %.preheader29 ], [ %10, %8 ], [ %10, %._crit_edge.us ]
  %.sroa.2.0.insert.shift = and i64 %0, -4294967296
  %.sroa.025.0.insert.ext = and i64 %2, 4294967295
  %.sroa.025.0.insert.insert = or disjoint i64 %.sroa.025.0.insert.ext, %.sroa.2.0.insert.shift
  %.fca.0.insert = insertvalue { i64, ptr } poison, i64 %.sroa.025.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, ptr } %.fca.0.insert, ptr %.sroa.3.0, 1
  ret { i64, ptr } %.fca.1.insert
}

; Function Attrs: nounwind uwtable
declare dso_local double @col_x_row(ptr noundef, i64, ptr, i32 noundef) local_unnamed_addr #2

attributes #0 = { nofree nounwind "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 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 = { cold 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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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