; LLVM IR from vteromero/VTEnc :: tests (encdec)

; 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.EncDec = type { i32, i32, i64, %struct.EncDecCtx, ptr }
%struct.EncDecCtx = type { ptr, i64, ptr, i64, ptr, i64 }
%struct.EncDecFuncs = type { ptr, ptr, ptr, ptr }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 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 ptr @vtenc_create() #1

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

declare void @vtenc_destroy(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
define dso_local i32 @encdec_decode(ptr noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %8 = call ptr @vtenc_create()
  store ptr %8, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str.3) #5
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

14:                                               ; preds = %1
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.EncDec, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = call i32 (ptr, i32, ...) @vtenc_config(ptr noundef %15, i32 noundef 0, i32 noundef %18)
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EncDec, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = call i32 (ptr, i32, ...) @vtenc_config(ptr noundef %20, i32 noundef 1, i32 noundef %23)
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.EncDec, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !16
  %29 = call i32 (ptr, i32, ...) @vtenc_config(ptr noundef %25, i32 noundef 2, i64 noundef %28)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EncDec, ptr %30, i32 0, i32 3
  %32 = getelementptr inbounds %struct.EncDecCtx, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.EncDec, ptr %34, i32 0, i32 3
  %36 = getelementptr inbounds %struct.EncDecCtx, ptr %35, i32 0, i32 5
  store i64 %33, ptr %36, align 8, !tbaa !18
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EncDec, ptr %37, i32 0, i32 3
  %39 = getelementptr inbounds %struct.EncDecCtx, ptr %38, i32 0, i32 5
  %40 = load i64, ptr %39, align 8, !tbaa !18
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.EncDec, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !19
  %44 = getelementptr inbounds %struct.EncDecFuncs, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !20
  %46 = call i64 (...) %45()
  %47 = mul i64 %40, %46
  %48 = call noalias ptr @malloc(i64 noundef %47) #6
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EncDec, ptr %49, i32 0, i32 3
  %51 = getelementptr inbounds %struct.EncDecCtx, ptr %50, i32 0, i32 4
  store ptr %48, ptr %51, align 8, !tbaa !22
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EncDec, ptr %52, i32 0, i32 3
  %54 = getelementptr inbounds %struct.EncDecCtx, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !22
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %60

57:                                               ; preds = %14
  %58 = load ptr, ptr @stderr, align 8, !tbaa !5
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef @.str.1) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %91

60:                                               ; preds = %14
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.EncDec, ptr %61, i32 0, i32 4
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = getelementptr inbounds %struct.EncDecFuncs, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !23
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.EncDec, ptr %67, i32 0, i32 3
  %69 = getelementptr inbounds %struct.EncDecCtx, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !24
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.EncDec, ptr %71, i32 0, i32 3
  %73 = getelementptr inbounds %struct.EncDecCtx, ptr %72, i32 0, i32 3
  %74 = load i64, ptr %73, align 8, !tbaa !25
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.EncDec, ptr %75, i32 0, i32 3
  %77 = getelementptr inbounds %struct.EncDecCtx, ptr %76, i32 0, i32 4
  %78 = load ptr, ptr %77, align 8, !tbaa !22
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.EncDec, ptr %79, i32 0, i32 3
  %81 = getelementptr inbounds %struct.EncDecCtx, ptr %80, i32 0, i32 5
  %82 = load i64, ptr %81, align 8, !tbaa !18
  %83 = call i32 %65(ptr noundef %66, ptr noundef %70, i64 noundef %74, ptr noundef %78, i64 noundef %82)
  store i32 %83, ptr %4, align 4, !tbaa !9
  %84 = load i32, ptr %4, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %90

86:                                               ; preds = %60
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = load i32, ptr %4, align 4, !tbaa !9
  %89 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str.4, i32 noundef %88) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %91

90:                                               ; preds = %60
  br label %91

91:                                               ; preds = %90, %86, %57
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vtenc_destroy(ptr noundef %92)
  %93 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %93, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

94:                                               ; preds = %91, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %95 = load i32, ptr %2, align 4
  ret i32 %95
}

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 "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 allocsize(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 }
attributes #6 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"EncDec", !10, i64 0, !10, i64 4, !13, i64 8, !14, i64 16, !6, i64 64}
!13 = !{!"long", !7, i64 0}
!14 = !{!"EncDecCtx", !6, i64 0, !13, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !13, i64 40}
!15 = !{!12, !10, i64 4}
!16 = !{!12, !13, i64 8}
!17 = !{!12, !13, i64 24}
!18 = !{!12, !13, i64 56}
!19 = !{!12, !6, i64 64}
!20 = !{!21, !6, i64 0}
!21 = !{!"EncDecFuncs", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!22 = !{!12, !6, i64 48}
!23 = !{!21, !6, i64 24}
!24 = !{!12, !6, i64 32}
!25 = !{!12, !13, i64 40}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1

declare ptr @vtenc_create() local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) 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 @encdec_decode(ptr nocapture noundef %0) local_unnamed_addr #3 {
  %2 = tail call ptr @vtenc_create() #4
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %7

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

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

27:                                               ; preds = %7
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.1) #5
  br label %43

30:                                               ; preds = %7
  %31 = load ptr, ptr %19, align 8, !tbaa !18
  %32 = getelementptr inbounds i8, ptr %31, i64 24
  %33 = load ptr, ptr %32, align 8, !tbaa !22
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  %35 = load ptr, ptr %34, align 8, !tbaa !23
  %36 = getelementptr inbounds i8, ptr %0, i64 40
  %37 = load i64, ptr %36, align 8, !tbaa !24
  %38 = load i64, ptr %18, align 8, !tbaa !17
  %39 = tail call i32 %33(ptr noundef nonnull %2, ptr noundef %35, i64 noundef %37, ptr noundef nonnull %24, i64 noundef %38) #4
  %.not = icmp eq i32 %39, 0
  br i1 %.not, label %43, label %40

40:                                               ; preds = %30
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.4, i32 noundef %39) #5
  br label %43

43:                                               ; preds = %30, %40, %27
  %.023 = phi i32 [ 0, %27 ], [ 0, %40 ], [ 1, %30 ]
  tail call void @vtenc_destroy(ptr noundef nonnull %2) #4
  br label %44

44:                                               ; preds = %43, %4
  %.0 = phi i32 [ 0, %4 ], [ %.023, %43 ]
  ret i32 %.0
}

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 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind }
attributes #5 = { cold nounwind }
attributes #6 = { nounwind allocsize(0) }

!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, !11, i64 0}
!10 = !{!"EncDec", !11, i64 0, !11, i64 4, !12, i64 8, !13, i64 16, !6, i64 64}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"EncDecCtx", !6, i64 0, !12, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !12, i64 40}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !12, i64 8}
!16 = !{!10, !12, i64 24}
!17 = !{!10, !12, i64 56}
!18 = !{!10, !6, i64 64}
!19 = !{!20, !6, i64 0}
!20 = !{!"EncDecFuncs", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!10, !6, i64 48}
!22 = !{!20, !6, i64 24}
!23 = !{!10, !6, i64 32}
!24 = !{!10, !12, i64 40}


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