; LLVM IR from vteromero/VTEnc :: tests/unit (bitstream_test)

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

@__const.test_bsreader_size.buf = external hidden unnamed_addr constant [12 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [42 x i8], align 1

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

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bsreader_init(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @bsreader_read(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @test_bsreader_size() #4 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.bsreader, align 8
  %3 = alloca [12 x i8], align 1
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 40, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 @__const.test_bsreader_size.buf, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 12, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds [12 x i8], ptr %3, i64 0, i64 0
  call void @bsreader_init(ptr noundef %2, ptr noundef %6, i64 noundef 12)
  br label %7

7:                                                ; preds = %0
  %8 = call i64 @bsreader_size(ptr noundef %2)
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %12, label %10

10:                                               ; preds = %7
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.40)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

12:                                               ; preds = %7
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  %15 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 1)
  br label %16

16:                                               ; preds = %14
  %17 = call i64 @bsreader_size(ptr noundef %2)
  %18 = icmp eq i64 %17, 1
  br i1 %18, label %21, label %19

19:                                               ; preds = %16
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.41)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 5)
  br label %25

25:                                               ; preds = %23
  %26 = call i64 @bsreader_size(ptr noundef %2)
  %27 = icmp eq i64 %26, 1
  br i1 %27, label %30, label %28

28:                                               ; preds = %25
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.41)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

30:                                               ; preds = %25
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 5)
  br label %34

34:                                               ; preds = %32
  %35 = call i64 @bsreader_size(ptr noundef %2)
  %36 = icmp eq i64 %35, 2
  br i1 %36, label %39, label %37

37:                                               ; preds = %34
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.42)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

39:                                               ; preds = %34
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 5)
  br label %43

43:                                               ; preds = %41
  %44 = call i64 @bsreader_size(ptr noundef %2)
  %45 = icmp eq i64 %44, 2
  br i1 %45, label %48, label %46

46:                                               ; preds = %43
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.42)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

48:                                               ; preds = %43
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 1)
  br label %52

52:                                               ; preds = %50
  %53 = call i64 @bsreader_size(ptr noundef %2)
  %54 = icmp eq i64 %53, 3
  br i1 %54, label %57, label %55

55:                                               ; preds = %52
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.43)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

57:                                               ; preds = %52
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  %60 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 20)
  br label %61

61:                                               ; preds = %59
  %62 = call i64 @bsreader_size(ptr noundef %2)
  %63 = icmp eq i64 %62, 5
  br i1 %63, label %66, label %64

64:                                               ; preds = %61
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.44)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

66:                                               ; preds = %61
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 40)
  br label %70

70:                                               ; preds = %68
  %71 = call i64 @bsreader_size(ptr noundef %2)
  %72 = icmp eq i64 %71, 10
  br i1 %72, label %75, label %73

73:                                               ; preds = %70
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.45)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

75:                                               ; preds = %70
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = call i64 @bsreader_read(ptr noundef %2, i32 noundef 16)
  br label %79

79:                                               ; preds = %77
  %80 = call i64 @bsreader_size(ptr noundef %2)
  %81 = icmp eq i64 %80, 12
  br i1 %81, label %84, label %82

82:                                               ; preds = %79
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.46)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

84:                                               ; preds = %79
  br label %85

85:                                               ; preds = %84
  br label %86

86:                                               ; preds = %85
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %87

87:                                               ; preds = %86, %82, %73, %64, %55, %46, %37, %28, %19, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %2) #5
  %88 = load i32, ptr %1, align 4
  ret i32 %88
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @bsreader_size(ptr noundef) #3

attributes #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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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 #5 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

@__const.test_bsreader_size.buf = external hidden unnamed_addr constant [12 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [42 x i8], align 1

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bsreader_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @bsreader_read(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @test_bsreader_size() local_unnamed_addr #4 {
  %1 = alloca %struct.bsreader, align 8
  %2 = alloca [12 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(12) %2, ptr noundef nonnull align 1 dereferenceable(12) @__const.test_bsreader_size.buf, i64 12, i1 false)
  call void @bsreader_init(ptr noundef nonnull %1, ptr noundef nonnull %2, i64 noundef 12)
  %3 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %5, label %.sink.split

5:                                                ; preds = %0
  %6 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 1)
  %7 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %8 = icmp eq i64 %7, 1
  br i1 %8, label %9, label %.sink.split

9:                                                ; preds = %5
  %10 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 5)
  %11 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %12 = icmp eq i64 %11, 1
  br i1 %12, label %13, label %.sink.split

13:                                               ; preds = %9
  %14 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 5)
  %15 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %16 = icmp eq i64 %15, 2
  br i1 %16, label %17, label %.sink.split

17:                                               ; preds = %13
  %18 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 5)
  %19 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %20 = icmp eq i64 %19, 2
  br i1 %20, label %21, label %.sink.split

21:                                               ; preds = %17
  %22 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 1)
  %23 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %24 = icmp eq i64 %23, 3
  br i1 %24, label %25, label %.sink.split

25:                                               ; preds = %21
  %26 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 20)
  %27 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %28 = icmp eq i64 %27, 5
  br i1 %28, label %29, label %.sink.split

29:                                               ; preds = %25
  %30 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 40)
  %31 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %32 = icmp eq i64 %31, 10
  br i1 %32, label %33, label %.sink.split

33:                                               ; preds = %29
  %34 = call i64 @bsreader_read(ptr noundef nonnull %1, i32 noundef 16)
  %35 = call i64 @bsreader_size(ptr noundef nonnull %1)
  %36 = icmp eq i64 %35, 12
  br i1 %36, label %38, label %.sink.split

.sink.split:                                      ; preds = %33, %29, %25, %21, %17, %13, %9, %5, %0
  %.str.46.sink = phi ptr [ @.str.40, %0 ], [ @.str.41, %5 ], [ @.str.41, %9 ], [ @.str.42, %13 ], [ @.str.42, %17 ], [ @.str.43, %21 ], [ @.str.44, %25 ], [ @.str.45, %29 ], [ @.str.46, %33 ]
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.46.sink)
  br label %38

38:                                               ; preds = %.sink.split, %33
  %.0 = phi i32 [ 1, %33 ], [ 0, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %1) #5
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @bsreader_size(ptr noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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 #5 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass