; LLVM IR from clangen/musikcube :: src/3rdparty/win32_src/pdcurses (pdccolor)

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

@.str.1 = external hidden unnamed_addr constant [94 x i8], align 1
@rgbs = external hidden global ptr, align 8
@palette_size = external hidden global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__.PDC_set_palette_entry = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @PDC_default_color(i32 noundef) #0

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PDC_set_palette_entry(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr @palette_size, align 4, !tbaa !5
  %13 = icmp sge i32 %11, %12
  br i1 %13, label %14, label %62

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %15 = load i32, ptr @palette_size, align 4, !tbaa !5
  store i32 %15, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 8, ptr %9, align 4, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 8, ptr %8, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %18, %14
  br label %20

20:                                               ; preds = %24, %19
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %24, label %27

24:                                               ; preds = %20
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = mul nsw i32 %25, 2
  store i32 %26, ptr %8, align 4, !tbaa !5
  br label %20, !llvm.loop !9

27:                                               ; preds = %20
  %28 = load ptr, ptr @rgbs, align 8, !tbaa !11
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = mul i64 %30, 4
  %32 = call ptr @realloc(ptr noundef %28, i64 noundef %31) #5
  store ptr %32, ptr @rgbs, align 8, !tbaa !11
  %33 = load ptr, ptr @rgbs, align 8, !tbaa !11
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  br label %37

36:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 110, ptr noundef @__PRETTY_FUNCTION__.PDC_set_palette_entry) #6
  unreachable

37:                                               ; preds = %35
  %38 = load ptr, ptr @rgbs, align 8, !tbaa !11
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

41:                                               ; preds = %37
  %42 = load i32, ptr @palette_size, align 4, !tbaa !5
  store i32 %42, ptr %7, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %54, %41
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %43
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = call i32 @PDC_default_color(i32 noundef %48)
  %50 = load ptr, ptr @rgbs, align 8, !tbaa !11
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  store i32 %49, ptr %53, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %47
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %7, align 4, !tbaa !5
  br label %43, !llvm.loop !13

57:                                               ; preds = %43
  %58 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %58, ptr @palette_size, align 4, !tbaa !5
  store i32 0, ptr %10, align 4
  br label %59

59:                                               ; preds = %57, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %60 = load i32, ptr %10, align 4
  switch i32 %60, label %78 [
    i32 0, label %61
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61, %2
  %63 = load ptr, ptr @rgbs, align 8, !tbaa !11
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %63, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = icmp eq i32 %67, %68
  %70 = zext i1 %69 to i64
  %71 = select i1 %69, i32 1, i32 0
  store i32 %71, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = load ptr, ptr @rgbs, align 8, !tbaa !11
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  store i32 %72, ptr %76, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %77, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %78

78:                                               ; preds = %62, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn nounwind "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 allocsize(1) "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(1) }
attributes #6 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !10}


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

@.str.1 = external hidden unnamed_addr constant [94 x i8], align 1
@rgbs = external hidden local_unnamed_addr global ptr, align 8
@palette_size = external hidden local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__.PDC_set_palette_entry = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @PDC_default_color(i32 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @PDC_set_palette_entry(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @palette_size, align 4, !tbaa !5
  %.not = icmp sgt i32 %3, %0
  br i1 %.not, label %._crit_edge29, label %4

._crit_edge29:                                    ; preds = %2
  %.pre = load ptr, ptr @rgbs, align 8, !tbaa !9
  br label %22

4:                                                ; preds = %2
  %.not24 = icmp eq i32 %3, 0
  %spec.store.select = select i1 %.not24, i32 8, i32 %3
  br label %5

5:                                                ; preds = %5, %4
  %.020 = phi i32 [ %spec.store.select, %4 ], [ %6, %5 ]
  %.not25 = icmp sgt i32 %.020, %0
  %6 = shl nsw i32 %.020, 1
  br i1 %.not25, label %7, label %5, !llvm.loop !11

7:                                                ; preds = %5
  %8 = load ptr, ptr @rgbs, align 8, !tbaa !9
  %9 = sext i32 %.020 to i64
  %10 = shl nsw i64 %9, 2
  %11 = tail call ptr @realloc(ptr noundef %8, i64 noundef %10) #3
  store ptr %11, ptr @rgbs, align 8, !tbaa !9
  %.not26 = icmp eq ptr %11, null
  br i1 %.not26, label %12, label %13

12:                                               ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 110, ptr noundef nonnull @__PRETTY_FUNCTION__.PDC_set_palette_entry) #4
  unreachable

13:                                               ; preds = %7
  %14 = load i32, ptr @palette_size, align 4, !tbaa !5
  %15 = icmp slt i32 %14, %.020
  br i1 %15, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %13
  %16 = sext i32 %14 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %16, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %17 = trunc nsw i64 %indvars.iv to i32
  %18 = tail call i32 @PDC_default_color(i32 noundef %17)
  %19 = load ptr, ptr @rgbs, align 8, !tbaa !9
  %20 = getelementptr inbounds i32, ptr %19, i64 %indvars.iv
  store i32 %18, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %9
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %13
  %21 = phi ptr [ %11, %13 ], [ %19, %.lr.ph ]
  store i32 %.020, ptr @palette_size, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %._crit_edge29, %._crit_edge
  %23 = phi ptr [ %.pre, %._crit_edge29 ], [ %21, %._crit_edge ]
  %24 = sext i32 %0 to i64
  %25 = getelementptr inbounds i32, ptr %23, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %1, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %26, %1
  %28 = zext i1 %27 to i32
  ret i32 %28
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { noreturn nounwind "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 willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(1) }
attributes #4 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass