; LLVM IR from dbry/wavpack-stream :: cli (utils)

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

@waiting_input = external hidden global i32, align 4
@stdin = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1

; 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 signext i8 @yna() #1 {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #5
  store i8 0, ptr %1, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr @waiting_input, align 4, !tbaa !8
  br label %3

3:                                                ; preds = %69, %0
  br label %4

4:                                                ; preds = %3
  %5 = load ptr, ptr @stdin, align 8, !tbaa !10
  %6 = call i32 @fgetc(ptr noundef %5)
  store i32 %6, ptr %2, align 4, !tbaa !8
  %7 = load i32, ptr %2, align 4, !tbaa !8
  %8 = icmp eq i32 %7, 3
  br i1 %8, label %9, label %12

9:                                                ; preds = %4
  %10 = load ptr, ptr @stderr, align 8, !tbaa !10
  %11 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef @.str.3) #5
  call void @exit(i32 noundef 1) #6
  unreachable

12:                                               ; preds = %4
  %13 = load i32, ptr %2, align 4, !tbaa !8
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  %16 = load ptr, ptr @stderr, align 8, !tbaa !10
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.4) #5
  call void @exit(i32 noundef 1) #6
  unreachable

18:                                               ; preds = %12
  %19 = load i32, ptr %2, align 4, !tbaa !8
  %20 = icmp eq i32 %19, 13
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %2, align 4, !tbaa !8
  %23 = icmp eq i32 %22, 10
  br i1 %23, label %24, label %38

24:                                               ; preds = %21, %18
  %25 = load i8, ptr %1, align 1, !tbaa !5
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = load ptr, ptr @stderr, align 8, !tbaa !10
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.4) #5
  %30 = load ptr, ptr @stderr, align 8, !tbaa !10
  %31 = call i32 @fflush(ptr noundef %30)
  br label %70

32:                                               ; preds = %24
  %33 = load ptr, ptr @stderr, align 8, !tbaa !10
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.5, i32 noundef 7) #5
  %35 = load ptr, ptr @stderr, align 8, !tbaa !10
  %36 = call i32 @fflush(ptr noundef %35)
  br label %37

37:                                               ; preds = %32
  br label %67

38:                                               ; preds = %21
  %39 = load i32, ptr %2, align 4, !tbaa !8
  %40 = icmp eq i32 %39, 89
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %2, align 4, !tbaa !8
  %43 = icmp eq i32 %42, 121
  br i1 %43, label %44, label %45

44:                                               ; preds = %41, %38
  store i8 121, ptr %1, align 1, !tbaa !5
  br label %66

45:                                               ; preds = %41
  %46 = load i32, ptr %2, align 4, !tbaa !8
  %47 = icmp eq i32 %46, 78
  br i1 %47, label %51, label %48

48:                                               ; preds = %45
  %49 = load i32, ptr %2, align 4, !tbaa !8
  %50 = icmp eq i32 %49, 110
  br i1 %50, label %51, label %52

51:                                               ; preds = %48, %45
  store i8 110, ptr %1, align 1, !tbaa !5
  br label %65

52:                                               ; preds = %48
  %53 = load i32, ptr %2, align 4, !tbaa !8
  %54 = icmp eq i32 %53, 65
  br i1 %54, label %58, label %55

55:                                               ; preds = %52
  %56 = load i32, ptr %2, align 4, !tbaa !8
  %57 = icmp eq i32 %56, 97
  br i1 %57, label %58, label %59

58:                                               ; preds = %55, %52
  store i8 97, ptr %1, align 1, !tbaa !5
  br label %64

59:                                               ; preds = %55
  %60 = load ptr, ptr @stderr, align 8, !tbaa !10
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.5, i32 noundef 7) #5
  %62 = load ptr, ptr @stderr, align 8, !tbaa !10
  %63 = call i32 @fflush(ptr noundef %62)
  br label %64

64:                                               ; preds = %59, %58
  br label %65

65:                                               ; preds = %64, %51
  br label %66

66:                                               ; preds = %65, %44
  br label %67

67:                                               ; preds = %66, %37
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  br label %3

70:                                               ; preds = %27
  store i32 0, ptr @waiting_input, align 4, !tbaa !8
  %71 = load i8, ptr %1, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #5
  ret i8 %71
}

declare i32 @fgetc(ptr noundef) #2

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

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

declare i32 @fflush(ptr noundef) #2

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 = { "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 "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 = { nounwind }
attributes #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}


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

@waiting_input = external hidden local_unnamed_addr global i32, align 4
@stdin = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local signext range(i8 1, 122) i8 @yna() local_unnamed_addr #0 {
  store i32 1, ptr @waiting_input, align 4, !tbaa !5
  br label %.outer

.outer:                                           ; preds = %.outer.backedge, %0
  %.0.ph = phi i8 [ 0, %0 ], [ %.0.ph.be, %.outer.backedge ]
  br label %1

1:                                                ; preds = %.outer, %22
  %2 = load ptr, ptr @stdin, align 8, !tbaa !9
  %3 = tail call i32 @fgetc(ptr noundef %2)
  switch i32 %3, label %20 [
    i32 3, label %4
    i32 -1, label %7
    i32 13, label %10
    i32 10, label %10
  ]

4:                                                ; preds = %1
  %5 = load ptr, ptr @stderr, align 8, !tbaa !9
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.3) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

7:                                                ; preds = %1
  %8 = load ptr, ptr @stderr, align 8, !tbaa !9
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.4) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

10:                                               ; preds = %1, %1
  %.not = icmp eq i8 %.0.ph, 0
  %11 = load ptr, ptr @stderr, align 8, !tbaa !9
  br i1 %.not, label %16, label %12

12:                                               ; preds = %10
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.4) #3
  %14 = load ptr, ptr @stderr, align 8, !tbaa !9
  %15 = tail call i32 @fflush(ptr noundef %14)
  store i32 0, ptr @waiting_input, align 4, !tbaa !5
  ret i8 %.0.ph

16:                                               ; preds = %10
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.5, i32 noundef 7) #3
  %18 = load ptr, ptr @stderr, align 8, !tbaa !9
  %19 = tail call i32 @fflush(ptr noundef %18)
  br label %.outer.backedge

.outer.backedge:                                  ; preds = %20, %16, %.fold.split, %.fold.split20
  %.0.ph.be = phi i8 [ 97, %.fold.split20 ], [ 110, %.fold.split ], [ 0, %16 ], [ 121, %20 ]
  br label %.outer

20:                                               ; preds = %1
  %21 = and i32 %3, -33
  switch i32 %21, label %22 [
    i32 89, label %.outer.backedge
    i32 78, label %.fold.split
    i32 65, label %.fold.split20
  ]

22:                                               ; preds = %20
  %23 = load ptr, ptr @stderr, align 8, !tbaa !9
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.5, i32 noundef 7) #3
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = tail call i32 @fflush(ptr noundef %25)
  br label %1

.fold.split:                                      ; preds = %20
  br label %.outer.backedge

.fold.split20:                                    ; preds = %20
  br label %.outer.backedge
}

; Function Attrs: nofree nounwind
declare noundef i32 @fgetc(ptr nocapture noundef) local_unnamed_addr #1

; 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 #2

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #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 = { 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 = { 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 #3 = { cold nounwind }
attributes #4 = { 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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass