; LLVM IR from aws/s2n-tls :: tests/testlib (s2n_io_testlib)

; 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.s2n_debug_info = type { ptr, ptr }
%struct.s2n_result = type { i32 }
%struct.s2n_test_iovecs = type { ptr, i64 }
%struct.iovec = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [100 x i8], align 1
@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_test_iovecs_free(ptr noundef %0) #0 {
  %2 = alloca %struct.s2n_result, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %41, label %9

9:                                                ; preds = %6
  br label %10

10:                                               ; preds = %9
  br label %11

11:                                               ; preds = %10
  %12 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %13 = getelementptr inbounds %struct.s2n_debug_info, ptr %12, i32 0, i32 0
  store ptr @.str, ptr %13, align 8, !tbaa !9
  %14 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %15 = getelementptr inbounds %struct.s2n_debug_info, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %16, i64 21
  %18 = call ptr @strrchr(ptr noundef %17, i32 noundef 47) #5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %27

20:                                               ; preds = %11
  %21 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %22 = getelementptr inbounds %struct.s2n_debug_info, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %23, i64 21
  %25 = call ptr @strrchr(ptr noundef %24, i32 noundef 47) #5
  %26 = getelementptr inbounds i8, ptr %25, i64 1
  br label %32

27:                                               ; preds = %11
  %28 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %29 = getelementptr inbounds %struct.s2n_debug_info, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %30, i64 21
  br label %32

32:                                               ; preds = %27, %20
  %33 = phi ptr [ %26, %20 ], [ %31, %27 ]
  %34 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %35 = getelementptr inbounds %struct.s2n_debug_info, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !11
  %36 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %36, align 4, !tbaa !12
  %37 = call i32 @s2n_calculate_stacktrace()
  br label %38

38:                                               ; preds = %32
  %39 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %39, align 4, !tbaa !14
  br label %94

40:                                               ; No predecessors!
  br label %41

41:                                               ; preds = %40, %6
  br label %42

42:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store i64 0, ptr %4, align 8, !tbaa !16
  br label %43

43:                                               ; preds = %73, %42
  %44 = load i64, ptr %4, align 8, !tbaa !16
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s2n_test_iovecs, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !18
  %48 = icmp ult i64 %44, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %43
  store i32 8, ptr %5, align 4
  br label %76

50:                                               ; preds = %43
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.s2n_test_iovecs, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !20
  %55 = load i64, ptr %4, align 8, !tbaa !16
  %56 = getelementptr inbounds %struct.iovec, ptr %54, i64 %55
  %57 = getelementptr inbounds %struct.iovec, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.s2n_test_iovecs, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !20
  %61 = load i64, ptr %4, align 8, !tbaa !16
  %62 = getelementptr inbounds %struct.iovec, ptr %60, i64 %61
  %63 = getelementptr inbounds %struct.iovec, ptr %62, i32 0, i32 1
  %64 = load i64, ptr %63, align 8, !tbaa !21
  %65 = trunc i64 %64 to i32
  %66 = call i32 @s2n_free_object(ptr noundef %57, i32 noundef %65)
  %67 = icmp sgt i32 %66, -1
  br i1 %67, label %70, label %68

68:                                               ; preds = %51
  %69 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %69, align 4, !tbaa !14
  store i32 1, ptr %5, align 4
  br label %76

70:                                               ; preds = %51
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = load i64, ptr %4, align 8, !tbaa !16
  %75 = add i64 %74, 1
  store i64 %75, ptr %4, align 8, !tbaa !16
  br label %43, !llvm.loop !23

76:                                               ; preds = %68, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %77 = load i32, ptr %5, align 4
  switch i32 %77, label %97 [
    i32 8, label %78
    i32 1, label %94
  ]

78:                                               ; preds = %76
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.s2n_test_iovecs, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.s2n_test_iovecs, ptr %82, i32 0, i32 1
  %84 = load i64, ptr %83, align 8, !tbaa !18
  %85 = mul i64 16, %84
  %86 = trunc i64 %85 to i32
  %87 = call i32 @s2n_free_object(ptr noundef %81, i32 noundef %86)
  %88 = icmp sgt i32 %87, -1
  br i1 %88, label %91, label %89

89:                                               ; preds = %79
  %90 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %90, align 4, !tbaa !14
  br label %94

91:                                               ; preds = %79
  br label %92

92:                                               ; preds = %91
  %93 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 0, ptr %93, align 4, !tbaa !14
  br label %94

94:                                               ; preds = %92, %89, %76, %38
  %95 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  %96 = load i32, ptr %95, align 4
  ret i32 %96

97:                                               ; preds = %76
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #2

declare i32 @s2n_calculate_stacktrace() #3

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

declare i32 @s2n_free_object(ptr noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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, !6, i64 0}
!10 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"", !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !17, i64 8}
!19 = !{!"s2n_test_iovecs", !6, i64 0, !17, i64 8}
!20 = !{!19, !6, i64 0}
!21 = !{!22, !17, i64 8}
!22 = !{!"iovec", !6, i64 0, !17, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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.s2n_debug_info = type { ptr, ptr }
%struct.iovec = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [100 x i8], align 1
@_s2n_debug_info = external thread_local local_unnamed_addr global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_test_iovecs_free(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %.preheader

.preheader:                                       ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not19 = icmp eq i64 %3, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

4:                                                ; preds = %1
  %5 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str, ptr %5, align 8, !tbaa !11
  %6 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str, i64 21), i32 noundef 47) #4
  %.not13 = icmp eq ptr %6, null
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  %8 = select i1 %.not13, ptr getelementptr inbounds (i8, ptr @.str, i64 21), ptr %7
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !13
  %10 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %10, align 4, !tbaa !14
  %11 = tail call i32 @s2n_calculate_stacktrace() #5
  br label %.loopexit

12:                                               ; preds = %.lr.ph
  %13 = add nuw i64 %.01018, 1
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %12
  %.01018 = phi i64 [ %13, %12 ], [ 0, %.preheader ]
  %16 = load ptr, ptr %0, align 8, !tbaa !18
  %17 = getelementptr inbounds %struct.iovec, ptr %16, i64 %.01018
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !19
  %20 = trunc i64 %19 to i32
  %21 = tail call i32 @s2n_free_object(ptr noundef %17, i32 noundef %20) #5
  %22 = icmp sgt i32 %21, -1
  br i1 %22, label %12, label %.loopexit

._crit_edge.loopexit:                             ; preds = %12
  %23 = trunc i64 %14 to i32
  %24 = shl i32 %23, 4
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.tr = phi i32 [ %24, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %25 = tail call i32 @s2n_free_object(ptr noundef nonnull %0, i32 noundef %.tr) #5
  %.lobit = ashr i32 %25, 31
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %4
  %.sroa.0.1 = phi i32 [ -1, %4 ], [ %.lobit, %._crit_edge ], [ -1, %.lr.ph ]
  ret i32 %.sroa.0.1
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strrchr(ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #3

declare i32 @s2n_free_object(ptr noundef, i32 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #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 = { nounwind willreturn memory(read) }
attributes #5 = { 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, !10, i64 8}
!6 = !{!"s2n_test_iovecs", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"s2n_debug_info", !7, i64 0, !7, i64 8}
!13 = !{!12, !7, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 0}
!19 = !{!20, !10, i64 8}
!20 = !{!"iovec", !7, i64 0, !10, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass