; LLVM IR from aws/s2n-tls :: tests/testlib (s2n_mem_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_mem_test_malloc = 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.2 = external hidden unnamed_addr constant [102 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_mem_test_get_malloc_count(ptr noundef) #2

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

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

declare i32 @s2n_calculate_stacktrace() #5

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_mem_test_get_malloc(i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_mem_test_assert_all_freed() #2 {
  %1 = alloca %struct.s2n_result, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct.s2n_result, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.s2n_mem_test_malloc, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.s2n_result, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %0
  %9 = call i32 @s2n_mem_test_get_malloc_count(ptr noundef %2)
  %10 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 %9, ptr %10, align 4
  %11 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  %12 = load i32, ptr %11, align 4
  %13 = call zeroext i1 @s2n_result_is_ok(i32 %12)
  br i1 %13, label %16, label %14

14:                                               ; preds = %8
  %15 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  store i32 -1, ptr %15, align 4, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %88

16:                                               ; preds = %8
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #7
  call void @llvm.memset.p0.i64(ptr align 8 %5, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %80, %18
  %20 = load i64, ptr %6, align 8, !tbaa !11
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = icmp ult i64 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 4, ptr %4, align 4
  br label %83

25:                                               ; preds = %19
  br label %26

26:                                               ; preds = %25
  %27 = load i64, ptr %6, align 8, !tbaa !11
  %28 = trunc i64 %27 to i32
  %29 = call i32 @s2n_mem_test_get_malloc(i32 noundef %28, ptr noundef %5)
  %30 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 %29, ptr %30, align 4
  %31 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  %32 = load i32, ptr %31, align 4
  %33 = call zeroext i1 @s2n_result_is_ok(i32 %32)
  br i1 %33, label %36, label %34

34:                                               ; preds = %26
  %35 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  store i32 -1, ptr %35, align 4, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %83

36:                                               ; preds = %26
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  %40 = getelementptr inbounds %struct.s2n_mem_test_malloc, ptr %5, i32 0, i32 3
  %41 = load i8, ptr %40, align 8, !tbaa !13, !range !17, !noundef !18
  %42 = trunc i8 %41 to i1
  br i1 %42, label %77, label %43

43:                                               ; preds = %39
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %47 = getelementptr inbounds %struct.s2n_debug_info, ptr %46, i32 0, i32 0
  store ptr @.str.2, ptr %47, align 8, !tbaa !19
  %48 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %49 = getelementptr inbounds %struct.s2n_debug_info, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = getelementptr inbounds i8, ptr %50, i64 21
  %52 = call ptr @strrchr(ptr noundef %51, i32 noundef 47) #8
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %61

54:                                               ; preds = %45
  %55 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %56 = getelementptr inbounds %struct.s2n_debug_info, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !19
  %58 = getelementptr inbounds i8, ptr %57, i64 21
  %59 = call ptr @strrchr(ptr noundef %58, i32 noundef 47) #8
  %60 = getelementptr inbounds i8, ptr %59, i64 1
  br label %66

61:                                               ; preds = %45
  %62 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %63 = getelementptr inbounds %struct.s2n_debug_info, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !19
  %65 = getelementptr inbounds i8, ptr %64, i64 21
  br label %66

66:                                               ; preds = %61, %54
  %67 = phi ptr [ %60, %54 ], [ %65, %61 ]
  %68 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %69 = getelementptr inbounds %struct.s2n_debug_info, ptr %68, i32 0, i32 1
  store ptr %67, ptr %69, align 8, !tbaa !21
  %70 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653271, ptr %70, align 4, !tbaa !5
  %71 = call i32 @s2n_calculate_stacktrace()
  br label %72

72:                                               ; preds = %66
  br label %73

73:                                               ; preds = %72
  %74 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  store i32 -1, ptr %74, align 4, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %83

75:                                               ; No predecessors!
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76, %39
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %6, align 8, !tbaa !11
  %82 = add i64 %81, 1
  store i64 %82, ptr %6, align 8, !tbaa !11
  br label %19, !llvm.loop !22

83:                                               ; preds = %73, %34, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %84 = load i32, ptr %4, align 4
  switch i32 %84, label %87 [
    i32 4, label %85
  ]

85:                                               ; preds = %83
  %86 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  store i32 0, ptr %86, align 4, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %87

87:                                               ; preds = %85, %83
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #7
  br label %88

88:                                               ; preds = %87, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  %89 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  %90 = load i32, ptr %89, align 4
  ret i32 %90
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { "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 #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !16, i64 16}
!14 = !{!"s2n_mem_test_malloc", !15, i64 0, !6, i64 8, !6, i64 12, !16, i64 16}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!20, !15, i64 0}
!20 = !{!"s2n_debug_info", !15, i64 0, !15, i64 8}
!21 = !{!20, !15, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"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.s2n_mem_test_malloc = type { ptr, i32, i32, i8 }

@_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.2 = external hidden unnamed_addr constant [102 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_mem_test_get_malloc_count(ptr noundef) local_unnamed_addr #2

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

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

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #5

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_mem_test_get_malloc(i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_mem_test_assert_all_freed() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.s2n_mem_test_malloc, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  store i32 0, ptr %1, align 4, !tbaa !5
  %3 = call i32 @s2n_mem_test_get_malloc_count(ptr noundef nonnull %1)
  %4 = call zeroext i1 @s2n_result_is_ok(i32 %3)
  br i1 %4, label %5, label %28

5:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %2, i8 0, i64 24, i1 false)
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %.not811.not = icmp eq i32 %6, 0
  br i1 %.not811.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  br label %12

8:                                                ; preds = %16
  %9 = add nuw nsw i64 %.012, 1
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %.not8 = icmp ult i64 %9, %11
  br i1 %.not8, label %12, label %.loopexit.loopexit, !llvm.loop !9

12:                                               ; preds = %.lr.ph, %8
  %.012 = phi i64 [ 0, %.lr.ph ], [ %9, %8 ]
  %13 = trunc nuw i64 %.012 to i32
  %14 = call i32 @s2n_mem_test_get_malloc(i32 noundef %13, ptr noundef nonnull %2)
  %15 = call zeroext i1 @s2n_result_is_ok(i32 %14)
  br i1 %15, label %16, label %.loopexit.loopexit

16:                                               ; preds = %12
  %17 = load i8, ptr %7, align 8, !tbaa !11, !range !15, !noundef !16
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %8, label %19

19:                                               ; preds = %16
  %20 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.2, ptr %20, align 8, !tbaa !17
  %21 = call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.2, i64 21), i32 noundef 47) #8
  %.not = icmp eq ptr %21, null
  %22 = getelementptr inbounds i8, ptr %21, i64 1
  %23 = select i1 %.not, ptr getelementptr inbounds (i8, ptr @.str.2, i64 21), ptr %22
  %24 = getelementptr inbounds i8, ptr %20, i64 8
  store ptr %23, ptr %24, align 8, !tbaa !19
  %25 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653271, ptr %25, align 4, !tbaa !5
  %26 = call i32 @s2n_calculate_stacktrace() #7
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %12, %8
  %.not810.ph = xor i1 %15, true
  %27 = sext i1 %.not810.ph to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %5, %19
  %.not810 = phi i32 [ -1, %19 ], [ 0, %5 ], [ %27, %.loopexit.loopexit ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #7
  br label %28

28:                                               ; preds = %0, %.loopexit
  %.sroa.05.2 = phi i32 [ %.not810, %.loopexit ], [ -1, %0 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  ret i32 %.sroa.05.2
}

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


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