; LLVM IR from vteromero/VTEnc :: tests/unit (encode_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.EncodeTestCase = type { %struct.EncodeTestCaseInput, %struct.EncodeTestCaseOutput }
%struct.EncodeTestCaseInput = type { %struct.EncodingParams, ptr, i64 }
%struct.EncodingParams = type { i32, i32, i64 }
%struct.EncodeTestCaseOutput = type { ptr, i64, i32 }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.vtenc_encode16_test_case = external hidden unnamed_addr constant [54 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
declare ptr @llvm.stacksave.p0() #1

declare ptr @vtenc_create() #2

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

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

declare i64 @vtenc_encoded_size(ptr noundef) #2

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

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

declare void @vtenc_destroy(ptr noundef) #2

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

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

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

28:                                               ; preds = %1
  br label %30

29:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1150, ptr noundef @__PRETTY_FUNCTION__.vtenc_encode16_test_case) #7
  unreachable

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

60:                                               ; preds = %30
  %61 = load i64, ptr %9, align 8, !tbaa !14
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.EncodeTestCaseOutput, ptr %62, i32 0, i32 1
  %64 = load i64, ptr %63, align 8, !tbaa !20
  %65 = icmp eq i64 %61, %64
  br i1 %65, label %68, label %66

66:                                               ; preds = %60
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %12, align 4
  br label %97

68:                                               ; preds = %60
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  br label %71

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

80:                                               ; preds = %71
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %12, align 4
  br label %97

82:                                               ; preds = %71
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %10, align 4, !tbaa !19
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.EncodeTestCaseOutput, ptr %87, i32 0, i32 2
  %89 = load i32, ptr %88, align 8, !tbaa !23
  %90 = icmp eq i32 %86, %89
  br i1 %90, label %93, label %91

91:                                               ; preds = %85
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %12, align 4
  br label %97

93:                                               ; preds = %85
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  call void @vtenc_destroy(ptr noundef %96)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %12, align 4
  br label %97

97:                                               ; preds = %95, %91, %80, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  %98 = load ptr, ptr %7, align 8
  call void @llvm.stackrestore.p0(ptr %98)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %99 = load i32, ptr %2, align 4
  ret i32 %99
}

declare i64 @vtenc_max_encoded_size16(i64 noundef) #2

declare i32 @vtenc_encode16(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
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 = { 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 #4 = { 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 #5 = { 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 #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 24}
!10 = !{!"EncodeTestCaseInput", !11, i64 0, !6, i64 16, !13, i64 24}
!11 = !{!"EncodingParams", !12, i64 0, !12, i64 4, !13, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!10, !12, i64 0}
!16 = !{!10, !12, i64 4}
!17 = !{!10, !13, i64 8}
!18 = !{!10, !6, i64 16}
!19 = !{!12, !12, i64 0}
!20 = !{!21, !13, i64 8}
!21 = !{!"EncodeTestCaseOutput", !6, i64 0, !13, i64 8, !12, i64 16}
!22 = !{!21, !6, i64 0}
!23 = !{!21, !12, i64 16}


; 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
@.str.2 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.vtenc_encode16_test_case = external hidden unnamed_addr constant [54 x i8], align 1

declare ptr @vtenc_create() local_unnamed_addr #0

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

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

declare i64 @vtenc_encoded_size(ptr noundef) local_unnamed_addr #0

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

declare void @vtenc_destroy(ptr noundef) local_unnamed_addr #0

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

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

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

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

29:                                               ; preds = %10
  %30 = load ptr, ptr %2, align 8, !tbaa !19
  %bcmp = call i32 @bcmp(ptr nonnull %7, ptr %30, i64 %23)
  %31 = icmp eq i32 %bcmp, 0
  br i1 %31, label %34, label %32

32:                                               ; preds = %29
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %41

34:                                               ; preds = %29
  %35 = getelementptr inbounds i8, ptr %0, i64 48
  %36 = load i32, ptr %35, align 8, !tbaa !20
  %37 = icmp eq i32 %22, %36
  br i1 %37, label %40, label %38

38:                                               ; preds = %34
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %41

40:                                               ; preds = %34
  call void @vtenc_destroy(ptr noundef nonnull %8) #5
  br label %41

41:                                               ; preds = %40, %38, %32, %27
  %.0 = phi i32 [ 1, %40 ], [ 0, %38 ], [ 0, %32 ], [ 0, %27 ]
  ret i32 %.0
}

declare i64 @vtenc_max_encoded_size16(i64 noundef) local_unnamed_addr #0

declare i32 @vtenc_encode16(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

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 = { 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 #2 = { 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 #3 = { 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 = { 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 24}
!6 = !{!"EncodeTestCaseInput", !7, i64 0, !12, i64 16, !11, i64 24}
!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 = !{!18, !11, i64 8}
!18 = !{!"EncodeTestCaseOutput", !12, i64 0, !11, i64 8, !8, i64 16}
!19 = !{!18, !12, i64 0}
!20 = !{!18, !8, i64 16}


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