; LLVM IR from Tiramisu-Compiler/tiramisu :: benchmarks/framework_benchmarking/linear_algebra/ppcg-gpu_sgemm (sgemm)

; 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 [21 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @sgemm(ptr noundef, ptr noundef, ptr noundef, float noundef, float noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %13 = call ptr @new_matrix(i32 noundef 3072, i32 noundef 3072)
  store ptr %13, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %14 = call ptr @new_matrix(i32 noundef 3072, i32 noundef 3072)
  store ptr %14, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %15 = call ptr @new_matrix(i32 noundef 3072, i32 noundef 3072)
  store ptr %15, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store float 3.000000e+00, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store float 2.000000e+00, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %26, %0
  %17 = load i32, ptr %7, align 4, !tbaa !11
  %18 = icmp slt i32 %17, 10
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %29

20:                                               ; preds = %16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load float, ptr %5, align 4, !tbaa !9
  %25 = load float, ptr %6, align 4, !tbaa !9
  call void @sgemm(ptr noundef %21, ptr noundef %22, ptr noundef %23, float noundef %24, float noundef %25)
  br label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %7, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %7, align 4, !tbaa !11
  br label %16, !llvm.loop !13

29:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 100, ptr %8, align 4, !tbaa !11
  %30 = load i32, ptr %8, align 4, !tbaa !11
  %31 = zext i32 %30 to i64
  %32 = call ptr @llvm.stacksave.p0()
  store ptr %32, ptr %9, align 8
  %33 = alloca i64, i64 %31, align 16
  store i64 %31, ptr %10, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %52, %29
  %35 = load i32, ptr %11, align 4, !tbaa !11
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %55

39:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %40 = call i64 @clock() #5
  store i64 %40, ptr %12, align 8, !tbaa !15
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load float, ptr %5, align 4, !tbaa !9
  %45 = load float, ptr %6, align 4, !tbaa !9
  call void @sgemm(ptr noundef %41, ptr noundef %42, ptr noundef %43, float noundef %44, float noundef %45)
  %46 = call i64 @clock() #5
  %47 = load i64, ptr %12, align 8, !tbaa !15
  %48 = sub nsw i64 %46, %47
  %49 = load i32, ptr %11, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i64, ptr %33, i64 %50
  store i64 %48, ptr %51, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %52

52:                                               ; preds = %39
  %53 = load i32, ptr %11, align 4, !tbaa !11
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %11, align 4, !tbaa !11
  br label %34, !llvm.loop !17

55:                                               ; preds = %38
  %56 = load i32, ptr %8, align 4, !tbaa !11
  %57 = sext i32 %56 to i64
  call void @qsort(ptr noundef %33, i64 noundef %57, i64 noundef 8, ptr noundef @clock_t_comparator)
  %58 = load i32, ptr %8, align 4, !tbaa !11
  %59 = sdiv i32 %58, 2
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i64, ptr %33, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !15
  %63 = sitofp i64 %62 to float
  %64 = fdiv float %63, 1.000000e+06
  %65 = fmul float %64, 1.000000e+03
  %66 = fpext float %65 to double
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %66)
  %68 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %68)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %69 = load i32, ptr %1, align 4
  ret i32 %69
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nounwind
declare i64 @clock() #3

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !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"

@.str = external hidden unnamed_addr constant [21 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @sgemm(ptr noundef, ptr noundef, ptr noundef, float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call ptr @new_matrix(i32 noundef 3072, i32 noundef 3072)
  %2 = tail call ptr @new_matrix(i32 noundef 3072, i32 noundef 3072)
  %3 = tail call ptr @new_matrix(i32 noundef 3072, i32 noundef 3072)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  %4 = alloca [100 x i64], align 16
  br label %13

5:                                                ; preds = %13
  call void @qsort(ptr noundef nonnull %4, i64 noundef 100, i64 noundef 8, ptr noundef nonnull @clock_t_comparator) #4
  %6 = getelementptr inbounds i8, ptr %4, i64 400
  %7 = load i64, ptr %6, align 16, !tbaa !5
  %8 = sitofp i64 %7 to float
  %9 = fdiv float %8, 1.000000e+06
  %10 = fmul float %9, 1.000000e+03
  %11 = fpext float %10 to double
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %11)
  ret i32 0

13:                                               ; preds = %0, %13
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %13 ]
  %14 = tail call i64 @clock() #4
  tail call void @sgemm(ptr noundef %1, ptr noundef %2, ptr noundef %3, float noundef 3.000000e+00, float noundef 2.000000e+00)
  %15 = tail call i64 @clock() #4
  %16 = sub nsw i64 %15, %14
  %17 = getelementptr inbounds i64, ptr %4, i64 %indvars.iv
  store i64 %16, ptr %17, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond.not, label %5, label %13, !llvm.loop !9
}

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #1

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

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

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 = { 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 = { nofree "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 = { 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 = !{!"long", !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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass