; LLVM IR from clbx/Cosmic :: src/cosproc.ll (ZN7cosproc5cycleEv)

; 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.cosproc::Debug" = type { i32, %"struct.cosproc::Instruction" }
%"struct.cosproc::Instruction" = type { { i64, i64 }, { i64, i64 }, ptr, i32 }
%class.cosproc = type { ptr, ptr, i16, i16, [8 x i8], [8 x i8], [257 x %"struct.cosproc::Instruction"] }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cosproc5cycleEv(ptr dead_on_unwind noalias writable sret(%"struct.cosproc::Debug") align 8 %0, ptr noundef nonnull align 8 dereferenceable(12376) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca %"struct.cosproc::Instruction", align 8
  %6 = alloca %"struct.cosproc::Instruction", align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %8 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 2
  %11 = load i16, ptr %10, align 8, !tbaa !12
  %12 = call noundef zeroext i8 %9(i16 noundef zeroext %11)
  store i8 %12, ptr %4, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 48, ptr %5) #3
  %13 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 6
  %14 = load i8, ptr %4, align 1, !tbaa !13
  %15 = zext i8 %14 to i64
  %16 = getelementptr inbounds [257 x %"struct.cosproc::Instruction"], ptr %13, i64 0, i64 %15
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %16, i64 48, i1 false), !tbaa.struct !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %5, i64 48, i1 false), !tbaa.struct !14
  call void @_ZN7cosproc7executeENS_11InstructionE(ptr noundef nonnull align 8 dereferenceable(12376) %7, ptr noundef byval(%"struct.cosproc::Instruction") align 8 %6)
  %17 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 2
  %18 = load i16, ptr %17, align 8, !tbaa !12
  %19 = zext i16 %18 to i32
  %20 = getelementptr inbounds %"struct.cosproc::Debug", ptr %0, i32 0, i32 0
  store i32 %19, ptr %20, align 8, !tbaa !17
  %21 = getelementptr inbounds %"struct.cosproc::Debug", ptr %0, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %21, ptr align 8 %5, i64 48, i1 false), !tbaa.struct !14
  %22 = getelementptr inbounds %"struct.cosproc::Instruction", ptr %5, i32 0, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !20
  %24 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 2
  %25 = load i16, ptr %24, align 8, !tbaa !12
  %26 = zext i16 %25 to i32
  %27 = add nsw i32 %26, %23
  %28 = trunc i32 %27 to i16
  store i16 %28, ptr %24, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 48, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cosproc7executeENS_11InstructionE(ptr noundef nonnull align 8 dereferenceable(12376), ptr noundef byval(%"struct.cosproc::Instruction") align 8) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS7cosproc", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 18, !7, i64 20, !7, i64 28, !7, i64 40}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{i64 0, i64 16, !13, i64 16, i64 16, !13, i64 32, i64 8, !5, i64 40, i64 4, !15}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !16, i64 0}
!18 = !{!"_ZTSN7cosproc5DebugE", !16, i64 0, !19, i64 8}
!19 = !{!"_ZTSN7cosproc11InstructionE", !7, i64 0, !7, i64 16, !6, i64 32, !16, i64 40}
!20 = !{!19, !16, i64 40}


; 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.cosproc::Debug" = type { i32, %"struct.cosproc::Instruction" }
%"struct.cosproc::Instruction" = type { { i64, i64 }, { i64, i64 }, ptr, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cosproc5cycleEv(ptr dead_on_unwind noalias nocapture writable writeonly sret(%"struct.cosproc::Debug") align 8 %0, ptr noundef nonnull align 8 dereferenceable(12376) %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %"struct.cosproc::Instruction", align 8
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load i16, ptr %6, align 8, !tbaa !11
  %8 = tail call noundef zeroext i8 %5(i16 noundef zeroext %7)
  %9 = getelementptr inbounds i8, ptr %1, i64 40
  %10 = zext i8 %8 to i64
  %11 = getelementptr inbounds [257 x %"struct.cosproc::Instruction"], ptr %9, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %12, ptr noundef nonnull align 8 dereferenceable(40) %11, i64 40, i1 false)
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 40
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !12
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 44
  %.sroa.6.0.copyload = load i32, ptr %.sroa.6.0..sroa_idx, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %3, ptr noundef nonnull align 8 dereferenceable(40) %11, i64 40, i1 false)
  %.sroa.5.0..sroa_idx1 = getelementptr inbounds i8, ptr %3, i64 40
  store i32 %.sroa.5.0.copyload, ptr %.sroa.5.0..sroa_idx1, align 8, !tbaa !12
  %.sroa.6.0..sroa_idx5 = getelementptr inbounds i8, ptr %3, i64 44
  store i32 %.sroa.6.0.copyload, ptr %.sroa.6.0..sroa_idx5, align 4
  tail call void @_ZN7cosproc7executeENS_11InstructionE(ptr noundef nonnull align 8 dereferenceable(12376) %1, ptr noundef nonnull byval(%"struct.cosproc::Instruction") align 8 %3)
  %13 = load i16, ptr %6, align 8, !tbaa !11
  %14 = zext i16 %13 to i32
  store i32 %14, ptr %0, align 8, !tbaa !14
  %.sroa.5.0..sroa_idx3 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %.sroa.5.0.copyload, ptr %.sroa.5.0..sroa_idx3, align 8, !tbaa !12
  %.sroa.6.0..sroa_idx7 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %.sroa.6.0.copyload, ptr %.sroa.6.0..sroa_idx7, align 4
  %15 = trunc i32 %.sroa.5.0.copyload to i16
  %16 = add i16 %13, %15
  store i16 %16, ptr %6, align 8, !tbaa !11
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cosproc7executeENS_11InstructionE(ptr noundef nonnull align 8 dereferenceable(12376), ptr noundef byval(%"struct.cosproc::Instruction") align 8) local_unnamed_addr #1 align 2

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

!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, !7, i64 8}
!6 = !{!"_ZTS7cosproc", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !8, i64 20, !8, i64 28, !8, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTSN7cosproc5DebugE", !13, i64 0, !16, i64 8}
!16 = !{!"_ZTSN7cosproc11InstructionE", !8, i64 0, !8, i64 16, !7, i64 32, !13, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass