; 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 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@__PRETTY_FUNCTION__.vtenc_decode8_test_case = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [68 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @vtenc_decode8_test_case(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.DecodeTestCase, ptr %11, i32 0, i32 0
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DecodeTestCase, ptr %13, i32 0, i32 1
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.DecodeTestCaseInput, ptr %15, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = and i64 %17, 65535
  %19 = call ptr @llvm.stacksave.p0()
  store ptr %19, ptr %6, align 8
  %20 = alloca i8, i64 %18, align 16
  store i64 %18, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %21 = call ptr @vtenc_create()
  store ptr %21, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %1
  br label %26

25:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1259, ptr noundef @__PRETTY_FUNCTION__.vtenc_decode8_test_case) #7
  unreachable

26:                                               ; preds = %24
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.DecodeTestCaseInput, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.EncodingParams, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !14
  %32 = call i32 (ptr, i32, ...) @vtenc_config(ptr noundef %27, i32 noundef 0, i32 noundef %31)
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.DecodeTestCaseInput, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.EncodingParams, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !15
  %38 = call i32 (ptr, i32, ...) @vtenc_config(ptr noundef %33, i32 noundef 1, i32 noundef %37)
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.DecodeTestCaseInput, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.EncodingParams, ptr %41, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !16
  %44 = call i32 (ptr, i32, ...) @vtenc_config(ptr noundef %39, i32 noundef 2, i64 noundef %43)
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.DecodeTestCaseInput, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.DecodeTestCaseInput, ptr %49, i32 0, i32 2
  %51 = load i64, ptr %50, align 8, !tbaa !18
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.DecodeTestCaseInput, ptr %52, i32 0, i32 3
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = call i32 @vtenc_decode8(ptr noundef %45, ptr noundef %48, i64 noundef %51, ptr noundef %20, i64 noundef %54)
  store i32 %55, ptr %8, align 4, !tbaa !19
  br label %56

56:                                               ; preds = %26
  %57 = load i32, ptr %8, align 4, !tbaa !19
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.DecodeTestCaseOutput, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 8, !tbaa !20
  %61 = icmp eq i32 %57, %60
  br i1 %61, label %64, label %62

62:                                               ; preds = %56
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %83

64:                                               ; preds = %56
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %8, align 4, !tbaa !19
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %81

69:                                               ; preds = %66
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.DecodeTestCaseOutput, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !22
  %74 = call i32 @memcmp(ptr noundef %20, ptr noundef %73, i64 noundef %18) #8
  %75 = icmp eq i32 %74, 0
  br i1 %75, label %78, label %76

76:                                               ; preds = %70
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %83

78:                                               ; preds = %70
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80, %66
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  call void @vtenc_destroy(ptr noundef %82)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %83

83:                                               ; preds = %81, %76, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %84 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %84)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %85 = load i32, ptr %2, align 4
  ret i32 %85
}

; 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
declare ptr @llvm.stacksave.p0() #2

declare ptr @vtenc_create() #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

declare i32 @vtenc_config(ptr noundef, i32 noundef, ...) #3

declare i32 @vtenc_decode8(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #3

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #5

declare void @vtenc_destroy(ptr noundef) #3

; 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 nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { "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 willreturn memory(read) "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 = { noreturn nounwind }
attributes #8 = { nounwind willreturn memory(read) }

!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 = !{!10, !13, i64 32}
!10 = !{!"DecodeTestCaseInput", !11, i64 0, !6, i64 16, !13, i64 24, !13, i64 32}
!11 = !{!"EncodingParams", !12, i64 0, !12, i64 4, !13, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !12, i64 0}
!15 = !{!10, !12, i64 4}
!16 = !{!10, !13, i64 8}
!17 = !{!10, !6, i64 16}
!18 = !{!10, !13, i64 24}
!19 = !{!12, !12, i64 0}
!20 = !{!21, !12, i64 8}
!21 = !{!"DecodeTestCaseOutput", !6, i64 0, !12, i64 8}
!22 = !{!21, !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"

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@__PRETTY_FUNCTION__.vtenc_decode8_test_case = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [68 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @vtenc_decode8_test_case(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = and i64 %4, 65535
  %6 = alloca i8, i64 %5, align 16
  %7 = tail call ptr @vtenc_create() #5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %9

8:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1259, ptr noundef nonnull @__PRETTY_FUNCTION__.vtenc_decode8_test_case) #6
  unreachable

9:                                                ; preds = %1
  %10 = load i32, ptr %0, align 8, !tbaa !13
  %11 = tail call i32 (ptr, i32, ...) @vtenc_config(ptr noundef nonnull %7, i32 noundef 0, i32 noundef %10) #5
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = tail call i32 (ptr, i32, ...) @vtenc_config(ptr noundef nonnull %7, i32 noundef 1, i32 noundef %13) #5
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = tail call i32 (ptr, i32, ...) @vtenc_config(ptr noundef nonnull %7, i32 noundef 2, i64 noundef %16) #5
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load i64, ptr %20, align 8, !tbaa !17
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = call i32 @vtenc_decode8(ptr noundef nonnull %7, ptr noundef %19, i64 noundef %21, ptr noundef nonnull %6, i64 noundef %22) #5
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  %25 = load i32, ptr %24, align 8, !tbaa !18
  %26 = icmp eq i32 %23, %25
  br i1 %26, label %29, label %27

27:                                               ; preds = %9
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %37

29:                                               ; preds = %9
  %30 = icmp eq i32 %23, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %29
  %32 = load ptr, ptr %2, align 8, !tbaa !20
  %bcmp = call i32 @bcmp(ptr nonnull %6, ptr %32, i64 %5)
  %33 = icmp eq i32 %bcmp, 0
  br i1 %33, label %36, label %34

34:                                               ; preds = %31
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %37

36:                                               ; preds = %31, %29
  call void @vtenc_destroy(ptr noundef nonnull %7) #5
  br label %37

37:                                               ; preds = %36, %34, %27
  %.0 = phi i32 [ 1, %36 ], [ 0, %34 ], [ 0, %27 ]
  ret i32 %.0
}

declare ptr @vtenc_create() local_unnamed_addr #1

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

declare i32 @vtenc_config(ptr noundef, i32 noundef, ...) local_unnamed_addr #1

declare i32 @vtenc_decode8(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

declare void @vtenc_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #4

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 = { 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 = { 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 #4 = { nofree nounwind willreturn memory(argmem: read) }
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, !11, i64 32}
!6 = !{!"DecodeTestCaseInput", !7, i64 0, !12, i64 16, !11, i64 24, !11, i64 32}
!7 = !{!"EncodingParams", !8, i64 0, !8, i64 4, !11, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!6, !8, i64 0}
!14 = !{!6, !8, i64 4}
!15 = !{!6, !11, i64 8}
!16 = !{!6, !12, i64 16}
!17 = !{!6, !11, i64 24}
!18 = !{!19, !8, i64 8}
!19 = !{!"DecodeTestCaseOutput", !12, i64 0, !8, i64 8}
!20 = !{!19, !12, i64 0}


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