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

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

%class.cosproc = type { ptr, ptr, i16, i16, [8 x i8], [8 x i8], [257 x %"struct.cosproc::Instruction"] }
%"struct.cosproc::Instruction" = type { { i64, i64 }, { i64, i64 }, ptr, i32 }

; 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 nounwind uwtable
define dso_local void @_ZN7cosproc4JMPREt(ptr noundef nonnull align 8 dereferenceable(12376) %0, i16 noundef zeroext %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i16, ptr %4, align 2, !tbaa !9
  %8 = zext i16 %7 to i32
  %9 = srem i32 %8, 2
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %28

11:                                               ; preds = %2
  %12 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 4
  %13 = load i16, ptr %4, align 2, !tbaa !9
  %14 = zext i16 %13 to i64
  %15 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = zext i8 %16 to i32
  %18 = shl i32 %17, 8
  %19 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 4
  %20 = load i16, ptr %4, align 2, !tbaa !9
  %21 = zext i16 %20 to i32
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [8 x i8], ptr %19, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = or i32 %18, %26
  store i32 %27, ptr %5, align 4, !tbaa !12
  br label %45

28:                                               ; preds = %2
  %29 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 4
  %30 = load i16, ptr %4, align 2, !tbaa !9
  %31 = zext i16 %30 to i32
  %32 = sub nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [8 x i8], ptr %29, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = shl i32 %36, 8
  %38 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 4
  %39 = load i16, ptr %4, align 2, !tbaa !9
  %40 = zext i16 %39 to i64
  %41 = getelementptr inbounds [8 x i8], ptr %38, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = or i32 %37, %43
  store i32 %44, ptr %5, align 4, !tbaa !12
  br label %45

45:                                               ; preds = %28, %11
  %46 = load i32, ptr %5, align 4, !tbaa !12
  %47 = trunc i32 %46 to i16
  %48 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 2
  store i16 %47, ptr %48, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !10, i64 16}
!15 = !{!"_ZTS7cosproc", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 18, !7, i64 20, !7, i64 28, !7, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN7cosproc4JMPREt(ptr nocapture noundef nonnull align 8 dereferenceable(12376) %0, i16 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = zext i16 %1 to i32
  %4 = and i32 %3, 1
  %5 = icmp eq i32 %4, 0
  %6 = add nsw i32 %3, -1
  %7 = zext nneg i32 %6 to i64
  %8 = zext i16 %1 to i64
  %9 = zext i16 %1 to i64
  %10 = or disjoint i32 %3, 1
  %11 = zext nneg i32 %10 to i64
  %.sink9 = select i1 %5, i64 %11, i64 %8
  %.pn = select i1 %5, i64 %9, i64 %7
  %12 = getelementptr inbounds i8, ptr %0, i64 20
  %.sink.in.in.in = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 %.pn
  %.sink.in.in = load i8, ptr %.sink.in.in.in, align 1, !tbaa !5
  %.sink.in = zext i8 %.sink.in.in to i16
  %.sink = shl nuw i16 %.sink.in, 8
  %13 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 %.sink9
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = zext i8 %14 to i16
  %16 = or disjoint i16 %.sink, %15
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store i16 %16, ptr %17, align 8, !tbaa !8
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !11, i64 16}
!9 = !{!"_ZTS7cosproc", !10, i64 0, !10, i64 8, !11, i64 16, !11, i64 18, !6, i64 20, !6, i64 28, !6, i64 40}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"short", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass