; LLVM IR from jgaeddert/liquid-dsp :: examples (msequence_generator_example)

; 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.3 = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @usage() #0

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %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
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  br label %16

16:                                               ; preds = %29, %2
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = call i32 @getopt(i32 noundef %17, ptr noundef %18, ptr noundef @.str.3) #6
  store i32 %19, ptr %7, align 4, !tbaa !5
  %20 = icmp ne i32 %19, -1
  br i1 %20, label %21, label %30

21:                                               ; preds = %16
  %22 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %22, label %28 [
    i32 104, label %23
    i32 100, label %24
  ]

23:                                               ; preds = %21
  call void @usage()
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %79

24:                                               ; preds = %21
  %25 = load ptr, ptr @optarg, align 8, !tbaa !9
  %26 = call i64 @atol(ptr noundef %25) #7
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %6, align 4, !tbaa !5
  br label %29

28:                                               ; preds = %21
  call void @exit(i32 noundef -1) #8
  unreachable

29:                                               ; preds = %24
  br label %16, !llvm.loop !11

30:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = shl i32 1, %31
  %33 = sub nsw i32 %32, 1
  store i32 %33, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = add i32 %34, 1
  %36 = udiv i32 %35, 2
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = mul i32 %36, %37
  store i32 %38, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %75, %30
  %40 = load i32, ptr %12, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = icmp ule i32 %40, %41
  br i1 %42, label %43, label %78

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  %44 = load i32, ptr %12, align 4, !tbaa !5
  %45 = shl i32 %44, 1
  %46 = add i32 %45, 1
  store i32 %46, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !5
  %49 = call ptr @msequence_create(i32 noundef %47, i32 noundef %48, i32 noundef 1)
  store ptr %49, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  store i32 0, ptr %15, align 4, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %61, %43
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = icmp ult i32 %51, %52
  br i1 %53, label %54, label %64

54:                                               ; preds = %50
  %55 = load ptr, ptr %14, align 8, !tbaa !9
  %56 = call i32 @msequence_get_state(ptr noundef %55)
  %57 = load i32, ptr %15, align 4, !tbaa !5
  %58 = add i32 %57, %56
  store i32 %58, ptr %15, align 4, !tbaa !5
  %59 = load ptr, ptr %14, align 8, !tbaa !9
  %60 = call i32 @msequence_advance(ptr noundef %59)
  br label %61

61:                                               ; preds = %54
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = add i32 %62, 1
  store i32 %63, ptr %11, align 4, !tbaa !5
  br label %50, !llvm.loop !13

64:                                               ; preds = %50
  %65 = load i32, ptr %15, align 4, !tbaa !5
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = icmp eq i32 %65, %66
  br i1 %67, label %68, label %72

68:                                               ; preds = %64
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %69, i32 noundef %70)
  br label %72

72:                                               ; preds = %68, %64
  %73 = load ptr, ptr %14, align 8, !tbaa !9
  %74 = call i32 @msequence_destroy(ptr noundef %73)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %75

75:                                               ; preds = %72
  %76 = load i32, ptr %12, align 4, !tbaa !5
  %77 = add i32 %76, 1
  store i32 %77, ptr %12, align 4, !tbaa !5
  br label %39, !llvm.loop !14

78:                                               ; preds = %39
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %79

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

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

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i64 @atol(ptr noundef nonnull) #4

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #5

declare ptr @msequence_create(i32 noundef, i32 noundef, i32 noundef) #1

declare i32 @msequence_get_state(ptr noundef) #1

declare i32 @msequence_advance(ptr noundef) #1

declare i32 @msequence_destroy(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint nounwind willreturn memory(read) 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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}
!14 = distinct !{!14, !12}


; 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.3 = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @usage() local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %6, %2
  %.024 = phi i32 [ 2, %2 ], [ %9, %6 ]
  %4 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str.3) #6
  switch i32 %4, label %10 [
    i32 -1, label %11
    i32 104, label %5
    i32 100, label %6
  ]

5:                                                ; preds = %3
  tail call void @usage()
  br label %.loopexit

6:                                                ; preds = %3
  %7 = load ptr, ptr @optarg, align 8, !tbaa !5
  %8 = tail call i64 @atol(ptr nocapture noundef %7) #7
  %9 = trunc i64 %8 to i32
  br label %3, !llvm.loop !9

10:                                               ; preds = %3
  tail call void @exit(i32 noundef -1) #8
  unreachable

11:                                               ; preds = %3
  %12 = shl nuw i32 1, %.024
  %.fr = freeze i32 %12
  %13 = add i32 %.fr, -1
  %14 = lshr i32 %.fr, 1
  %15 = mul i32 %14, %13
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %.loopexit.loopexit, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %11, %21
  %.02534.us = phi i32 [ %23, %21 ], [ 0, %11 ]
  %16 = shl i32 %.02534.us, 1
  %17 = or disjoint i32 %16, 1
  %18 = tail call ptr @msequence_create(i32 noundef %.024, i32 noundef %17, i32 noundef 1) #6
  br label %24

19:                                               ; preds = %._crit_edge.us
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %.024, i32 noundef %17)
  br label %21

21:                                               ; preds = %19, %._crit_edge.us
  %22 = tail call i32 @msequence_destroy(ptr noundef %18) #6
  %23 = add i32 %.02534.us, 1
  %.not29.us = icmp ugt i32 %23, %13
  br i1 %.not29.us, label %.loopexit, label %.lr.ph.us, !llvm.loop !11

24:                                               ; preds = %.lr.ph.us, %24
  %.033.us = phi i32 [ 0, %.lr.ph.us ], [ %26, %24 ]
  %.02632.us = phi i32 [ 0, %.lr.ph.us ], [ %28, %24 ]
  %25 = tail call i32 @msequence_get_state(ptr noundef %18) #6
  %26 = add i32 %25, %.033.us
  %27 = tail call i32 @msequence_advance(ptr noundef %18) #6
  %28 = add nuw i32 %.02632.us, 1
  %exitcond.not = icmp eq i32 %28, %13
  br i1 %exitcond.not, label %._crit_edge.us, label %24, !llvm.loop !12

._crit_edge.us:                                   ; preds = %24
  %29 = icmp eq i32 %26, %15
  br i1 %29, label %19, label %21

.loopexit.loopexit:                               ; preds = %11
  %30 = tail call ptr @msequence_create(i32 noundef %.024, i32 noundef 1, i32 noundef 1) #6
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %.024, i32 noundef 1)
  %32 = tail call i32 @msequence_destroy(ptr noundef %30) #6
  br label %.loopexit

.loopexit:                                        ; preds = %21, %.loopexit.loopexit, %5
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i64 @atol(ptr nocapture noundef nonnull) local_unnamed_addr #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #4

declare ptr @msequence_create(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #5

declare i32 @msequence_get_state(ptr noundef) local_unnamed_addr #5

declare i32 @msequence_advance(ptr noundef) local_unnamed_addr #5

declare i32 @msequence_destroy(ptr noundef) local_unnamed_addr #5

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 = { nofree 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 = { 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #4 = { 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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