; LLVM IR from aws/s2n-tls :: stuffer (s2n_stuffer)

; 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_stuffer = type { %struct.s2n_blob, i32, i32, i32, i8 }
%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.19 = external hidden unnamed_addr constant [92 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_stuffer_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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #6

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_stuffer_wipe(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.s2n_result, align 4
  %5 = alloca %struct.s2n_result, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.s2n_result, align 4
  %10 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %11

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

24:                                               ; preds = %11
  %25 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 0, ptr %25, align 4, !tbaa !9
  br label %28

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

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

32:                                               ; preds = %28
  store i32 -1, ptr %2, align 4
  br label %143

33:                                               ; preds = %28
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s2n_stuffer, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 8, !tbaa !12
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %107, label %39

39:                                               ; preds = %34
  br label %40

40:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.s2n_stuffer, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %42, align 8, !tbaa !12
  store i32 %43, ptr %6, align 4, !tbaa !15
  %44 = load i32, ptr %6, align 4, !tbaa !15
  %45 = icmp ne i32 %44, 0
  %46 = xor i1 %45, true
  %47 = xor i1 %46, true
  %48 = zext i1 %47 to i32
  %49 = sext i32 %48 to i64
  %50 = call i64 @llvm.expect.i64(i64 %49, i64 1)
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %102

52:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.s2n_stuffer, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.s2n_blob, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  store ptr %56, ptr %7, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %52
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %93, label %60

60:                                               ; preds = %57
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %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 0
  store ptr @.str.19, ptr %64, align 8, !tbaa !17
  %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 !17
  %68 = getelementptr inbounds i8, ptr %67, i64 21
  %69 = call ptr @strrchr(ptr noundef %68, i32 noundef 47) #9
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %78

71:                                               ; preds = %62
  %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 !17
  %75 = getelementptr inbounds i8, ptr %74, i64 21
  %76 = call ptr @strrchr(ptr noundef %75, i32 noundef 47) #9
  %77 = getelementptr inbounds i8, ptr %76, i64 1
  br label %83

78:                                               ; preds = %62
  %79 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %80 = getelementptr inbounds %struct.s2n_debug_info, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = getelementptr inbounds i8, ptr %81, i64 21
  br label %83

83:                                               ; preds = %78, %71
  %84 = phi ptr [ %77, %71 ], [ %82, %78 ]
  %85 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %86 = getelementptr inbounds %struct.s2n_debug_info, ptr %85, i32 0, i32 1
  store ptr %84, ptr %86, align 8, !tbaa !19
  %87 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %87, align 4, !tbaa !15
  %88 = call i32 @s2n_calculate_stacktrace()
  br label %89

89:                                               ; preds = %83
  br label %90

90:                                               ; preds = %89
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %99

91:                                               ; No predecessors!
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92, %57
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load i32, ptr %6, align 4, !tbaa !15
  %98 = zext i32 %97 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %96, i8 119, i64 %98, i1 false)
  store i32 0, ptr %8, align 4
  br label %99

99:                                               ; preds = %95, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  %100 = load i32, ptr %8, align 4
  switch i32 %100, label %103 [
    i32 0, label %101
  ]

101:                                              ; preds = %99
  br label %102

102:                                              ; preds = %101, %40
  store i32 0, ptr %8, align 4
  br label %103

103:                                              ; preds = %102, %99
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  %104 = load i32, ptr %8, align 4
  switch i32 %104, label %145 [
    i32 0, label %105
    i32 1, label %143
  ]

105:                                              ; preds = %103
  br label %106

106:                                              ; preds = %105
  br label %107

107:                                              ; preds = %106, %34
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.s2n_stuffer, ptr %108, i32 0, i32 4
  %110 = load i8, ptr %109, align 4
  %111 = and i8 %110, -5
  %112 = or i8 %111, 0
  store i8 %112, ptr %109, align 4
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.s2n_stuffer, ptr %113, i32 0, i32 2
  store i32 0, ptr %114, align 4, !tbaa !20
  %115 = load ptr, ptr %3, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.s2n_stuffer, ptr %115, i32 0, i32 1
  store i32 0, ptr %116, align 8, !tbaa !21
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.s2n_stuffer, ptr %117, i32 0, i32 3
  store i32 0, ptr %118, align 8, !tbaa !12
  br label %119

119:                                              ; preds = %107
  %120 = load ptr, ptr %3, align 8, !tbaa !5
  %121 = call i32 @s2n_stuffer_validate(ptr noundef %120)
  %122 = getelementptr inbounds %struct.s2n_result, ptr %10, i32 0, i32 0
  store i32 %121, ptr %122, align 4
  %123 = getelementptr inbounds %struct.s2n_result, ptr %10, i32 0, i32 0
  %124 = load i32, ptr %123, align 4
  %125 = call zeroext i1 @s2n_result_is_ok(i32 %124)
  %126 = xor i1 %125, true
  %127 = xor i1 %126, true
  %128 = zext i1 %127 to i32
  %129 = sext i32 %128 to i64
  %130 = call i64 @llvm.expect.i64(i64 %129, i64 1)
  %131 = icmp ne i64 %130, 0
  br i1 %131, label %132, label %134

132:                                              ; preds = %119
  %133 = getelementptr inbounds %struct.s2n_result, ptr %9, i32 0, i32 0
  store i32 0, ptr %133, align 4, !tbaa !9
  br label %136

134:                                              ; preds = %119
  %135 = getelementptr inbounds %struct.s2n_result, ptr %9, i32 0, i32 0
  store i32 -1, ptr %135, align 4, !tbaa !9
  br label %136

136:                                              ; preds = %134, %132
  %137 = getelementptr inbounds %struct.s2n_result, ptr %9, i32 0, i32 0
  %138 = load i32, ptr %137, align 4
  %139 = call zeroext i1 @s2n_result_is_ok(i32 %138)
  br i1 %139, label %141, label %140

140:                                              ; preds = %136
  store i32 -1, ptr %2, align 4
  br label %143

141:                                              ; preds = %136
  br label %142

142:                                              ; preds = %141
  store i32 0, ptr %2, align 4
  br label %143

143:                                              ; preds = %142, %140, %103, %32
  %144 = load i32, ptr %2, align 4
  ret i32 %144

145:                                              ; preds = %103
  unreachable
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #8 = { nounwind }
attributes #9 = { 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, !11, i64 0}
!10 = !{!"", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 32}
!13 = !{!"s2n_stuffer", !14, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 36, !11, i64 36}
!14 = !{!"s2n_blob", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!15 = !{!11, !11, i64 0}
!16 = !{!13, !6, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!19 = !{!18, !6, i64 8}
!20 = !{!13, !11, i64 28}
!21 = !{!13, !11, i64 24}


; 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.19 = external hidden unnamed_addr constant [92 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_stuffer_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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %20, label %9

9:                                                ; preds = %5
  %10 = load ptr, ptr %0, align 8, !tbaa !12
  %.not.not = icmp eq ptr %10, null
  br i1 %.not.not, label %12, label %.thread

.thread:                                          ; preds = %9
  %11 = zext i32 %7 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %10, i8 119, i64 %11, i1 false)
  br label %20

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

20:                                               ; preds = %.thread, %5
  %21 = getelementptr inbounds i8, ptr %0, i64 36
  %22 = load i8, ptr %21, align 4
  %23 = and i8 %22, -5
  store i8 %23, ptr %21, align 4
  %24 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 0, ptr %24, align 4, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %25, align 8, !tbaa !18
  store i32 0, ptr %6, align 8, !tbaa !5
  %26 = tail call i32 @s2n_stuffer_validate(ptr noundef nonnull %0)
  %27 = tail call zeroext i1 @s2n_result_is_ok(i32 %26)
  %not.25 = xor i1 %27, true
  %.23 = sext i1 %not.25 to i32
  %28 = tail call zeroext i1 @s2n_result_is_ok(i32 %.23)
  %not.26 = xor i1 %28, true
  %spec.select = sext i1 %not.26 to i32
  br label %29

29:                                               ; preds = %12, %20, %1
  %.3 = phi i32 [ -1, %12 ], [ -1, %1 ], [ %spec.select, %20 ]
  ret i32 %.3
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !11, i64 32}
!6 = !{!"s2n_stuffer", !7, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 36, !11, i64 36}
!7 = !{!"s2n_blob", !8, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !8, i64 0}
!13 = !{!14, !8, i64 0}
!14 = !{!"s2n_debug_info", !8, i64 0, !8, i64 8}
!15 = !{!14, !8, i64 8}
!16 = !{!11, !11, i64 0}
!17 = !{!6, !11, i64 28}
!18 = !{!6, !11, i64 24}


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