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

; 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 uwtable
define dso_local void @_ZN7cosproc4CMPXEt(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
  %7 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  %9 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load i16, ptr %4, align 2, !tbaa !9
  %12 = call noundef zeroext i8 %10(i16 noundef zeroext %11)
  %13 = zext i8 %12 to i32
  %14 = shl i32 %13, 8
  %15 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = load i16, ptr %4, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = add nsw i32 %18, 1
  %20 = trunc i32 %19 to i16
  %21 = call noundef zeroext i8 %16(i16 noundef zeroext %20)
  %22 = zext i8 %21 to i32
  %23 = or i32 %14, %22
  %24 = trunc i32 %23 to i16
  store i16 %24, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  %25 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %26 = getelementptr inbounds [8 x i8], ptr %25, i64 0, i64 0
  %27 = load i8, ptr %26, align 4, !tbaa !13
  %28 = zext i8 %27 to i32
  %29 = shl i32 %28, 8
  %30 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %31 = getelementptr inbounds [8 x i8], ptr %30, i64 0, i64 1
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  %34 = or i32 %29, %33
  %35 = trunc i32 %34 to i16
  store i16 %35, ptr %6, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %36 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %37 = getelementptr inbounds [8 x i8], ptr %36, i64 0, i64 0
  %38 = load i8, ptr %37, align 4, !tbaa !13
  %39 = zext i8 %38 to i32
  %40 = shl i32 %39, 8
  %41 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %42 = getelementptr inbounds [8 x i8], ptr %41, i64 0, i64 1
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = or i32 %40, %44
  %46 = trunc i32 %45 to i16
  store i16 %46, ptr %7, align 2, !tbaa !9
  call void @_ZN7cosproc3CLFEt(ptr noundef nonnull align 8 dereferenceable(12376) %8, i16 noundef zeroext 0)
  %47 = load i16, ptr %5, align 2, !tbaa !9
  %48 = zext i16 %47 to i32
  %49 = load i16, ptr %6, align 2, !tbaa !9
  %50 = zext i16 %49 to i32
  %51 = icmp eq i32 %48, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %2
  %53 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %54 = getelementptr inbounds [8 x i8], ptr %53, i64 0, i64 0
  store i8 1, ptr %54, align 4, !tbaa !14
  br label %55

55:                                               ; preds = %52, %2
  %56 = load i16, ptr %5, align 2, !tbaa !9
  %57 = zext i16 %56 to i32
  %58 = load i16, ptr %6, align 2, !tbaa !9
  %59 = zext i16 %58 to i32
  %60 = icmp sgt i32 %57, %59
  br i1 %60, label %61, label %64

61:                                               ; preds = %55
  %62 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %63 = getelementptr inbounds [8 x i8], ptr %62, i64 0, i64 1
  store i8 1, ptr %63, align 1, !tbaa !14
  br label %64

64:                                               ; preds = %61, %55
  %65 = load i16, ptr %5, align 2, !tbaa !9
  %66 = zext i16 %65 to i32
  %67 = load i16, ptr %6, align 2, !tbaa !9
  %68 = zext i16 %67 to i32
  %69 = icmp slt i32 %66, %68
  br i1 %69, label %70, label %73

70:                                               ; preds = %64
  %71 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %72 = getelementptr inbounds [8 x i8], ptr %71, i64 0, i64 2
  store i8 1, ptr %72, align 2, !tbaa !14
  br label %73

73:                                               ; preds = %70, %64
  %74 = load i16, ptr %5, align 2, !tbaa !9
  %75 = sext i16 %74 to i32
  %76 = load i16, ptr %7, align 2, !tbaa !9
  %77 = sext i16 %76 to i32
  %78 = icmp slt i32 %75, %77
  br i1 %78, label %79, label %82

79:                                               ; preds = %73
  %80 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %81 = getelementptr inbounds [8 x i8], ptr %80, i64 0, i64 3
  store i8 1, ptr %81, align 1, !tbaa !14
  br label %82

82:                                               ; preds = %79, %73
  %83 = load i16, ptr %5, align 2, !tbaa !9
  %84 = sext i16 %83 to i32
  %85 = load i16, ptr %7, align 2, !tbaa !9
  %86 = sext i16 %85 to i32
  %87 = icmp sgt i32 %84, %86
  br i1 %87, label %88, label %91

88:                                               ; preds = %82
  %89 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %90 = getelementptr inbounds [8 x i8], ptr %89, i64 0, i64 4
  store i8 1, ptr %90, align 4, !tbaa !14
  br label %91

91:                                               ; preds = %88, %82
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cosproc3CLFEt(ptr noundef nonnull align 8 dereferenceable(12376), i16 noundef zeroext) #2 align 2

attributes #0 = { nocallback nofree nosync 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" }
attributes #2 = { 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 #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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS7cosproc", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 18, !7, i64 20, !7, i64 28, !7, i64 40}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"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 uwtable
define dso_local void @_ZN7cosproc4CMPXEt(ptr noundef nonnull align 8 dereferenceable(12376) %0, i16 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call noundef zeroext i8 %4(i16 noundef zeroext %1)
  %6 = zext i8 %5 to i16
  %7 = shl nuw i16 %6, 8
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = add i16 %1, 1
  %10 = tail call noundef zeroext i8 %8(i16 noundef zeroext %9)
  %11 = zext i8 %10 to i16
  %12 = or disjoint i16 %7, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 20
  %14 = load i8, ptr %13, align 4, !tbaa !11
  %15 = zext i8 %14 to i16
  %16 = shl nuw i16 %15, 8
  %17 = getelementptr inbounds i8, ptr %0, i64 21
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i16
  %20 = or disjoint i16 %16, %19
  tail call void @_ZN7cosproc3CLFEt(ptr noundef nonnull align 8 dereferenceable(12376) %0, i16 noundef zeroext 0)
  %21 = icmp eq i16 %12, %20
  br i1 %21, label %22, label %24

22:                                               ; preds = %2
  %23 = getelementptr inbounds i8, ptr %0, i64 28
  store i8 1, ptr %23, align 4, !tbaa !12
  br label %24

24:                                               ; preds = %22, %2
  %25 = icmp ugt i16 %12, %20
  br i1 %25, label %26, label %28

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %0, i64 29
  store i8 1, ptr %27, align 1, !tbaa !12
  br label %28

28:                                               ; preds = %26, %24
  %29 = icmp ult i16 %12, %20
  br i1 %29, label %30, label %32

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %0, i64 30
  store i8 1, ptr %31, align 2, !tbaa !12
  br label %32

32:                                               ; preds = %30, %28
  %33 = icmp slt i16 %12, %20
  br i1 %33, label %34, label %36

34:                                               ; preds = %32
  %35 = getelementptr inbounds i8, ptr %0, i64 31
  store i8 1, ptr %35, align 1, !tbaa !12
  br label %36

36:                                               ; preds = %34, %32
  %37 = icmp sgt i16 %12, %20
  br i1 %37, label %38, label %40

38:                                               ; preds = %36
  %39 = getelementptr inbounds i8, ptr %0, i64 32
  store i8 1, ptr %39, align 8, !tbaa !12
  br label %40

40:                                               ; preds = %38, %36
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cosproc3CLFEt(ptr noundef nonnull align 8 dereferenceable(12376), i16 noundef zeroext) local_unnamed_addr #1 align 2

attributes #0 = { 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 #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" }

!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 = !{!8, !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass