; LLVM IR from aws/s2n-tls :: crypto (s2n_certificate)

; 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_cert_chain_and_key = type { ptr, ptr, %struct.s2n_blob, %struct.s2n_blob, ptr, ptr, ptr }
%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.5 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [95 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

declare i32 @s2n_free(ptr noundef) #2

declare i32 @s2n_alloc(ptr noundef, i32 noundef) #2

; 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_cert_chain_and_key_set_ocsp_data(ptr noundef %0, ptr noundef %1, i32 noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  br label %11

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

14:                                               ; preds = %11
  br label %15

15:                                               ; preds = %14
  br label %16

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

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

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

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

43:                                               ; preds = %37
  store i32 -1, ptr %4, align 4
  br label %137

44:                                               ; No predecessors!
  br label %45

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

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %48, i32 0, i32 2
  %50 = call i32 @s2n_free(ptr noundef %49)
  %51 = icmp sgt i32 %50, -1
  br i1 %51, label %53, label %52

52:                                               ; preds = %47
  store i32 -1, ptr %4, align 4
  br label %137

53:                                               ; preds = %47
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %136

57:                                               ; preds = %54
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %136

60:                                               ; preds = %57
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = call i32 @s2n_alloc(ptr noundef %63, i32 noundef %64)
  %66 = icmp sgt i32 %65, -1
  br i1 %66, label %68, label %67

67:                                               ; preds = %61
  store i32 -1, ptr %4, align 4
  br label %137

68:                                               ; preds = %61
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %71 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %71, ptr %8, align 4, !tbaa !9
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = icmp ne i32 %72, 0
  %74 = xor i1 %73, true
  %75 = xor i1 %74, true
  %76 = zext i1 %75 to i32
  %77 = sext i32 %76 to i64
  %78 = call i64 @llvm.expect.i64(i64 %77, i64 1)
  %79 = icmp ne i64 %78, 0
  br i1 %79, label %80, label %131

80:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.s2n_cert_chain_and_key, ptr %81, i32 0, i32 2
  %83 = getelementptr inbounds %struct.s2n_blob, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !14
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = zext i32 %86 to i64
  %88 = call ptr @s2n_ensure_memmove_trace(ptr noundef %84, ptr noundef %85, i64 noundef %87)
  store ptr %88, ptr %9, align 8, !tbaa !5
  br label %89

89:                                               ; preds = %80
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = icmp ne ptr %90, null
  br i1 %91, label %125, label %92

92:                                               ; preds = %89
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  %95 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %96 = getelementptr inbounds %struct.s2n_debug_info, ptr %95, i32 0, i32 0
  store ptr @.str.6, ptr %96, align 8, !tbaa !11
  %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 !11
  %100 = getelementptr inbounds i8, ptr %99, i64 21
  %101 = call ptr @strrchr(ptr noundef %100, i32 noundef 47) #6
  %102 = icmp ne ptr %101, null
  br i1 %102, label %103, label %110

103:                                              ; preds = %94
  %104 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %105 = getelementptr inbounds %struct.s2n_debug_info, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !11
  %107 = getelementptr inbounds i8, ptr %106, i64 21
  %108 = call ptr @strrchr(ptr noundef %107, i32 noundef 47) #6
  %109 = getelementptr inbounds i8, ptr %108, i64 1
  br label %115

110:                                              ; preds = %94
  %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
  br label %115

115:                                              ; preds = %110, %103
  %116 = phi ptr [ %109, %103 ], [ %114, %110 ]
  %117 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %118 = getelementptr inbounds %struct.s2n_debug_info, ptr %117, i32 0, i32 1
  store ptr %116, ptr %118, align 8, !tbaa !13
  %119 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %119, align 4, !tbaa !9
  %120 = call i32 @s2n_calculate_stacktrace()
  br label %121

121:                                              ; preds = %115
  br label %122

122:                                              ; preds = %121
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %128

123:                                              ; No predecessors!
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124, %89
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126
  store i32 0, ptr %10, align 4
  br label %128

128:                                              ; preds = %127, %122
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  %129 = load i32, ptr %10, align 4
  switch i32 %129, label %132 [
    i32 0, label %130
  ]

130:                                              ; preds = %128
  br label %131

131:                                              ; preds = %130, %70
  store i32 0, ptr %10, align 4
  br label %132

132:                                              ; preds = %131, %128
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  %133 = load i32, ptr %10, align 4
  switch i32 %133, label %139 [
    i32 0, label %134
    i32 1, label %137
  ]

134:                                              ; preds = %132
  br label %135

135:                                              ; preds = %134
  br label %136

136:                                              ; preds = %135, %57, %54
  store i32 0, ptr %4, align 4
  br label %137

137:                                              ; preds = %136, %132, %67, %52, %43
  %138 = load i32, ptr %4, align 4
  ret i32 %138

139:                                              ; preds = %132
  unreachable
}

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

declare ptr @s2n_ensure_memmove_trace(ptr noundef, ptr noundef, i64 noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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 = !{!"int", !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, !6, i64 16}
!15 = !{!"s2n_cert_chain_and_key", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 40, !6, i64 64, !6, i64 72, !6, i64 80}
!16 = !{!"s2n_blob", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}


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

declare i32 @s2n_free(ptr noundef) local_unnamed_addr #2

declare i32 @s2n_alloc(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_cert_chain_and_key_set_ocsp_data(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #3 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.critedge.thread.sink.split, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = tail call i32 @s2n_free(ptr noundef nonnull %5) #4
  %7 = icmp sgt i32 %6, -1
  br i1 %7, label %8, label %.critedge.thread

8:                                                ; preds = %4
  %9 = icmp ne ptr %1, null
  %10 = icmp ne i32 %2, 0
  %or.cond = and i1 %9, %10
  br i1 %or.cond, label %11, label %.critedge.thread

11:                                               ; preds = %8
  %12 = tail call i32 @s2n_alloc(ptr noundef nonnull %5, i32 noundef %2) #4
  %13 = icmp sgt i32 %12, -1
  br i1 %13, label %14, label %.critedge.thread

14:                                               ; preds = %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = zext i32 %2 to i64
  %17 = tail call ptr @s2n_ensure_memmove_trace(ptr noundef %15, ptr noundef nonnull %1, i64 noundef %16) #4
  %.not23.not = icmp eq ptr %17, null
  br i1 %.not23.not, label %.critedge.thread.sink.split, label %.critedge.thread

.critedge.thread.sink.split:                      ; preds = %14, %3
  %.str.6.sink = phi ptr [ @.str.5, %3 ], [ @.str.6, %14 ]
  %.sink31 = phi ptr [ getelementptr inbounds (i8, ptr @.str.5, i64 21), %3 ], [ getelementptr inbounds (i8, ptr @.str.6, i64 21), %14 ]
  %18 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr %.str.6.sink, ptr %18, align 8, !tbaa !12
  %19 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) %.sink31, i32 noundef 47) #5
  %.not24 = icmp eq ptr %19, null
  %20 = getelementptr inbounds i8, ptr %19, i64 1
  %21 = select i1 %.not24, ptr %.sink31, ptr %20
  %22 = getelementptr inbounds i8, ptr %18, i64 8
  store ptr %21, ptr %22, align 8, !tbaa !14
  %23 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %23, align 4, !tbaa !15
  %24 = tail call i32 @s2n_calculate_stacktrace() #4
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.critedge.thread.sink.split, %14, %8, %11, %4
  %.3 = phi i32 [ -1, %4 ], [ -1, %11 ], [ 0, %8 ], [ 0, %14 ], [ -1, %.critedge.thread.sink.split ]
  ret i32 %.3
}

declare ptr @s2n_ensure_memmove_trace(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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 }
attributes #5 = { 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, !7, i64 16}
!6 = !{!"s2n_cert_chain_and_key", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 40, !7, i64 64, !7, i64 72, !7, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"s2n_blob", !7, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"s2n_debug_info", !7, i64 0, !7, i64 8}
!14 = !{!13, !7, i64 8}
!15 = !{!11, !11, i64 0}


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