; LLVM IR from onnx/onnx-mlir :: docs/mnist_example (mnist)

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

@__const.main.shape = external hidden unnamed_addr constant [4 x i64], align 16
@_ZL8img_data = external hidden global [784 x float], align 16
@.str.16 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [17 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: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca [4 x i64], align 16
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca float, align 4
  %14 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = call ptr @llvm.stacksave.p0()
  store ptr %17, ptr %3, align 8
  %18 = alloca ptr, i64 %16, align 16
  store i64 %16, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 4, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.main.shape, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %19 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = call ptr @omTensorCreate(ptr noundef @_ZL8img_data, ptr noundef %19, i64 noundef %20, i32 noundef 1)
  store ptr %21, ptr %7, align 8, !tbaa !11
  %22 = load ptr, ptr %7, align 8, !tbaa !11
  %23 = getelementptr inbounds ptr, ptr %18, i64 0
  store ptr %22, ptr %23, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = call ptr @omTensorListCreate(ptr noundef %18, i64 noundef %25)
  store ptr %26, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %27 = load ptr, ptr %8, align 8, !tbaa !11
  %28 = call ptr @run_main_graph(ptr noundef %27)
  store ptr %28, ptr %9, align 8, !tbaa !11
  %29 = load ptr, ptr %8, align 8, !tbaa !11
  call void @omTensorListDestroy(ptr noundef %29)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %30 = load ptr, ptr %9, align 8, !tbaa !11
  %31 = call ptr @omTensorListGetOmtByIndex(ptr noundef %30, i64 noundef 0)
  store ptr %31, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %32 = load ptr, ptr %10, align 8, !tbaa !11
  %33 = call ptr @omTensorGetDataPtr(ptr noundef %32)
  store ptr %33, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 -1, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store float 0.000000e+00, ptr %13, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %62, %0
  %35 = load i32, ptr %14, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 10
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %34
  %39 = load i32, ptr %14, align 4, !tbaa !5
  %40 = load ptr, ptr %11, align 8, !tbaa !11
  %41 = load i32, ptr %14, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds float, ptr %40, i64 %42
  %44 = load float, ptr %43, align 4, !tbaa !13
  %45 = fpext float %44 to double
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.16, i32 noundef %39, double noundef %45)
  %47 = load ptr, ptr %11, align 8, !tbaa !11
  %48 = load i32, ptr %14, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds float, ptr %47, i64 %49
  %51 = load float, ptr %50, align 4, !tbaa !13
  %52 = load float, ptr %13, align 4, !tbaa !13
  %53 = fcmp ogt float %51, %52
  br i1 %53, label %54, label %61

54:                                               ; preds = %38
  %55 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %55, ptr %12, align 4, !tbaa !5
  %56 = load ptr, ptr %11, align 8, !tbaa !11
  %57 = load i32, ptr %14, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds float, ptr %56, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !13
  store float %60, ptr %13, align 4, !tbaa !13
  br label %61

61:                                               ; preds = %54, %38
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %14, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %14, align 4, !tbaa !5
  br label %34, !llvm.loop !15

65:                                               ; preds = %37
  %66 = load ptr, ptr %9, align 8, !tbaa !11
  call void @omTensorListDestroy(ptr noundef %66)
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.17, i32 noundef %67)
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %69 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %69)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %70 = load i32, ptr %1, align 4
  ret i32 %70
}

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

; 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) #3

declare ptr @omTensorCreate(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #4

declare ptr @omTensorListCreate(ptr noundef, i64 noundef) #4

declare ptr @run_main_graph(ptr noundef) #4

declare void @omTensorListDestroy(ptr noundef) #4

declare ptr @omTensorListGetOmtByIndex(ptr noundef, i64 noundef) #4

declare ptr @omTensorGetDataPtr(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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress norecurse 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 nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@__const.main.shape = external hidden unnamed_addr constant [4 x i64], align 16
@_ZL8img_data = external hidden global [784 x float], align 16
@.str.16 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [17 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca [4 x i64], align 16
  %2 = alloca ptr, align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %1, ptr noundef nonnull align 16 dereferenceable(32) @__const.main.shape, i64 32, i1 false)
  %3 = call ptr @omTensorCreate(ptr noundef nonnull @_ZL8img_data, ptr noundef nonnull %1, i64 noundef 4, i32 noundef 1)
  store ptr %3, ptr %2, align 16, !tbaa !5
  %4 = call ptr @omTensorListCreate(ptr noundef nonnull %2, i64 noundef 1)
  %5 = call ptr @run_main_graph(ptr noundef %4)
  call void @omTensorListDestroy(ptr noundef %4)
  %6 = call ptr @omTensorListGetOmtByIndex(ptr noundef %5, i64 noundef 0)
  %7 = call ptr @omTensorGetDataPtr(ptr noundef %6)
  %8 = load float, ptr %7, align 4, !tbaa !9
  %9 = fpext float %8 to double
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 0, double noundef %9)
  %11 = load float, ptr %7, align 4, !tbaa !9
  %12 = fcmp ule float %11, 0.000000e+00
  %.124 = sext i1 %12 to i32
  %.1 = select i1 %12, float 0.000000e+00, float %11
  %13 = getelementptr inbounds i8, ptr %7, i64 4
  %14 = load float, ptr %13, align 4, !tbaa !9
  %15 = fpext float %14 to double
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 1, double noundef %15)
  %17 = load float, ptr %13, align 4, !tbaa !9
  %18 = fcmp ogt float %17, %.1
  %.124.1 = select i1 %18, i32 1, i32 %.124
  %.1.1 = select i1 %18, float %17, float %.1
  %19 = getelementptr inbounds i8, ptr %7, i64 8
  %20 = load float, ptr %19, align 4, !tbaa !9
  %21 = fpext float %20 to double
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 2, double noundef %21)
  %23 = load float, ptr %19, align 4, !tbaa !9
  %24 = fcmp ogt float %23, %.1.1
  %.124.2 = select i1 %24, i32 2, i32 %.124.1
  %.1.2 = select i1 %24, float %23, float %.1.1
  %25 = getelementptr inbounds i8, ptr %7, i64 12
  %26 = load float, ptr %25, align 4, !tbaa !9
  %27 = fpext float %26 to double
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 3, double noundef %27)
  %29 = load float, ptr %25, align 4, !tbaa !9
  %30 = fcmp ogt float %29, %.1.2
  %.124.3 = select i1 %30, i32 3, i32 %.124.2
  %.1.3 = select i1 %30, float %29, float %.1.2
  %31 = getelementptr inbounds i8, ptr %7, i64 16
  %32 = load float, ptr %31, align 4, !tbaa !9
  %33 = fpext float %32 to double
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 4, double noundef %33)
  %35 = load float, ptr %31, align 4, !tbaa !9
  %36 = fcmp ogt float %35, %.1.3
  %.124.4 = select i1 %36, i32 4, i32 %.124.3
  %.1.4 = select i1 %36, float %35, float %.1.3
  %37 = getelementptr inbounds i8, ptr %7, i64 20
  %38 = load float, ptr %37, align 4, !tbaa !9
  %39 = fpext float %38 to double
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 5, double noundef %39)
  %41 = load float, ptr %37, align 4, !tbaa !9
  %42 = fcmp ogt float %41, %.1.4
  %.124.5 = select i1 %42, i32 5, i32 %.124.4
  %.1.5 = select i1 %42, float %41, float %.1.4
  %43 = getelementptr inbounds i8, ptr %7, i64 24
  %44 = load float, ptr %43, align 4, !tbaa !9
  %45 = fpext float %44 to double
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 6, double noundef %45)
  %47 = load float, ptr %43, align 4, !tbaa !9
  %48 = fcmp ogt float %47, %.1.5
  %.124.6 = select i1 %48, i32 6, i32 %.124.5
  %.1.6 = select i1 %48, float %47, float %.1.5
  %49 = getelementptr inbounds i8, ptr %7, i64 28
  %50 = load float, ptr %49, align 4, !tbaa !9
  %51 = fpext float %50 to double
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 7, double noundef %51)
  %53 = load float, ptr %49, align 4, !tbaa !9
  %54 = fcmp ogt float %53, %.1.6
  %.124.7 = select i1 %54, i32 7, i32 %.124.6
  %.1.7 = select i1 %54, float %53, float %.1.6
  %55 = getelementptr inbounds i8, ptr %7, i64 32
  %56 = load float, ptr %55, align 4, !tbaa !9
  %57 = fpext float %56 to double
  %58 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 8, double noundef %57)
  %59 = load float, ptr %55, align 4, !tbaa !9
  %60 = fcmp ogt float %59, %.1.7
  %.124.8 = select i1 %60, i32 8, i32 %.124.7
  %.1.8 = select i1 %60, float %59, float %.1.7
  %61 = getelementptr inbounds i8, ptr %7, i64 36
  %62 = load float, ptr %61, align 4, !tbaa !9
  %63 = fpext float %62 to double
  %64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef 9, double noundef %63)
  %65 = load float, ptr %61, align 4, !tbaa !9
  %66 = fcmp ogt float %65, %.1.8
  %.124.9 = select i1 %66, i32 9, i32 %.124.8
  call void @omTensorListDestroy(ptr noundef %5)
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17, i32 noundef %.124.9)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #5
  ret i32 0
}

; Function Attrs: mustprogress 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

declare ptr @omTensorCreate(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

declare ptr @omTensorListCreate(ptr noundef, i64 noundef) local_unnamed_addr #3

declare ptr @run_main_graph(ptr noundef) local_unnamed_addr #3

declare void @omTensorListDestroy(ptr noundef) local_unnamed_addr #3

declare ptr @omTensorListGetOmtByIndex(ptr noundef, i64 noundef) local_unnamed_addr #3

declare ptr @omTensorGetDataPtr(ptr noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress norecurse 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,SROAPass,SimplifyCFGPass