; LLVM IR from vteromero/VTEnc :: tests/unit (decode_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.DecodeTestCase = type { %struct.DecodeTestCaseInput, %struct.DecodeTestCaseOutput }
%struct.DecodeTestCaseInput = type { %struct.EncodingParams, ptr, i64, i64 }
%struct.EncodingParams = type { i32, i32, i64 }
%struct.DecodeTestCaseOutput = type { ptr, i32 }

@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@test_cases16 = external hidden global [16 x %struct.DecodeTestCase], align 16
@.str.6 = external hidden unnamed_addr constant [59 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

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

; 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
declare dso_local i32 @vtenc_decode16_test_case(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @test_vtenc_decode16() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca [30 x i8], align 16
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 16, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 30, ptr %4) #4
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %24, %0
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp ult i64 %7, 16
  br i1 %8, label %9, label %27

9:                                                ; preds = %6
  %10 = getelementptr inbounds [30 x i8], ptr %4, i64 0, i64 0
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %10, ptr noundef @.str.4, i64 noundef %11) #4
  br label %13

13:                                               ; preds = %9
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds [16 x %struct.DecodeTestCase], ptr @test_cases16, i64 0, i64 %14
  %16 = call i32 @vtenc_decode16_test_case(ptr noundef %15)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %21, label %18

18:                                               ; preds = %13
  %19 = getelementptr inbounds [30 x i8], ptr %4, i64 0, i64 0
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %19)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %28

21:                                               ; preds = %13
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = add i64 %25, 1
  store i64 %26, ptr %3, align 8, !tbaa !5
  br label %6, !llvm.loop !9

27:                                               ; preds = %6
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %28

28:                                               ; preds = %27, %18
  call void @llvm.lifetime.end.p0(i64 30, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %29 = load i32, ptr %1, align 4
  ret i32 %29
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = { 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"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

%struct.DecodeTestCase = type { %struct.DecodeTestCaseInput, %struct.DecodeTestCaseOutput }
%struct.DecodeTestCaseInput = type { %struct.EncodingParams, ptr, i64, i64 }
%struct.EncodingParams = type { i32, i32, i64 }
%struct.DecodeTestCaseOutput = type { ptr, i32 }

@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@test_cases16 = external hidden global [16 x %struct.DecodeTestCase], align 16
@.str.6 = external hidden unnamed_addr constant [59 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @vtenc_decode16_test_case(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @test_vtenc_decode16() local_unnamed_addr #2 {
  %1 = alloca [30 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 30, ptr nonnull %1) #3
  %2 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 0) #3
  %3 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull @test_cases16)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %49, label %4

4:                                                ; preds = %0
  %5 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 1) #3
  %6 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 56))
  %.not.1 = icmp eq i32 %6, 0
  br i1 %.not.1, label %49, label %7

7:                                                ; preds = %4
  %8 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 2) #3
  %9 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 112))
  %.not.2 = icmp eq i32 %9, 0
  br i1 %.not.2, label %49, label %10

10:                                               ; preds = %7
  %11 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 3) #3
  %12 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 168))
  %.not.3 = icmp eq i32 %12, 0
  br i1 %.not.3, label %49, label %13

13:                                               ; preds = %10
  %14 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 4) #3
  %15 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 224))
  %.not.4 = icmp eq i32 %15, 0
  br i1 %.not.4, label %49, label %16

16:                                               ; preds = %13
  %17 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 5) #3
  %18 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 280))
  %.not.5 = icmp eq i32 %18, 0
  br i1 %.not.5, label %49, label %19

19:                                               ; preds = %16
  %20 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 6) #3
  %21 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 336))
  %.not.6 = icmp eq i32 %21, 0
  br i1 %.not.6, label %49, label %22

22:                                               ; preds = %19
  %23 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 7) #3
  %24 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 392))
  %.not.7 = icmp eq i32 %24, 0
  br i1 %.not.7, label %49, label %25

25:                                               ; preds = %22
  %26 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 8) #3
  %27 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 448))
  %.not.8 = icmp eq i32 %27, 0
  br i1 %.not.8, label %49, label %28

28:                                               ; preds = %25
  %29 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 9) #3
  %30 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 504))
  %.not.9 = icmp eq i32 %30, 0
  br i1 %.not.9, label %49, label %31

31:                                               ; preds = %28
  %32 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 10) #3
  %33 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 560))
  %.not.10 = icmp eq i32 %33, 0
  br i1 %.not.10, label %49, label %34

34:                                               ; preds = %31
  %35 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 11) #3
  %36 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 616))
  %.not.11 = icmp eq i32 %36, 0
  br i1 %.not.11, label %49, label %37

37:                                               ; preds = %34
  %38 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 12) #3
  %39 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 672))
  %.not.12 = icmp eq i32 %39, 0
  br i1 %.not.12, label %49, label %40

40:                                               ; preds = %37
  %41 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 13) #3
  %42 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 728))
  %.not.13 = icmp eq i32 %42, 0
  br i1 %.not.13, label %49, label %43

43:                                               ; preds = %40
  %44 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 14) #3
  %45 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 784))
  %.not.14 = icmp eq i32 %45, 0
  br i1 %.not.14, label %49, label %46

46:                                               ; preds = %43
  %47 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef 15) #3
  %48 = tail call i32 @vtenc_decode16_test_case(ptr noundef nonnull getelementptr inbounds (i8, ptr @test_cases16, i64 840))
  %.not.15 = icmp eq i32 %48, 0
  br i1 %.not.15, label %49, label %.loopexit

49:                                               ; preds = %46, %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4, %0
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %1)
  br label %.loopexit

.loopexit:                                        ; preds = %46, %49
  %.05 = phi i32 [ 0, %49 ], [ 1, %46 ]
  call void @llvm.lifetime.end.p0(i64 30, ptr nonnull %1) #3
  ret i32 %.05
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { 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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass