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

; 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 @_ZN7cosproc4JNCREt(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 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 5
  %8 = getelementptr inbounds [8 x i8], ptr %7, i64 0, i64 2
  %9 = load i8, ptr %8, align 2, !tbaa !11, !range !13, !noundef !14
  %10 = trunc i8 %9 to i1
  br i1 %10, label %54, label %11

11:                                               ; preds = %2
  %12 = load i16, ptr %4, align 2, !tbaa !9
  %13 = zext i16 %12 to i32
  %14 = srem i32 %13, 2
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %33

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

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

50:                                               ; preds = %33, %16
  %51 = load i32, ptr %5, align 4, !tbaa !16
  %52 = trunc i32 %51 to i16
  %53 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 2
  store i16 %52, ptr %53, align 8, !tbaa !18
  br label %60

54:                                               ; preds = %2
  %55 = getelementptr inbounds %class.cosproc, ptr %6, i32 0, i32 2
  %56 = load i16, ptr %55, align 8, !tbaa !18
  %57 = zext i16 %56 to i32
  %58 = add nsw i32 %57, 2
  %59 = trunc i32 %58 to i16
  store i16 %59, ptr %55, align 8, !tbaa !18
  br label %60

60:                                               ; preds = %54, %50
  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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!19, !10, i64 16}
!19 = !{!"_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 @_ZN7cosproc4JNCREt(ptr nocapture noundef nonnull align 8 dereferenceable(12376) %0, i16 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 30
  %4 = load i8, ptr %3, align 2, !tbaa !5, !range !9, !noundef !10
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %22, label %6

6:                                                ; preds = %2
  %7 = zext i16 %1 to i32
  %8 = and i32 %7, 1
  %9 = icmp eq i32 %8, 0
  %10 = getelementptr inbounds i8, ptr %0, i64 20
  %11 = add nsw i32 %7, -1
  %12 = zext nneg i32 %11 to i64
  %13 = zext i16 %1 to i64
  %14 = zext i16 %1 to i64
  %15 = or disjoint i32 %7, 1
  %16 = zext nneg i32 %15 to i64
  %.sink9 = select i1 %9, i64 %16, i64 %13
  %.pn = select i1 %9, i64 %14, i64 %12
  %.sink.in.in.in = getelementptr inbounds [8 x i8], ptr %10, i64 0, i64 %.pn
  %.sink.in.in = load i8, ptr %.sink.in.in.in, align 1, !tbaa !11
  %.sink.in = zext i8 %.sink.in.in to i16
  %.sink = shl nuw i16 %.sink.in, 8
  %17 = getelementptr inbounds [8 x i8], ptr %10, i64 0, i64 %.sink9
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i16
  %20 = or disjoint i16 %.sink, %19
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  store i16 %20, ptr %21, align 8, !tbaa !12
  br label %26

22:                                               ; preds = %2
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load i16, ptr %23, align 8, !tbaa !12
  %25 = add i16 %24, 2
  store i16 %25, ptr %23, align 8, !tbaa !12
  br label %26

26:                                               ; preds = %22, %6
  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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !15, i64 16}
!13 = !{!"_ZTS7cosproc", !14, i64 0, !14, i64 8, !15, i64 16, !15, i64 18, !7, i64 20, !7, i64 28, !7, i64 40}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"short", !7, i64 0}


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