; LLVM IR from bytecodealliance/sightglass :: benchmarks/shootout/src (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"

@.str = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [94 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [81 x i8], align 1
@black_box = external hidden global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 10, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 10, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = call ptr @mkmatrix(i32 noundef %9, i32 noundef %10)
  store ptr %11, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = call ptr @mkmatrix(i32 noundef %12, i32 noundef %13)
  store ptr %14, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = call ptr @mkmatrix(i32 noundef %15, i32 noundef %16)
  store ptr %17, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %27

20:                                               ; preds = %0
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %27

23:                                               ; preds = %20
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  br label %28

27:                                               ; preds = %23, %20, %0
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 60, ptr noundef @__PRETTY_FUNCTION__.main) #5
  unreachable

28:                                               ; preds = %26
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %29, i32 noundef %30, i32 noundef 300000)
  call void (...) @bench_start()
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %42, %28
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 300000
  br i1 %34, label %35, label %45

35:                                               ; preds = %32
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = call ptr @mmult(i32 noundef %36, i32 noundef %37, ptr noundef %38, ptr noundef %39, ptr noundef %40)
  store ptr %41, ptr %6, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %35
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %7, align 4, !tbaa !5
  br label %32, !llvm.loop !11

45:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds ptr, ptr %46, i64 0
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = getelementptr inbounds i32, ptr %48, i64 0
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = getelementptr inbounds ptr, ptr %51, i64 2
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds i32, ptr %53, i64 3
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = add nsw i32 %50, %55
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  %58 = getelementptr inbounds ptr, ptr %57, i64 3
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds i32, ptr %59, i64 2
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = add nsw i32 %56, %61
  %63 = load ptr, ptr %6, align 8, !tbaa !9
  %64 = getelementptr inbounds ptr, ptr %63, i64 4
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds i32, ptr %65, i64 4
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = add nsw i32 %62, %67
  store i32 %68, ptr %8, align 4, !tbaa !5
  call void (...) @bench_end()
  %69 = load volatile ptr, ptr @black_box, align 8, !tbaa !9
  call void %69(ptr noundef %8)
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %70)
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  call void @freematrix(i32 noundef %72, ptr noundef %73)
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  call void @freematrix(i32 noundef %74, ptr noundef %75)
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = load ptr, ptr %6, align 8, !tbaa !9
  call void @freematrix(i32 noundef %76, ptr noundef %77)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %78 = load i32, ptr %1, align 4
  ret i32 %78
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @mkmatrix(i32 noundef, i32 noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #3

declare void @bench_start(...) #3

; Function Attrs: nounwind uwtable
declare hidden ptr @mmult(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #0

declare void @bench_end(...) #3

; Function Attrs: nounwind uwtable
declare hidden void @freematrix(i32 noundef, ptr noundef) #0

; 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 = { noreturn 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 #3 = { "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 = { noreturn 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 = !{!"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"}


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

@.str = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [94 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [81 x i8], align 1
@black_box = external hidden global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = tail call ptr @mkmatrix(i32 noundef 10, i32 noundef 10)
  %3 = tail call ptr @mkmatrix(i32 noundef 10, i32 noundef 10)
  %4 = tail call ptr @mkmatrix(i32 noundef 10, i32 noundef 10)
  %5 = icmp ne ptr %2, null
  %6 = icmp ne ptr %3, null
  %or.cond = select i1 %5, i1 %6, i1 false
  %7 = icmp ne ptr %4, null
  %or.cond3 = select i1 %or.cond, i1 %7, i1 false
  br i1 %or.cond3, label %9, label %8

8:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 60, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #5
  unreachable

9:                                                ; preds = %0
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 10, i32 noundef 10, i32 noundef 300000)
  tail call void (...) @bench_start() #6
  br label %11

11:                                               ; preds = %9, %11
  %.036 = phi i32 [ 0, %9 ], [ %13, %11 ]
  %.03135 = phi ptr [ %4, %9 ], [ %12, %11 ]
  %12 = tail call ptr @mmult(i32 noundef 10, i32 noundef 10, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef %.03135)
  %13 = add nuw nsw i32 %.036, 1
  %exitcond.not = icmp eq i32 %13, 300000
  br i1 %exitcond.not, label %14, label %11, !llvm.loop !5

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %15 = load ptr, ptr %12, align 8, !tbaa !7
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %12, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !7
  %19 = getelementptr inbounds i8, ptr %18, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = add nsw i32 %20, %16
  %22 = getelementptr inbounds i8, ptr %12, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !7
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = add nsw i32 %21, %25
  %27 = getelementptr inbounds i8, ptr %12, i64 32
  %28 = load ptr, ptr %27, align 8, !tbaa !7
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = add nsw i32 %26, %30
  store i32 %31, ptr %1, align 4, !tbaa !11
  tail call void (...) @bench_end() #6
  %32 = load volatile ptr, ptr @black_box, align 8, !tbaa !7
  call void %32(ptr noundef nonnull %1) #6
  %33 = load i32, ptr %1, align 4, !tbaa !11
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %33)
  call void @freematrix(i32 noundef 10, ptr noundef nonnull %2)
  call void @freematrix(i32 noundef 10, ptr noundef nonnull %3)
  call void @freematrix(i32 noundef 10, ptr noundef nonnull %12)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @mkmatrix(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

declare void @bench_start(...) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden ptr @mmult(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @bench_end(...) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @freematrix(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn 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 #3 = { 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 #4 = { "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 #5 = { noreturn nounwind }
attributes #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass