; LLVM IR from aws/s2n-tls :: utils (s2n_array)

; 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_array = type { %struct.s2n_blob, i32, i32 }
%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.8 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [88 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_array_validate(ptr noundef) #0

; 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: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_array_get(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca %struct.s2n_result, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %struct.s2n_result, align 4
  %9 = alloca %struct.s2n_result, 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
  br label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i32 @s2n_array_validate(ptr noundef %11)
  %13 = getelementptr inbounds %struct.s2n_result, ptr %9, i32 0, i32 0
  store i32 %12, ptr %13, align 4
  %14 = getelementptr inbounds %struct.s2n_result, ptr %9, i32 0, i32 0
  %15 = load i32, ptr %14, align 4
  %16 = call zeroext i1 @s2n_result_is_ok(i32 %15)
  %17 = xor i1 %16, true
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = call i64 @llvm.expect.i64(i64 %20, i64 1)
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %10
  %24 = getelementptr inbounds %struct.s2n_result, ptr %8, i32 0, i32 0
  store i32 0, ptr %24, align 4, !tbaa !11
  br label %27

25:                                               ; preds = %10
  %26 = getelementptr inbounds %struct.s2n_result, ptr %8, i32 0, i32 0
  store i32 -1, ptr %26, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %25, %23
  %28 = getelementptr inbounds %struct.s2n_result, ptr %8, i32 0, i32 0
  %29 = load i32, ptr %28, align 4
  %30 = call zeroext i1 @s2n_result_is_ok(i32 %29)
  br i1 %30, label %33, label %31

31:                                               ; preds = %27
  %32 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %32, align 4, !tbaa !11
  br label %125

33:                                               ; preds = %27
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %70, label %38

38:                                               ; preds = %35
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %42 = getelementptr inbounds %struct.s2n_debug_info, ptr %41, i32 0, i32 0
  store ptr @.str.8, ptr %42, align 8, !tbaa !13
  %43 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %44 = getelementptr inbounds %struct.s2n_debug_info, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = getelementptr inbounds i8, ptr %45, i64 21
  %47 = call ptr @strrchr(ptr noundef %46, i32 noundef 47) #6
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %56

49:                                               ; preds = %40
  %50 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %51 = getelementptr inbounds %struct.s2n_debug_info, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  %53 = getelementptr inbounds i8, ptr %52, i64 21
  %54 = call ptr @strrchr(ptr noundef %53, i32 noundef 47) #6
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  br label %61

56:                                               ; preds = %40
  %57 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %58 = getelementptr inbounds %struct.s2n_debug_info, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = getelementptr inbounds i8, ptr %59, i64 21
  br label %61

61:                                               ; preds = %56, %49
  %62 = phi ptr [ %55, %49 ], [ %60, %56 ]
  %63 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %64 = getelementptr inbounds %struct.s2n_debug_info, ptr %63, i32 0, i32 1
  store ptr %62, ptr %64, align 8, !tbaa !15
  %65 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %65, align 4, !tbaa !9
  %66 = call i32 @s2n_calculate_stacktrace()
  br label %67

67:                                               ; preds = %61
  %68 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %68, align 4, !tbaa !11
  br label %125

69:                                               ; No predecessors!
  br label %70

70:                                               ; preds = %69, %35
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.s2n_array, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 8, !tbaa !16
  %77 = icmp ult i32 %73, %76
  br i1 %77, label %110, label %78

78:                                               ; preds = %72
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  %81 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %82 = getelementptr inbounds %struct.s2n_debug_info, ptr %81, i32 0, i32 0
  store ptr @.str.9, ptr %82, align 8, !tbaa !13
  %83 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %84 = getelementptr inbounds %struct.s2n_debug_info, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !13
  %86 = getelementptr inbounds i8, ptr %85, i64 21
  %87 = call ptr @strrchr(ptr noundef %86, i32 noundef 47) #6
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %96

89:                                               ; preds = %80
  %90 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %91 = getelementptr inbounds %struct.s2n_debug_info, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !13
  %93 = getelementptr inbounds i8, ptr %92, i64 21
  %94 = call ptr @strrchr(ptr noundef %93, i32 noundef 47) #6
  %95 = getelementptr inbounds i8, ptr %94, i64 1
  br label %101

96:                                               ; preds = %80
  %97 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %98 = getelementptr inbounds %struct.s2n_debug_info, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !13
  %100 = getelementptr inbounds i8, ptr %99, i64 21
  br label %101

101:                                              ; preds = %96, %89
  %102 = phi ptr [ %95, %89 ], [ %100, %96 ]
  %103 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %104 = getelementptr inbounds %struct.s2n_debug_info, ptr %103, i32 0, i32 1
  store ptr %102, ptr %104, align 8, !tbaa !15
  %105 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653252, ptr %105, align 4, !tbaa !9
  %106 = call i32 @s2n_calculate_stacktrace()
  br label %107

107:                                              ; preds = %101
  %108 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %108, align 4, !tbaa !11
  br label %125

109:                                              ; No predecessors!
  br label %110

110:                                              ; preds = %109, %72
  br label %111

111:                                              ; preds = %110
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.s2n_array, ptr %112, i32 0, i32 0
  %114 = getelementptr inbounds %struct.s2n_blob, ptr %113, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !19
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.s2n_array, ptr %116, i32 0, i32 2
  %118 = load i32, ptr %117, align 4, !tbaa !20
  %119 = load i32, ptr %6, align 4, !tbaa !9
  %120 = mul i32 %118, %119
  %121 = zext i32 %120 to i64
  %122 = getelementptr inbounds i8, ptr %115, i64 %121
  %123 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %122, ptr %123, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 0, ptr %124, align 4, !tbaa !11
  br label %125

125:                                              ; preds = %111, %107, %67, %31
  %126 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  %127 = load i32, ptr %126, align 4
  ret i32 %127
}

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 = { inlinehint 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !10, i64 24}
!17 = !{!"s2n_array", !18, i64 0, !10, i64 24, !10, i64 28}
!18 = !{!"s2n_blob", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!19 = !{!17, !6, i64 0}
!20 = !{!17, !10, i64 28}


; 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.8 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [88 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_array_validate(ptr noundef) local_unnamed_addr #0

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_array_get(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = tail call i32 @s2n_array_validate(ptr noundef %0)
  %5 = tail call zeroext i1 @s2n_result_is_ok(i32 %4)
  %not. = xor i1 %5, true
  %. = sext i1 %not. to i32
  %6 = tail call zeroext i1 @s2n_result_is_ok(i32 %.)
  br i1 %6, label %7, label %35

7:                                                ; preds = %3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %8, label %16

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

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp ugt i32 %18, %1
  br i1 %19, label %28, label %20

20:                                               ; preds = %16
  %21 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.9, ptr %21, align 8, !tbaa !5
  %22 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.9, i64 21), i32 noundef 47) #5
  %.not13 = icmp eq ptr %22, null
  %23 = getelementptr inbounds i8, ptr %22, i64 1
  %24 = select i1 %.not13, ptr getelementptr inbounds (i8, ptr @.str.9, i64 21), ptr %23
  %25 = getelementptr inbounds i8, ptr %21, i64 8
  store ptr %24, ptr %25, align 8, !tbaa !10
  %26 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653252, ptr %26, align 4, !tbaa !11
  %27 = tail call i32 @s2n_calculate_stacktrace() #6
  br label %35

28:                                               ; preds = %16
  %29 = load ptr, ptr %0, align 8, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %0, i64 28
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = mul i32 %31, %1
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %29, i64 %33
  store ptr %34, ptr %2, align 8, !tbaa !18
  br label %35

35:                                               ; preds = %3, %28, %20, %8
  %.sroa.08.0 = phi i32 [ 0, %28 ], [ -1, %20 ], [ -1, %8 ], [ -1, %3 ]
  ret i32 %.sroa.08.0
}

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 = { inlinehint 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, !7, i64 0}
!6 = !{!"s2n_debug_info", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"s2n_array", !15, i64 0, !12, i64 24, !12, i64 28}
!15 = !{!"s2n_blob", !7, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!16 = !{!14, !7, i64 0}
!17 = !{!14, !12, i64 28}
!18 = !{!7, !7, i64 0}


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