; LLVM IR from sfu-dis/mosaicdb :: benchmarks/egen/Random.ll (ZN4TPCE7CRandom20RndAlphaNumFormattedEPcPKc)

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

@_ZN4TPCEL16UpperCaseLettersE = external hidden constant [27 x i8], align 16
@_ZN4TPCEL8NumeralsE = external hidden constant [11 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4TPCE7CRandom20RndAlphaNumFormattedEPcPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  br label %8

8:                                                ; preds = %37, %3
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %15

11:                                               ; preds = %8
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = icmp ne i8 %13, 0
  br label %15

15:                                               ; preds = %11, %8
  %16 = phi i1 [ false, %8 ], [ %14, %11 ]
  br i1 %16, label %17, label %42

17:                                               ; preds = %15
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  switch i32 %20, label %33 [
    i32 97, label %21
    i32 110, label %27
  ]

21:                                               ; preds = %17
  %22 = call noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8) %7, i32 noundef 0, i32 noundef 25)
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [27 x i8], ptr @_ZN4TPCEL16UpperCaseLettersE, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %25, ptr %26, align 1, !tbaa !9
  br label %37

27:                                               ; preds = %17
  %28 = call noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8) %7, i32 noundef 0, i32 noundef 9)
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [11 x i8], ptr @_ZN4TPCEL8NumeralsE, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %31, ptr %32, align 1, !tbaa !9
  br label %37

33:                                               ; preds = %17
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %35, ptr %36, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %33, %27, %21
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i32 1
  store ptr %41, ptr %5, align 8, !tbaa !5
  br label %8, !llvm.loop !10

42:                                               ; preds = %15
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %43, align 1, !tbaa !9
  ret void
}

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@_ZN4TPCEL16UpperCaseLettersE = external hidden local_unnamed_addr constant [27 x i8], align 16
@_ZN4TPCEL8NumeralsE = external hidden local_unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4TPCE7CRandom20RndAlphaNumFormattedEPcPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr nocapture noundef writeonly %1, ptr noundef readonly %2) local_unnamed_addr #0 align 2 {
  %.not14 = icmp eq ptr %2, null
  br i1 %.not14, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %14
  %.016 = phi ptr [ %15, %14 ], [ %2, %3 ]
  %.01115 = phi ptr [ %16, %14 ], [ %1, %3 ]
  %4 = load i8, ptr %.016, align 1, !tbaa !5
  switch i8 %4, label %14 [
    i8 0, label %.critedge
    i8 97, label %5
    i8 110, label %9
  ]

5:                                                ; preds = %.lr.ph
  %6 = tail call noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef 0, i32 noundef 25)
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [27 x i8], ptr @_ZN4TPCEL16UpperCaseLettersE, i64 0, i64 %7
  br label %.sink.split

9:                                                ; preds = %.lr.ph
  %10 = tail call noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef 0, i32 noundef 9)
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [11 x i8], ptr @_ZN4TPCEL8NumeralsE, i64 0, i64 %11
  br label %.sink.split

.sink.split:                                      ; preds = %5, %9
  %.sink19 = phi ptr [ %12, %9 ], [ %8, %5 ]
  %13 = load i8, ptr %.sink19, align 1, !tbaa !5
  br label %14

14:                                               ; preds = %.sink.split, %.lr.ph
  %.sink = phi i8 [ %4, %.lr.ph ], [ %13, %.sink.split ]
  store i8 %.sink, ptr %.01115, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.016, i64 1
  %16 = getelementptr inbounds i8, ptr %.01115, i64 1
  br label %.lr.ph

.critedge:                                        ; preds = %.lr.ph, %3
  %.011.lcssa = phi ptr [ %1, %3 ], [ %.01115, %.lr.ph ]
  store i8 0, ptr %.011.lcssa, align 1, !tbaa !5
  ret void
}

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

!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"}


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