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

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

%struct.SLK = type { [32 x i64], i32, i32, i32 }

@labels = external hidden global i32, align 4
@slk = external hidden global ptr, align 8
@slk_label.temp = external hidden global [33 x i8], align 16

; 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: nounwind uwtable
define dso_local ptr @slk_label(i32 noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 1
  br i1 %8, label %13, label %9

9:                                                ; preds = %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr @labels, align 4, !tbaa !5
  %12 = icmp sgt i32 %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %9, %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %41

14:                                               ; preds = %9
  store i32 0, ptr %5, align 4, !tbaa !5
  %15 = load ptr, ptr @slk, align 8, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.SLK, ptr %15, i64 %18
  %20 = getelementptr inbounds %struct.SLK, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds [32 x i64], ptr %20, i64 0, i64 0
  store ptr %21, ptr %4, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %34, %14
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %37

26:                                               ; preds = %22
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds i64, ptr %27, i32 1
  store ptr %28, ptr %4, align 8, !tbaa !9
  %29 = load i64, ptr %27, align 8, !tbaa !11
  %30 = trunc i64 %29 to i8
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [33 x i8], ptr @slk_label.temp, i64 0, i64 %32
  store i8 %30, ptr %33, align 1, !tbaa !13
  br label %34

34:                                               ; preds = %26
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %5, align 4, !tbaa !5
  br label %22, !llvm.loop !14

37:                                               ; preds = %22
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [33 x i8], ptr @slk_label.temp, i64 0, i64 %39
  store i8 0, ptr %40, align 1, !tbaa !13
  store ptr @slk_label.temp, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %41

41:                                               ; preds = %37, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %42 = load ptr, ptr %2, align 8
  ret ptr %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

%struct.SLK = type { [32 x i64], i32, i32, i32 }

@labels = external hidden local_unnamed_addr global i32, align 4
@slk = external hidden local_unnamed_addr global ptr, align 8
@slk_label.temp = external hidden global [33 x i8], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @slk_label(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 1
  %3 = load i32, ptr @labels, align 4
  %4 = icmp slt i32 %3, %0
  %or.cond = select i1 %2, i1 true, i1 %4
  br i1 %or.cond, label %18, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr @slk, align 8, !tbaa !5
  %7 = zext nneg i32 %0 to i64
  %8 = getelementptr %struct.SLK, ptr %6, i64 %7
  %9 = getelementptr i8, ptr %8, i64 -272
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %.not13 = icmp eq i64 %10, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %11 = phi i64 [ %15, %.lr.ph ], [ %10, %5 ]
  %.0814 = phi ptr [ %12, %.lr.ph ], [ %9, %5 ]
  %12 = getelementptr inbounds i8, ptr %.0814, i64 8
  %13 = trunc i64 %11 to i8
  %14 = getelementptr inbounds [33 x i8], ptr @slk_label.temp, i64 0, i64 %indvars.iv
  store i8 %13, ptr %14, align 1, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load i64, ptr %12, align 8, !tbaa !9
  %.not = icmp eq i64 %15, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !12

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %16 = and i64 %indvars.iv.next, 4294967295
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %5
  %.0.lcssa = phi i64 [ 0, %5 ], [ %16, %._crit_edge.loopexit ]
  %17 = getelementptr inbounds [33 x i8], ptr @slk_label.temp, i64 0, i64 %.0.lcssa
  store i8 0, ptr %17, align 1, !tbaa !11
  br label %18

18:                                               ; preds = %1, %._crit_edge
  %.09 = phi ptr [ @slk_label.temp, %._crit_edge ], [ null, %1 ]
  ret ptr %.09
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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