; LLVM IR from jgaeddert/liquid-dsp :: examples (crc_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.4 = external hidden unnamed_addr constant [7 x i8], align 1
@optarg = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [7 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 ptr, align 8
  %12 = alloca i64, align 8
  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) #7
  store i32 32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 6, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  br label %13

13:                                               ; preds = %35, %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = call i32 @getopt(i32 noundef %14, ptr noundef %15, ptr noundef @.str.4) #7
  store i32 %16, ptr %8, align 4, !tbaa !5
  %17 = icmp ne i32 %16, -1
  br i1 %17, label %18, label %36

18:                                               ; preds = %13
  %19 = load i32, ptr %8, align 4, !tbaa !5
  switch i32 %19, label %34 [
    i32 104, label %20
    i32 117, label %20
    i32 110, label %21
    i32 118, label %24
  ]

20:                                               ; preds = %18, %18
  call void @usage()
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %79

21:                                               ; preds = %18
  %22 = load ptr, ptr @optarg, align 8, !tbaa !9
  %23 = call i32 @atoi(ptr noundef %22) #8
  store i32 %23, ptr %6, align 4, !tbaa !5
  br label %35

24:                                               ; preds = %18
  %25 = load ptr, ptr @optarg, align 8, !tbaa !9
  %26 = call i32 @liquid_getopt_str2crc(ptr noundef %25)
  store i32 %26, ptr %7, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %33

29:                                               ; preds = %24
  %30 = load ptr, ptr @stderr, align 8, !tbaa !9
  %31 = load ptr, ptr @optarg, align 8, !tbaa !9
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.5, ptr noundef %31) #7
  call void @exit(i32 noundef 1) #9
  unreachable

33:                                               ; preds = %24
  br label %35

34:                                               ; preds = %18
  call void @exit(i32 noundef 1) #9
  unreachable

35:                                               ; preds = %33, %21
  br label %13, !llvm.loop !11

36:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = add i32 %37, 4
  %39 = zext i32 %38 to i64
  %40 = call ptr @llvm.stacksave.p0()
  store ptr %40, ptr %11, align 8
  %41 = alloca i8, i64 %39, align 16
  store i64 %39, ptr %12, align 8
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %53, %36
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = icmp ult i32 %43, %44
  br i1 %45, label %46, label %56

46:                                               ; preds = %42
  %47 = call i32 @rand() #7
  %48 = and i32 %47, 255
  %49 = trunc i32 %48 to i8
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %41, i64 %51
  store i8 %49, ptr %52, align 1, !tbaa !13
  br label %53

53:                                               ; preds = %46
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = add i32 %54, 1
  store i32 %55, ptr %10, align 4, !tbaa !5
  br label %42, !llvm.loop !14

56:                                               ; preds = %42
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = call i32 @crc_append_key(i32 noundef %57, ptr noundef %41, i32 noundef %58)
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = call i32 @crc_check_key(i32 noundef %60, ptr noundef %41, i32 noundef %61)
  %63 = icmp ne i32 %62, 0
  %64 = zext i1 %63 to i64
  %65 = select i1 %63, ptr @.str.7, ptr @.str.8
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %65)
  %67 = getelementptr inbounds i8, ptr %41, i64 0
  %68 = load i8, ptr %67, align 16, !tbaa !13
  %69 = add i8 %68, 1
  store i8 %69, ptr %67, align 16, !tbaa !13
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = call i32 @crc_check_key(i32 noundef %70, ptr noundef %41, i32 noundef %71)
  %73 = icmp ne i32 %72, 0
  %74 = zext i1 %73 to i64
  %75 = select i1 %73, ptr @.str.7, ptr @.str.10
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, ptr noundef %75)
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  %78 = load ptr, ptr %11, align 8
  call void @llvm.stackrestore.p0(ptr %78)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %79

79:                                               ; preds = %56, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %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 i32 @atoi(ptr noundef nonnull) #4

declare i32 @liquid_getopt_str2crc(ptr noundef) #1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #6

; Function Attrs: nounwind
declare i32 @rand() #3

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #6

; 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 = { nocallback nofree nosync nounwind willreturn }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!7, !7, i64 0}
!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.4 = external hidden unnamed_addr constant [7 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [7 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 %.outer

.outer:                                           ; preds = %9, %2
  %.018.ph = phi i32 [ %11, %9 ], [ 6, %2 ]
  %.016.ph = phi i32 [ %.016, %9 ], [ 32, %2 ]
  br label %3

3:                                                ; preds = %.outer, %6
  %.016 = phi i32 [ %8, %6 ], [ %.016.ph, %.outer ]
  %4 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str.4) #7
  switch i32 %4, label %17 [
    i32 -1, label %18
    i32 104, label %5
    i32 117, label %5
    i32 110, label %6
    i32 118, label %9
  ]

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

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

9:                                                ; preds = %3
  %10 = load ptr, ptr @optarg, align 8, !tbaa !5
  %11 = tail call i32 @liquid_getopt_str2crc(ptr noundef %10) #7
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %.outer, !llvm.loop !9

13:                                               ; preds = %9
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = load ptr, ptr @optarg, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.5, ptr noundef %15) #9
  tail call void @exit(i32 noundef 1) #10
  unreachable

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

18:                                               ; preds = %3
  %19 = add i32 %.016, 4
  %20 = zext i32 %19 to i64
  %21 = tail call ptr @llvm.stacksave.p0()
  %22 = alloca i8, i64 %20, align 16
  %.not = icmp eq i32 %.016, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %18
  %wide.trip.count = zext i32 %.016 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %23 = tail call i32 @rand() #7
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds i8, ptr %22, i64 %indvars.iv
  store i8 %24, ptr %25, align 1, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %18
  %26 = call i32 @crc_append_key(i32 noundef %.018.ph, ptr noundef nonnull %22, i32 noundef %.016) #7
  %27 = call i32 @crc_check_key(i32 noundef %.018.ph, ptr noundef nonnull %22, i32 noundef %.016) #7
  %.not21 = icmp eq i32 %27, 0
  %28 = select i1 %.not21, ptr @.str.8, ptr @.str.7
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %28)
  %30 = load i8, ptr %22, align 16, !tbaa !11
  %31 = add i8 %30, 1
  store i8 %31, ptr %22, align 16, !tbaa !11
  %32 = call i32 @crc_check_key(i32 noundef %.018.ph, ptr noundef nonnull %22, i32 noundef %.016) #7
  %.not22 = icmp eq i32 %32, 0
  %33 = select i1 %.not22, ptr @.str.10, ptr @.str.7
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, ptr noundef nonnull %33)
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  call void @llvm.stackrestore.p0(ptr %21)
  br label %36

36:                                               ; preds = %._crit_edge, %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 i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #3

declare i32 @liquid_getopt_str2crc(ptr noundef) local_unnamed_addr #4

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #6

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

declare i32 @crc_append_key(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare i32 @crc_check_key(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #6

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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { cold nounwind }
attributes #10 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


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