; 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.1 = 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: nounwind uwtable
define dso_local i32 @s2n_mem_test_assert_malloc(i32 noundef %0) #2 {
  %2 = alloca %struct.s2n_result, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.s2n_result, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.s2n_mem_test_malloc, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.s2n_result, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %10

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

16:                                               ; preds = %10
  %17 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %17, align 4, !tbaa !9
  store i32 1, ptr %6, align 4
  br label %88

18:                                               ; preds = %10
  br label %19

19:                                               ; preds = %18
  br label %20

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

21:                                               ; preds = %48, %20
  %22 = load i64, ptr %8, align 8, !tbaa !11
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 4, ptr %6, align 4
  br label %51

27:                                               ; preds = %21
  br label %28

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

36:                                               ; preds = %28
  %37 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %37, align 4, !tbaa !9
  store i32 1, ptr %6, align 4
  br label %51

38:                                               ; preds = %28
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = getelementptr inbounds %struct.s2n_mem_test_malloc, ptr %7, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = icmp eq i32 %42, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %40
  %46 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 0, ptr %46, align 4, !tbaa !9
  store i32 1, ptr %6, align 4
  br label %51

47:                                               ; preds = %40
  br label %48

48:                                               ; preds = %47
  %49 = load i64, ptr %8, align 8, !tbaa !11
  %50 = add i64 %49, 1
  store i64 %50, ptr %8, align 8, !tbaa !11
  br label %21, !llvm.loop !17

51:                                               ; preds = %45, %36, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  %52 = load i32, ptr %6, align 4
  switch i32 %52, label %87 [
    i32 4, label %53
  ]

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %57 = getelementptr inbounds %struct.s2n_debug_info, ptr %56, i32 0, i32 0
  store ptr @.str.1, ptr %57, align 8, !tbaa !19
  %58 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %59 = getelementptr inbounds %struct.s2n_debug_info, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = getelementptr inbounds i8, ptr %60, i64 21
  %62 = call ptr @strrchr(ptr noundef %61, i32 noundef 47) #8
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %71

64:                                               ; preds = %55
  %65 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %66 = getelementptr inbounds %struct.s2n_debug_info, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = getelementptr inbounds i8, ptr %67, i64 21
  %69 = call ptr @strrchr(ptr noundef %68, i32 noundef 47) #8
  %70 = getelementptr inbounds i8, ptr %69, i64 1
  br label %76

71:                                               ; preds = %55
  %72 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %73 = getelementptr inbounds %struct.s2n_debug_info, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  %75 = getelementptr inbounds i8, ptr %74, i64 21
  br label %76

76:                                               ; preds = %71, %64
  %77 = phi ptr [ %70, %64 ], [ %75, %71 ]
  %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 1
  store ptr %77, ptr %79, align 8, !tbaa !21
  %80 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653271, ptr %80, align 4, !tbaa !5
  %81 = call i32 @s2n_calculate_stacktrace()
  br label %82

82:                                               ; preds = %76
  br label %83

83:                                               ; preds = %82
  %84 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %84, align 4, !tbaa !9
  store i32 1, ptr %6, align 4
  br label %87

85:                                               ; No predecessors!
  br label %86

86:                                               ; preds = %85
  store i32 0, ptr %6, align 4
  br label %87

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

88:                                               ; preds = %87, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  %89 = load i32, ptr %6, align 4
  switch i32 %89, label %93 [
    i32 0, label %90
    i32 1, label %90
  ]

90:                                               ; preds = %88, %88
  %91 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  %92 = load i32, ptr %91, align 4
  ret i32 %92

93:                                               ; preds = %88
  unreachable
}

; 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

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, !6, i64 8}
!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 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !15, i64 0}
!20 = !{!"s2n_debug_info", !15, i64 0, !15, i64 8}
!21 = !{!20, !15, i64 8}


; 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.1 = 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: nounwind uwtable
define dso_local noundef i32 @s2n_mem_test_assert_malloc(i32 noundef %0) local_unnamed_addr #2 {
  %2 = alloca i32, align 4
  %3 = alloca %struct.s2n_mem_test_malloc, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  %4 = call i32 @s2n_mem_test_get_malloc_count(ptr noundef nonnull %2)
  %5 = call zeroext i1 @s2n_result_is_ok(i32 %4)
  br i1 %5, label %6, label %27

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

.lr.ph:                                           ; preds = %6
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  br label %13

9:                                                ; preds = %17
  %10 = add nuw nsw i64 %.012, 1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = zext i32 %11 to i64
  %.not = icmp ult i64 %10, %12
  br i1 %.not, label %13, label %._crit_edge, !llvm.loop !9

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

17:                                               ; preds = %13
  %18 = load i32, ptr %8, align 8, !tbaa !11
  %19 = icmp eq i32 %18, %0
  br i1 %19, label %.thread, label %9

._crit_edge:                                      ; preds = %9, %6
  %20 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.1, ptr %20, align 8, !tbaa !15
  %21 = call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.1, i64 21), i32 noundef 47) #8
  %.not9 = icmp eq ptr %21, null
  %22 = getelementptr inbounds i8, ptr %21, i64 1
  %23 = select i1 %.not9, ptr getelementptr inbounds (i8, ptr @.str.1, i64 21), ptr %22
  %24 = getelementptr inbounds i8, ptr %20, i64 8
  store ptr %23, ptr %24, align 8, !tbaa !17
  %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 %.thread

.thread:                                          ; preds = %13, %17, %._crit_edge
  %.sroa.06.1 = phi i32 [ -1, %._crit_edge ], [ -1, %13 ], [ 0, %17 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #7
  br label %27

27:                                               ; preds = %1, %.thread
  %.sroa.06.2 = phi i32 [ %.sroa.06.1, %.thread ], [ -1, %1 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  ret i32 %.sroa.06.2
}

; 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

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, !6, i64 8}
!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 = !{!16, !13, i64 0}
!16 = !{!"s2n_debug_info", !13, i64 0, !13, i64 8}
!17 = !{!16, !13, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass