; LLVM IR from sbu-fsl/kernel-ml :: src/models (model)

; 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.model_multithreading = type { [32 x %struct.mt_buffer], [32 x i32], i32, i32, i32, i64, ptr }
%struct.mt_buffer = type { ptr, ptr }
%struct.model_data = type { ptr, ptr, ptr, ptr }

; 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
define dso_local void @set_data_async(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %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
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %25, %2
  br label %11

11:                                               ; preds = %15, %10
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.model_multithreading, ptr %12, i32 0, i32 4
  %14 = call i32 @kml_atomic_int_read(ptr noundef %13)
  store i32 %14, ptr %8, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %11
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 32
  br i1 %17, label %11, label %18, !llvm.loop !11

18:                                               ; preds = %15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.model_multithreading, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  %23 = call i32 @kml_atomic_cmpxchg(ptr noundef %20, ptr noundef %8, i32 noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %18
  br label %10

26:                                               ; preds = %18
  br label %27

27:                                               ; preds = %31, %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.model_multithreading, ptr %28, i32 0, i32 2
  %30 = call i32 @kml_atomic_int_read(ptr noundef %29)
  store i32 %30, ptr %7, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.model_multithreading, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  %36 = srem i32 %35, 32
  %37 = call i32 @kml_atomic_cmpxchg(ptr noundef %33, ptr noundef %7, i32 noundef %36)
  %38 = icmp ne i32 %37, 0
  %39 = xor i1 %38, true
  br i1 %39, label %27, label %40, !llvm.loop !13

40:                                               ; preds = %31
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.model_data, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  store ptr %43, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.model_data, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  store ptr %46, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.model_multithreading, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [32 x %struct.mt_buffer], ptr %48, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.mt_buffer, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.model_data, ptr %54, i32 0, i32 2
  store ptr %53, ptr %55, align 8, !tbaa !14
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.model_multithreading, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [32 x %struct.mt_buffer], ptr %57, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.mt_buffer, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.model_data, ptr %63, i32 0, i32 3
  store ptr %62, ptr %64, align 8, !tbaa !16
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.model_multithreading, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [32 x %struct.mt_buffer], ptr %67, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.mt_buffer, ptr %70, i32 0, i32 0
  store ptr %65, ptr %71, align 8, !tbaa !17
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.model_multithreading, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [32 x %struct.mt_buffer], ptr %74, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.mt_buffer, ptr %77, i32 0, i32 1
  store ptr %72, ptr %78, align 8, !tbaa !19
  br label %79

79:                                               ; preds = %80, %40
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.model_multithreading, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [32 x i32], ptr %82, i64 0, i64 %84
  %86 = call i32 @kml_atomic_cmpxchg(ptr noundef %85, ptr noundef %9, i32 noundef 1)
  %87 = icmp ne i32 %86, 0
  %88 = xor i1 %87, true
  br i1 %88, label %79, label %89, !llvm.loop !20

89:                                               ; preds = %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare i32 @kml_atomic_int_read(ptr noundef) #2

declare i32 @kml_atomic_cmpxchg(ptr noundef, ptr noundef, i32 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 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !6, i64 16}
!15 = !{!"model_data", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!15, !6, i64 24}
!17 = !{!18, !6, i64 0}
!18 = !{!"mt_buffer", !6, i64 0, !6, i64 8}
!19 = !{!18, !6, i64 8}
!20 = distinct !{!20, !12}


; 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.mt_buffer = type { ptr, ptr }

; 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
define dso_local void @set_data_async(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 648
  br label %7

7:                                                ; preds = %.backedge, %2
  %8 = call i32 @kml_atomic_int_read(ptr noundef nonnull %6) #3
  store i32 %8, ptr %4, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 32
  br i1 %9, label %.backedge, label %10

.backedge:                                        ; preds = %7, %10
  br label %7, !llvm.loop !9

10:                                               ; preds = %7
  %11 = add nsw i32 %8, 1
  %12 = call i32 @kml_atomic_cmpxchg(ptr noundef nonnull %6, ptr noundef nonnull %4, i32 noundef %11) #3
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %.backedge, label %.preheader

.preheader:                                       ; preds = %10
  %13 = getelementptr inbounds i8, ptr %1, i64 640
  br label %14

14:                                               ; preds = %.preheader, %14
  %15 = call i32 @kml_atomic_int_read(ptr noundef nonnull %13) #3
  store i32 %15, ptr %3, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = srem i32 %16, 32
  %18 = call i32 @kml_atomic_cmpxchg(ptr noundef nonnull %13, ptr noundef nonnull %3, i32 noundef %17) #3
  %.not15 = icmp eq i32 %18, 0
  br i1 %.not15, label %14, label %19, !llvm.loop !11

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [32 x %struct.mt_buffer], ptr %1, i64 0, i64 %22
  %24 = load <2 x ptr>, ptr %23, align 8, !tbaa !12
  %25 = load <2 x ptr>, ptr %20, align 8, !tbaa !12
  store <2 x ptr> %24, ptr %20, align 8, !tbaa !12
  store <2 x ptr> %25, ptr %23, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %1, i64 512
  br label %27

27:                                               ; preds = %27, %19
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [32 x i32], ptr %26, i64 0, i64 %29
  %31 = call i32 @kml_atomic_cmpxchg(ptr noundef nonnull %30, ptr noundef nonnull %5, i32 noundef 1) #3
  %.not16 = icmp eq i32 %31, 0
  br i1 %.not16, label %27, label %32, !llvm.loop !14

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret void
}

declare i32 @kml_atomic_int_read(ptr noundef) local_unnamed_addr #2

declare i32 @kml_atomic_cmpxchg(ptr noundef, ptr noundef, i32 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass