; LLVM IR from ggml-org/ggml :: tests (test-cont)

; 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.ggml_bf16_t = type { i16 }
%struct.model = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@__const.test_cont.buf_f32 = external hidden unnamed_addr constant [2 x float], align 4
@__const.test_cont.expected_out = external hidden unnamed_addr constant [2 x float], align 4

; 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 uwtable
declare dso_local void @model_init(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @model_alloc(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @model_compute(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @model_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @check_tensor(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare i64 @ggml_nbytes(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @test_cont() #1 {
  %1 = alloca [2 x float], align 4
  %2 = alloca [2 x i16], align 2
  %3 = alloca [2 x %struct.ggml_bf16_t], align 2
  %4 = alloca [2 x float], align 4
  %5 = alloca %struct.model, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %1, ptr align 4 @__const.test_cont.buf_f32, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %10 = getelementptr inbounds [2 x float], ptr %1, i64 0, i64 0
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = call zeroext i16 @ggml_fp32_to_fp16(float noundef %11)
  store i16 %12, ptr %2, align 2, !tbaa !9
  %13 = getelementptr inbounds i16, ptr %2, i64 1
  %14 = getelementptr inbounds [2 x float], ptr %1, i64 0, i64 1
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = call zeroext i16 @ggml_fp32_to_fp16(float noundef %15)
  store i16 %16, ptr %13, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %17 = getelementptr inbounds [2 x float], ptr %1, i64 0, i64 0
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = call i16 @ggml_fp32_to_bf16(float noundef %18)
  %20 = getelementptr inbounds %struct.ggml_bf16_t, ptr %3, i32 0, i32 0
  store i16 %19, ptr %20, align 2
  %21 = getelementptr inbounds %struct.ggml_bf16_t, ptr %3, i64 1
  %22 = getelementptr inbounds [2 x float], ptr %1, i64 0, i64 1
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = call i16 @ggml_fp32_to_bf16(float noundef %23)
  %25 = getelementptr inbounds %struct.ggml_bf16_t, ptr %21, i32 0, i32 0
  store i16 %24, ptr %25, align 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 @__const.test_cont.expected_out, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 56, ptr %5) #4
  call void @model_init(ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %26 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = call ptr @ggml_new_tensor_1d(ptr noundef %27, i32 noundef 0, i64 noundef 2)
  store ptr %28, ptr %6, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %29 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = call ptr @ggml_new_tensor_1d(ptr noundef %30, i32 noundef 1, i64 noundef 2)
  store ptr %31, ptr %7, align 8, !tbaa !14
  call void @model_alloc(ptr noundef %5)
  %32 = load ptr, ptr %6, align 8, !tbaa !14
  %33 = getelementptr inbounds [2 x float], ptr %1, i64 0, i64 0
  %34 = load ptr, ptr %6, align 8, !tbaa !14
  %35 = call i64 @ggml_nbytes(ptr noundef %34)
  call void @ggml_backend_tensor_set(ptr noundef %32, ptr noundef %33, i64 noundef 0, i64 noundef %35)
  %36 = load ptr, ptr %7, align 8, !tbaa !14
  %37 = getelementptr inbounds [2 x i16], ptr %2, i64 0, i64 0
  %38 = load ptr, ptr %7, align 8, !tbaa !14
  %39 = call i64 @ggml_nbytes(ptr noundef %38)
  call void @ggml_backend_tensor_set(ptr noundef %36, ptr noundef %37, i64 noundef 0, i64 noundef %39)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %40 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %6, align 8, !tbaa !14
  %45 = call ptr @ggml_transpose(ptr noundef %43, ptr noundef %44)
  %46 = call ptr @ggml_cont(ptr noundef %41, ptr noundef %45)
  store ptr %46, ptr %8, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %47 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = load ptr, ptr %7, align 8, !tbaa !14
  %52 = call ptr @ggml_transpose(ptr noundef %50, ptr noundef %51)
  %53 = call ptr @ggml_cont(ptr noundef %48, ptr noundef %52)
  store ptr %53, ptr %9, align 8, !tbaa !14
  %54 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load ptr, ptr %8, align 8, !tbaa !14
  call void @ggml_build_forward_expand(ptr noundef %55, ptr noundef %56)
  %57 = getelementptr inbounds %struct.model, ptr %5, i32 0, i32 4
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %9, align 8, !tbaa !14
  call void @ggml_build_forward_expand(ptr noundef %58, ptr noundef %59)
  call void @model_compute(ptr noundef %5)
  %60 = load ptr, ptr %8, align 8, !tbaa !14
  %61 = getelementptr inbounds [2 x float], ptr %4, i64 0, i64 0
  call void @check_tensor(ptr noundef %60, ptr noundef %61, i32 noundef 1, i32 noundef 2, i32 noundef 1)
  %62 = load ptr, ptr %9, align 8, !tbaa !14
  %63 = getelementptr inbounds [2 x float], ptr %4, i64 0, i64 0
  call void @check_tensor(ptr noundef %62, ptr noundef %63, i32 noundef 1, i32 noundef 2, i32 noundef 1)
  call void @model_free(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 56, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; 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 zeroext i16 @ggml_fp32_to_fp16(float noundef) #2

declare i16 @ggml_fp32_to_bf16(float noundef) #2

declare ptr @ggml_new_tensor_1d(ptr noundef, i32 noundef, i64 noundef) #2

declare void @ggml_backend_tensor_set(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #2

declare ptr @ggml_cont(ptr noundef, ptr noundef) #2

declare ptr @ggml_transpose(ptr noundef, ptr noundef) #2

declare void @ggml_build_forward_expand(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"model", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !13, i64 32}


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

%struct.model = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@__const.test_cont.buf_f32 = external hidden unnamed_addr constant [2 x float], align 4
@__const.test_cont.expected_out = external hidden unnamed_addr constant [2 x float], align 4

; 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: nounwind uwtable
declare dso_local void @model_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @model_alloc(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @model_compute(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @model_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @check_tensor(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i64 @ggml_nbytes(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @test_cont() local_unnamed_addr #1 {
  %1 = alloca [2 x float], align 8
  %2 = alloca [2 x i16], align 2
  %3 = alloca [2 x float], align 8
  %4 = alloca %struct.model, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %5 = load i64, ptr @__const.test_cont.buf_f32, align 4
  store i64 %5, ptr %1, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %6 = trunc i64 %5 to i32
  %7 = bitcast i32 %6 to float
  %8 = tail call zeroext i16 @ggml_fp32_to_fp16(float noundef %7) #3
  store i16 %8, ptr %2, align 2, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %2, i64 2
  %10 = lshr i64 %5, 32
  %11 = trunc nuw i64 %10 to i32
  %12 = bitcast i32 %11 to float
  %13 = tail call zeroext i16 @ggml_fp32_to_fp16(float noundef %12) #3
  store i16 %13, ptr %9, align 2, !tbaa !5
  %14 = tail call i16 @ggml_fp32_to_bf16(float noundef %7) #3
  %15 = tail call i16 @ggml_fp32_to_bf16(float noundef %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %16 = load i64, ptr @__const.test_cont.expected_out, align 4
  store i64 %16, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %4) #3
  call void @model_init(ptr noundef nonnull %4)
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = call ptr @ggml_new_tensor_1d(ptr noundef %17, i32 noundef 0, i64 noundef 2) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = call ptr @ggml_new_tensor_1d(ptr noundef %19, i32 noundef 1, i64 noundef 2) #3
  call void @model_alloc(ptr noundef nonnull %4)
  %21 = call i64 @ggml_nbytes(ptr noundef %18) #3
  call void @ggml_backend_tensor_set(ptr noundef %18, ptr noundef nonnull %1, i64 noundef 0, i64 noundef %21) #3
  %22 = call i64 @ggml_nbytes(ptr noundef %20) #3
  call void @ggml_backend_tensor_set(ptr noundef %20, ptr noundef nonnull %2, i64 noundef 0, i64 noundef %22) #3
  %23 = getelementptr inbounds i8, ptr %4, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = call ptr @ggml_transpose(ptr noundef %24, ptr noundef %18) #3
  %26 = call ptr @ggml_cont(ptr noundef %24, ptr noundef %25) #3
  %27 = load ptr, ptr %23, align 8, !tbaa !12
  %28 = call ptr @ggml_transpose(ptr noundef %27, ptr noundef %20) #3
  %29 = call ptr @ggml_cont(ptr noundef %27, ptr noundef %28) #3
  %30 = getelementptr inbounds i8, ptr %4, i64 32
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  call void @ggml_build_forward_expand(ptr noundef %31, ptr noundef %26) #3
  %32 = load ptr, ptr %30, align 8, !tbaa !13
  call void @ggml_build_forward_expand(ptr noundef %32, ptr noundef %29) #3
  call void @model_compute(ptr noundef nonnull %4)
  call void @check_tensor(ptr noundef %26, ptr noundef nonnull %3, i32 noundef 1, i32 noundef 2, i32 noundef 1)
  call void @check_tensor(ptr noundef %29, ptr noundef nonnull %3, i32 noundef 1, i32 noundef 2, i32 noundef 1)
  call void @model_free(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret void
}

declare zeroext i16 @ggml_fp32_to_fp16(float noundef) local_unnamed_addr #2

declare i16 @ggml_fp32_to_bf16(float noundef) local_unnamed_addr #2

declare ptr @ggml_new_tensor_1d(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

declare void @ggml_backend_tensor_set(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

declare ptr @ggml_cont(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @ggml_transpose(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @ggml_build_forward_expand(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"model", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 32}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SCCPPass,SROAPass,TailCallElimPass