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

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

@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 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 memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @encode_and_decode_set(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %struct.EncDec, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr %8) #4
  call void @encdec_init32(ptr noundef %8)
  %10 = getelementptr inbounds %struct.EncDec, ptr %8, i32 0, i32 0
  store i32 0, ptr %10, align 8, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = call i32 @encdec_encode(ptr noundef %8, ptr noundef %11, i64 noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef @.str.4) #4
  call void @encdec_free(ptr noundef %8)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %50

19:                                               ; preds = %3
  %20 = call i32 @encdec_decode(ptr noundef %8)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %25, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.5) #4
  call void @encdec_free(ptr noundef %8)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %50

25:                                               ; preds = %19
  %26 = call i32 @encdec_check_equality(ptr noundef %8)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.6) #4
  call void @encdec_free(ptr noundef %8)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %50

31:                                               ; preds = %25
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Stats, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !15
  %35 = add i64 %34, 1
  store i64 %35, ptr %33, align 8, !tbaa !15
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = mul i64 %37, 4
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Stats, ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !17
  %42 = add i64 %41, %38
  store i64 %42, ptr %40, align 8, !tbaa !17
  %43 = getelementptr inbounds %struct.EncDec, ptr %8, i32 0, i32 3
  %44 = getelementptr inbounds %struct.EncDecCtx, ptr %43, i32 0, i32 3
  %45 = load i64, ptr %44, align 8, !tbaa !18
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Stats, ptr %46, i32 0, i32 2
  %48 = load i64, ptr %47, align 8, !tbaa !19
  %49 = add i64 %48, %45
  store i64 %49, ptr %47, align 8, !tbaa !19
  call void @encdec_free(ptr noundef %8)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %50

50:                                               ; preds = %31, %28, %22, %16
  call void @llvm.lifetime.end.p0(i64 72, ptr %8) #4
  %51 = load i32, ptr %4, align 4
  ret i32 %51
}

declare void @encdec_init32(ptr noundef) #2

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

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

declare void @encdec_free(ptr noundef) #2

declare i32 @encdec_decode(ptr noundef) #2

declare i32 @encdec_check_equality(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"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 = !{!16, !13, i64 0}
!16 = !{!"Stats", !13, i64 0, !13, i64 8, !13, i64 16}
!17 = !{!16, !13, i64 8}
!18 = !{!12, !13, i64 40}
!19 = !{!16, !13, 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"

%struct.EncDec = type { i32, i32, i64, %struct.EncDecCtx, ptr }
%struct.EncDecCtx = type { ptr, i64, ptr, i64, ptr, i64 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 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: mustprogress 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 range(i32 0, 2) i32 @encode_and_decode_set(ptr noundef %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.EncDec, align 8
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %4) #4
  call void @encdec_init32(ptr noundef nonnull %4) #4
  store i32 0, ptr %4, align 8, !tbaa !5
  %5 = zext i32 %1 to i64
  %6 = call i32 @encdec_encode(ptr noundef nonnull %4, ptr noundef %0, i64 noundef %5) #4
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %10

7:                                                ; preds = %3
  %8 = load ptr, ptr @stderr, align 8, !tbaa !13
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.4) #5
  br label %30

10:                                               ; preds = %3
  %11 = call i32 @encdec_decode(ptr noundef nonnull %4) #4
  %.not6 = icmp eq i32 %11, 0
  br i1 %.not6, label %12, label %15

12:                                               ; preds = %10
  %13 = load ptr, ptr @stderr, align 8, !tbaa !13
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.5) #5
  br label %30

15:                                               ; preds = %10
  %16 = call i32 @encdec_check_equality(ptr noundef nonnull %4) #4
  %.not7 = icmp eq i32 %16, 0
  br i1 %.not7, label %17, label %20

17:                                               ; preds = %15
  %18 = load ptr, ptr @stderr, align 8, !tbaa !13
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.6) #5
  br label %30

20:                                               ; preds = %15
  %21 = shl nuw nsw i64 %5, 2
  %22 = load <2 x i64>, ptr %2, align 8, !tbaa !14
  %23 = insertelement <2 x i64> <i64 1, i64 poison>, i64 %21, i64 1
  %24 = add <2 x i64> %22, %23
  store <2 x i64> %24, ptr %2, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %4, i64 40
  %26 = load i64, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %2, i64 16
  %28 = load i64, ptr %27, align 8, !tbaa !16
  %29 = add i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !16
  br label %30

30:                                               ; preds = %20, %17, %12, %7
  %.0 = phi i32 [ 1, %20 ], [ 0, %17 ], [ 0, %12 ], [ 0, %7 ]
  call void @encdec_free(ptr noundef nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %4) #4
  ret i32 %.0
}

declare void @encdec_init32(ptr noundef) local_unnamed_addr #2

declare i32 @encdec_encode(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

declare void @encdec_free(ptr noundef) local_unnamed_addr #2

declare i32 @encdec_decode(ptr noundef) local_unnamed_addr #2

declare i32 @encdec_check_equality(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { nounwind }
attributes #5 = { cold 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, !7, i64 0}
!6 = !{!"EncDec", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !12, i64 64}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"EncDecCtx", !12, i64 0, !10, i64 8, !12, i64 16, !10, i64 24, !12, i64 32, !10, i64 40}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !10, i64 40}
!16 = !{!17, !10, i64 16}
!17 = !{!"Stats", !10, i64 0, !10, i64 8, !10, i64 16}


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