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

; 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_config = type { i32, ptr, ptr, %struct.certs_by_type, %struct.s2n_blob, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, i64, ptr, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, %struct.s2n_x509_trust_store, i16, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32, ptr, ptr, i32, %struct.s2n_blob }
%struct.certs_by_type = type { [4 x ptr] }
%struct.s2n_x509_trust_store = type { ptr, i8 }
%struct.s2n_blob = type { ptr, i32, i32, i8 }
%struct.s2n_timer = type { i64 }

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

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.s2n_config, ptr %11, i32 0, i32 6
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s2n_config, ptr %14, i32 0, i32 9
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = call i32 %13(ptr noundef %16, ptr noundef %8)
  %18 = icmp sge i32 %17, 0
  br i1 %18, label %53, label %19

19:                                               ; preds = %10
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %23 = getelementptr inbounds %struct.s2n_debug_info, ptr %22, i32 0, i32 0
  store ptr @.str.1, ptr %23, align 8, !tbaa !19
  %24 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %25 = getelementptr inbounds %struct.s2n_debug_info, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  %27 = getelementptr inbounds i8, ptr %26, i64 21
  %28 = call ptr @strrchr(ptr noundef %27, i32 noundef 47) #6
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %37

30:                                               ; preds = %21
  %31 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %32 = getelementptr inbounds %struct.s2n_debug_info, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds i8, ptr %33, i64 21
  %35 = call ptr @strrchr(ptr noundef %34, i32 noundef 47) #6
  %36 = getelementptr inbounds i8, ptr %35, i64 1
  br label %42

37:                                               ; preds = %21
  %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 0
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = getelementptr inbounds i8, ptr %40, i64 21
  br label %42

42:                                               ; preds = %37, %30
  %43 = phi ptr [ %36, %30 ], [ %41, %37 ]
  %44 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %45 = getelementptr inbounds %struct.s2n_debug_info, ptr %44, i32 0, i32 1
  store ptr %43, ptr %45, align 8, !tbaa !21
  %46 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 335544386, ptr %46, align 4, !tbaa !22
  %47 = call i32 @s2n_calculate_stacktrace()
  br label %48

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %48
  %50 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %50, align 4, !tbaa !23
  store i32 1, ptr %9, align 4
  br label %63

51:                                               ; No predecessors!
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %10
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = load i64, ptr %8, align 8, !tbaa !9
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.s2n_timer, ptr %57, i32 0, i32 0
  %59 = load i64, ptr %58, align 8, !tbaa !25
  %60 = sub i64 %56, %59
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %60, ptr %61, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 0, ptr %62, align 4, !tbaa !23
  store i32 1, ptr %9, align 4
  br label %63

63:                                               ; preds = %55, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %64 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  %65 = load i32, ptr %64, align 4
  ret i32 %65
}

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 88}
!12 = !{!"s2n_config", !13, i64 0, !13, i64 0, !13, i64 0, !13, i64 0, !13, i64 0, !13, i64 0, !13, i64 0, !13, i64 0, !13, i64 1, !13, i64 1, !13, i64 1, !13, i64 1, !13, i64 1, !13, i64 1, !13, i64 1, !13, i64 1, !13, i64 2, !13, i64 2, !13, i64 2, !13, i64 2, !6, i64 8, !6, i64 16, !14, i64 24, !15, i64 56, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !13, i64 128, !13, i64 132, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !10, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !13, i64 224, !7, i64 228, !13, i64 232, !13, i64 236, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !7, i64 296, !7, i64 297, !16, i64 304, !17, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !13, i64 392, !13, i64 396, !13, i64 400, !6, i64 408, !13, i64 416, !13, i64 420, !6, i64 424, !6, i64 432, !13, i64 440, !15, i64 448}
!13 = !{!"int", !7, i64 0}
!14 = !{!"certs_by_type", !7, i64 0}
!15 = !{!"s2n_blob", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16}
!16 = !{!"s2n_x509_trust_store", !6, i64 0, !13, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!12, !6, i64 112}
!19 = !{!20, !6, i64 0}
!20 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!21 = !{!20, !6, i64 8}
!22 = !{!13, !13, i64 0}
!23 = !{!24, !13, i64 0}
!24 = !{!"", !13, i64 0}
!25 = !{!26, !10, i64 0}
!26 = !{!"s2n_timer", !10, 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.1 = external hidden unnamed_addr constant [87 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_timer_elapsed(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #3 {
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store i64 0, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %0, i64 112
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  %9 = call i32 %6(ptr noundef %8, ptr noundef nonnull %4) #5
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %19, label %11

11:                                               ; preds = %3
  %12 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.1, ptr %12, align 8, !tbaa !18
  %13 = call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.1, i64 21), i32 noundef 47) #6
  %.not = icmp eq ptr %13, null
  %14 = getelementptr inbounds i8, ptr %13, i64 1
  %15 = select i1 %.not, ptr getelementptr inbounds (i8, ptr @.str.1, i64 21), ptr %14
  %16 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !20
  %17 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 335544386, ptr %17, align 4, !tbaa !21
  %18 = call i32 @s2n_calculate_stacktrace() #5
  br label %23

19:                                               ; preds = %3
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %1, align 8, !tbaa !22
  %22 = sub i64 %20, %21
  store i64 %22, ptr %2, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %19, %11
  %.sroa.0.0 = phi i32 [ 0, %19 ], [ -1, %11 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %.sroa.0.0
}

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 88}
!10 = !{!"s2n_config", !11, i64 0, !11, i64 0, !11, i64 0, !11, i64 0, !11, i64 0, !11, i64 0, !11, i64 0, !11, i64 0, !11, i64 1, !11, i64 1, !11, i64 1, !11, i64 1, !11, i64 1, !11, i64 1, !11, i64 1, !11, i64 1, !11, i64 2, !11, i64 2, !11, i64 2, !11, i64 2, !12, i64 8, !12, i64 16, !13, i64 24, !14, i64 56, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !11, i64 128, !11, i64 132, !12, i64 136, !6, i64 144, !12, i64 152, !6, i64 160, !6, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !11, i64 224, !7, i64 228, !11, i64 232, !11, i64 236, !12, i64 240, !12, i64 248, !12, i64 256, !12, i64 264, !12, i64 272, !12, i64 280, !12, i64 288, !7, i64 296, !7, i64 297, !15, i64 304, !16, i64 320, !12, i64 328, !12, i64 336, !12, i64 344, !12, i64 352, !12, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !11, i64 392, !11, i64 396, !11, i64 400, !12, i64 408, !11, i64 416, !11, i64 420, !12, i64 424, !12, i64 432, !11, i64 440, !14, i64 448}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"certs_by_type", !7, i64 0}
!14 = !{!"s2n_blob", !12, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!15 = !{!"s2n_x509_trust_store", !12, i64 0, !11, i64 8}
!16 = !{!"short", !7, i64 0}
!17 = !{!10, !12, i64 112}
!18 = !{!19, !12, i64 0}
!19 = !{!"s2n_debug_info", !12, i64 0, !12, i64 8}
!20 = !{!19, !12, i64 8}
!21 = !{!11, !11, i64 0}
!22 = !{!23, !6, i64 0}
!23 = !{!"s2n_timer", !6, i64 0}


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