; LLVM IR from ponylang/ponyc :: src/libponyc/pkg (use)

; 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.use_scheme_t = type { ptr, i64, i8, i8, ptr }

@handlers = external hidden thread_local global [5 x %struct.use_scheme_t], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @use_test_handler(ptr noundef %0, i1 noundef zeroext %1, i1 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %9 = zext i1 %1 to i8
  store i8 %9, ptr %5, align 1, !tbaa !9
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %53, %3
  %12 = call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @handlers)
  %13 = load i32, ptr %7, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [5 x %struct.use_scheme_t], ptr %12, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.use_scheme_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 16, !tbaa !13
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %11
  store i32 2, ptr %8, align 4
  br label %56

20:                                               ; preds = %11
  %21 = call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @handlers)
  %22 = load i32, ptr %7, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [5 x %struct.use_scheme_t], ptr %21, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.use_scheme_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 16, !tbaa !13
  %27 = call i32 @strcmp(ptr noundef %26, ptr noundef @.str) #5
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %52

29:                                               ; preds = %20
  %30 = load i8, ptr %5, align 1, !tbaa !9, !range !16, !noundef !17
  %31 = trunc i8 %30 to i1
  %32 = call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @handlers)
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [5 x %struct.use_scheme_t], ptr %32, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.use_scheme_t, ptr %35, i32 0, i32 2
  %37 = zext i1 %31 to i8
  store i8 %37, ptr %36, align 16, !tbaa !18
  %38 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %39 = trunc i8 %38 to i1
  %40 = call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @handlers)
  %41 = load i32, ptr %7, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [5 x %struct.use_scheme_t], ptr %40, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.use_scheme_t, ptr %43, i32 0, i32 3
  %45 = zext i1 %39 to i8
  store i8 %45, ptr %44, align 1, !tbaa !19
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @handlers)
  %48 = load i32, ptr %7, align 4, !tbaa !11
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [5 x %struct.use_scheme_t], ptr %47, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.use_scheme_t, ptr %50, i32 0, i32 4
  store ptr %46, ptr %51, align 8, !tbaa !20
  store i32 1, ptr %8, align 4
  br label %56

52:                                               ; preds = %20
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %7, align 4, !tbaa !11
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %7, align 4, !tbaa !11
  br label %11, !llvm.loop !21

56:                                               ; preds = %29, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %57 = load i32, ptr %8, align 4
  switch i32 %57, label %59 [
    i32 2, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %56
  unreachable
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind willreturn memory(read) "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 willreturn memory(read) }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"use_scheme_t", !6, i64 0, !15, i64 8, !10, i64 16, !10, i64 17, !6, i64 24}
!15 = !{!"long", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!14, !10, i64 16}
!19 = !{!14, !10, i64 17}
!20 = !{!14, !6, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"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.use_scheme_t = type { ptr, i64, i8, i8, ptr }

@handlers = external hidden thread_local local_unnamed_addr global [5 x %struct.use_scheme_t], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @use_test_handler(ptr noundef %0, i1 noundef zeroext %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = zext i1 %1 to i8
  %5 = zext i1 %2 to i8
  %6 = tail call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @handlers)
  %7 = load ptr, ptr %6, align 16, !tbaa !5
  %.not10 = icmp eq ptr %7, null
  br i1 %.not10, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %8 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str) #3
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.lr.ph._crit_edge, label %.lr.ph17

.lr.ph17:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv16 = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv16, 1
  %10 = getelementptr inbounds [5 x %struct.use_scheme_t], ptr %6, i64 0, i64 %indvars.iv.next
  %11 = load ptr, ptr %10, align 16, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !12

.lr.ph:                                           ; preds = %.lr.ph17
  %12 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) @.str) #3
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %.lr.ph._crit_edge, label %.lr.ph17, !llvm.loop !12

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa = phi ptr [ %6, %.lr.ph.preheader ], [ %10, %.lr.ph ]
  %14 = getelementptr inbounds i8, ptr %.lcssa, i64 16
  store i8 %4, ptr %14, align 16, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %.lcssa, i64 17
  store i8 %5, ptr %15, align 1, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %.lcssa, i64 24
  store ptr %0, ptr %16, align 8, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph17, %3, %.lr.ph._crit_edge
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { nofree nounwind memory(readwrite, 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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 0}
!6 = !{!"use_scheme_t", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 17, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !11, i64 16}
!15 = !{!6, !11, i64 17}
!16 = !{!6, !7, i64 24}


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