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

; 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_ktls_io_stuffer = type { %struct.s2n_stuffer, %struct.s2n_stuffer, i64, i64 }
%struct.s2n_stuffer = type { %struct.s2n_blob, i32, i32, i32, i8 }
%struct.s2n_blob = type { ptr, i32, i32, i8 }

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

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

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

declare i32 @s2n_calculate_stacktrace() #2

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

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

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

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %45, label %13

13:                                               ; preds = %10
  br label %14

14:                                               ; preds = %13
  br label %15

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

24:                                               ; preds = %15
  %25 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %26 = getelementptr inbounds %struct.s2n_debug_info, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %27, i64 21
  %29 = call ptr @strrchr(ptr noundef %28, i32 noundef 47) #5
  %30 = getelementptr inbounds i8, ptr %29, i64 1
  br label %36

31:                                               ; preds = %15
  %32 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %33 = getelementptr inbounds %struct.s2n_debug_info, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %34, i64 21
  br label %36

36:                                               ; preds = %31, %24
  %37 = phi ptr [ %30, %24 ], [ %35, %31 ]
  %38 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %39 = getelementptr inbounds %struct.s2n_debug_info, ptr %38, i32 0, i32 1
  store ptr %37, ptr %39, align 8, !tbaa !13
  %40 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %40, align 4, !tbaa !14
  %41 = call i32 @s2n_calculate_stacktrace()
  br label %42

42:                                               ; preds = %36
  %43 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %43, align 4, !tbaa !16
  br label %145

44:                                               ; No predecessors!
  br label %45

45:                                               ; preds = %44, %10
  br label %46

46:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.s2n_test_ktls_io_stuffer, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds %struct.s2n_stuffer, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !18
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s2n_test_ktls_io_stuffer, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.s2n_stuffer, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !23
  %55 = sub i32 %50, %54
  %56 = zext i32 %55 to i64
  store i64 %56, ptr %6, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %57 = load i64, ptr %6, align 8, !tbaa !24
  %58 = udiv i64 %57, 3
  store i64 %58, ptr %7, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %59 = load i64, ptr %6, align 8, !tbaa !24
  %60 = urem i64 %59, 3
  store i64 %60, ptr %8, align 8, !tbaa !24
  br label %61

61:                                               ; preds = %46
  %62 = load i64, ptr %7, align 8, !tbaa !24
  %63 = load i16, ptr %5, align 2, !tbaa !9
  %64 = zext i16 %63 to i64
  %65 = icmp eq i64 %62, %64
  br i1 %65, label %100, label %66

66:                                               ; preds = %61
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %70 = getelementptr inbounds %struct.s2n_debug_info, ptr %69, i32 0, i32 0
  store ptr @.str.25, ptr %70, align 8, !tbaa !11
  %71 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %72 = getelementptr inbounds %struct.s2n_debug_info, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !11
  %74 = getelementptr inbounds i8, ptr %73, i64 21
  %75 = call ptr @strrchr(ptr noundef %74, i32 noundef 47) #5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %84

77:                                               ; preds = %68
  %78 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %79 = getelementptr inbounds %struct.s2n_debug_info, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = getelementptr inbounds i8, ptr %80, i64 21
  %82 = call ptr @strrchr(ptr noundef %81, i32 noundef 47) #5
  %83 = getelementptr inbounds i8, ptr %82, i64 1
  br label %89

84:                                               ; preds = %68
  %85 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %86 = getelementptr inbounds %struct.s2n_debug_info, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !11
  %88 = getelementptr inbounds i8, ptr %87, i64 21
  br label %89

89:                                               ; preds = %84, %77
  %90 = phi ptr [ %83, %77 ], [ %88, %84 ]
  %91 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %92 = getelementptr inbounds %struct.s2n_debug_info, ptr %91, i32 0, i32 1
  store ptr %90, ptr %92, align 8, !tbaa !13
  %93 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653194, ptr %93, align 4, !tbaa !14
  %94 = call i32 @s2n_calculate_stacktrace()
  br label %95

95:                                               ; preds = %89
  br label %96

96:                                               ; preds = %95
  %97 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %97, align 4, !tbaa !16
  store i32 1, ptr %9, align 4
  br label %144

98:                                               ; No predecessors!
  br label %99

99:                                               ; preds = %98
  br label %100

100:                                              ; preds = %99, %61
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101
  br label %103

103:                                              ; preds = %102
  %104 = load i64, ptr %8, align 8, !tbaa !24
  %105 = icmp eq i64 %104, 0
  br i1 %105, label %140, label %106

106:                                              ; preds = %103
  br label %107

107:                                              ; preds = %106
  br label %108

108:                                              ; preds = %107
  %109 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %110 = getelementptr inbounds %struct.s2n_debug_info, ptr %109, i32 0, i32 0
  store ptr @.str.26, ptr %110, align 8, !tbaa !11
  %111 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %112 = getelementptr inbounds %struct.s2n_debug_info, ptr %111, i32 0, i32 0
  %113 = load ptr, ptr %112, align 8, !tbaa !11
  %114 = getelementptr inbounds i8, ptr %113, i64 21
  %115 = call ptr @strrchr(ptr noundef %114, i32 noundef 47) #5
  %116 = icmp ne ptr %115, null
  br i1 %116, label %117, label %124

117:                                              ; preds = %108
  %118 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %119 = getelementptr inbounds %struct.s2n_debug_info, ptr %118, i32 0, i32 0
  %120 = load ptr, ptr %119, align 8, !tbaa !11
  %121 = getelementptr inbounds i8, ptr %120, i64 21
  %122 = call ptr @strrchr(ptr noundef %121, i32 noundef 47) #5
  %123 = getelementptr inbounds i8, ptr %122, i64 1
  br label %129

124:                                              ; preds = %108
  %125 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %126 = getelementptr inbounds %struct.s2n_debug_info, ptr %125, i32 0, i32 0
  %127 = load ptr, ptr %126, align 8, !tbaa !11
  %128 = getelementptr inbounds i8, ptr %127, i64 21
  br label %129

129:                                              ; preds = %124, %117
  %130 = phi ptr [ %123, %117 ], [ %128, %124 ]
  %131 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %132 = getelementptr inbounds %struct.s2n_debug_info, ptr %131, i32 0, i32 1
  store ptr %130, ptr %132, align 8, !tbaa !13
  %133 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653194, ptr %133, align 4, !tbaa !14
  %134 = call i32 @s2n_calculate_stacktrace()
  br label %135

135:                                              ; preds = %129
  br label %136

136:                                              ; preds = %135
  %137 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %137, align 4, !tbaa !16
  store i32 1, ptr %9, align 4
  br label %144

138:                                              ; No predecessors!
  br label %139

139:                                              ; preds = %138
  br label %140

140:                                              ; preds = %139, %103
  br label %141

141:                                              ; preds = %140
  br label %142

142:                                              ; preds = %141
  %143 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 0, ptr %143, align 4, !tbaa !16
  store i32 1, ptr %9, align 4
  br label %144

144:                                              ; preds = %142, %136, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %145

145:                                              ; preds = %144, %42
  %146 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  %147 = load i32, ptr %146, align 4
  ret i32 %147
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"", !15, i64 0}
!18 = !{!19, !15, i64 28}
!19 = !{!"s2n_test_ktls_io_stuffer", !20, i64 0, !20, i64 40, !22, i64 80, !22, i64 88}
!20 = !{!"s2n_stuffer", !21, i64 0, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !15, i64 36, !15, i64 36}
!21 = !{!"s2n_blob", !6, i64 0, !15, i64 8, !15, i64 12, !15, i64 16}
!22 = !{!"long", !7, i64 0}
!23 = !{!19, !15, i64 24}
!24 = !{!22, !22, 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"

%struct.s2n_debug_info = type { ptr, ptr }

@_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
@.str.24 = external hidden unnamed_addr constant [106 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [106 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [106 x i8], align 1

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

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

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_test_records_in_ancillary(ptr noundef readonly %0, i16 noundef zeroext %1) local_unnamed_addr #3 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.sink.split, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !14
  %8 = sub i32 %5, %7
  %9 = udiv i32 %8, 3
  %10 = urem i32 %8, 3
  %11 = zext i16 %1 to i32
  %12 = icmp eq i32 %9, %11
  br i1 %12, label %13, label %.sink.split

13:                                               ; preds = %3
  %14 = icmp eq i32 %10, 0
  br i1 %14, label %22, label %.sink.split

.sink.split:                                      ; preds = %13, %3, %2
  %.str.25.sink = phi ptr [ @.str.24, %2 ], [ @.str.25, %3 ], [ @.str.26, %13 ]
  %.sink23 = phi ptr [ getelementptr inbounds (i8, ptr @.str.24, i64 21), %2 ], [ getelementptr inbounds (i8, ptr @.str.25, i64 21), %3 ], [ getelementptr inbounds (i8, ptr @.str.26, i64 21), %13 ]
  %.sink = phi i32 [ 402653193, %2 ], [ 402653194, %3 ], [ 402653194, %13 ]
  %15 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr %.str.25.sink, ptr %15, align 8, !tbaa !15
  %16 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) %.sink23, i32 noundef 47) #4
  %.not11 = icmp eq ptr %16, null
  %17 = getelementptr inbounds i8, ptr %16, i64 1
  %18 = select i1 %.not11, ptr %.sink23, ptr %17
  %19 = getelementptr inbounds i8, ptr %15, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !17
  %20 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 %.sink, ptr %20, align 4, !tbaa !18
  %21 = tail call i32 @s2n_calculate_stacktrace() #5
  br label %22

22:                                               ; preds = %.sink.split, %13
  %.sroa.0.1 = phi i32 [ 0, %13 ], [ -1, %.sink.split ]
  ret i32 %.sroa.0.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #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 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 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, !12, i64 28}
!6 = !{!"s2n_test_ktls_io_stuffer", !7, i64 0, !7, i64 40, !13, i64 80, !13, i64 88}
!7 = !{!"s2n_stuffer", !8, i64 0, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 36, !12, i64 36}
!8 = !{!"s2n_blob", !9, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"long", !10, i64 0}
!14 = !{!6, !12, i64 24}
!15 = !{!16, !9, i64 0}
!16 = !{!"s2n_debug_info", !9, i64 0, !9, i64 8}
!17 = !{!16, !9, i64 8}
!18 = !{!12, !12, i64 0}


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