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

; 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 @_ZN7cosproc5SHRXREt(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 i16, align 2
  %6 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  %8 = load i16, ptr %4, align 2, !tbaa !9
  %9 = zext i16 %8 to i32
  %10 = srem i32 %9, 2
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %30

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

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

48:                                               ; preds = %30, %12
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  %49 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 4
  %50 = getelementptr inbounds [8 x i8], ptr %49, i64 0, i64 0
  %51 = load i8, ptr %50, align 4, !tbaa !11
  %52 = zext i8 %51 to i32
  %53 = shl i32 %52, 8
  %54 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 4
  %55 = getelementptr inbounds [8 x i8], ptr %54, i64 0, i64 1
  %56 = load i8, ptr %55, align 1, !tbaa !11
  %57 = zext i8 %56 to i32
  %58 = or i32 %53, %57
  %59 = load i16, ptr %5, align 2, !tbaa !9
  %60 = zext i16 %59 to i32
  %61 = ashr i32 %58, %60
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr %6, align 2, !tbaa !9
  %63 = load i16, ptr %6, align 2, !tbaa !9
  %64 = zext i16 %63 to i32
  %65 = and i32 %64, 65280
  %66 = ashr i32 %65, 8
  %67 = trunc i32 %66 to i8
  %68 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 4
  %69 = getelementptr inbounds [8 x i8], ptr %68, i64 0, i64 0
  store i8 %67, ptr %69, align 4, !tbaa !11
  %70 = load i16, ptr %6, align 2, !tbaa !9
  %71 = zext i16 %70 to i32
  %72 = and i32 %71, 255
  %73 = trunc i32 %72 to i8
  %74 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 4
  %75 = getelementptr inbounds [8 x i8], ptr %74, i64 0, i64 1
  store i8 %73, ptr %75, align 1, !tbaa !11
  %76 = load i16, ptr %6, align 2, !tbaa !9
  %77 = zext i16 %76 to i32
  %78 = icmp eq i32 %77, 0
  %79 = getelementptr inbounds %class.cosproc, ptr %7, i32 0, i32 5
  %80 = getelementptr inbounds [8 x i8], ptr %79, i64 0, i64 0
  %81 = zext i1 %78 to i8
  store i8 %81, ptr %80, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 2, 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 = !{!"bool", !7, i64 0}


; 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 @_ZN7cosproc5SHRXREt(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
  %.sink12 = 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 i32
  %.sink = shl nuw nsw i32 %.sink.in, 8
  %13 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 %.sink12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = or disjoint i32 %.sink, %15
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = load i8, ptr %17, align 4, !tbaa !5
  %19 = zext i8 %18 to i32
  %20 = shl nuw nsw i32 %19, 8
  %21 = getelementptr inbounds i8, ptr %0, i64 21
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = or disjoint i32 %20, %23
  %25 = lshr i32 %24, %16
  %26 = lshr i32 %25, 8
  %27 = trunc nuw i32 %26 to i8
  store i8 %27, ptr %17, align 4, !tbaa !5
  %28 = trunc i32 %25 to i8
  store i8 %28, ptr %21, align 1, !tbaa !5
  %29 = icmp eq i32 %25, 0
  %30 = getelementptr inbounds i8, ptr %0, i64 28
  %31 = zext i1 %29 to i8
  store i8 %31, ptr %30, align 4, !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, !9, i64 0}
!9 = !{!"bool", !6, i64 0}


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