; LLVM IR from aws/s2n-tls :: bin (common)

; 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"

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1
@hex_inverse = external hidden constant [256 x i8], align 16
@.str.9 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [74 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_str_hex_to_bytes(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %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 i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i8, align 1
  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 %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str) #5
  call void @exit(i32 noundef 1) #6
  unreachable

20:                                               ; preds = %14
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str) #5
  call void @exit(i32 noundef 1) #6
  unreachable

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i64 @strlen(ptr noundef %30) #7
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %103, %45, %29
  %34 = load i64, ptr %10, align 8, !tbaa !11
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = icmp ult i64 %34, %36
  br i1 %37, label %38, label %104

38:                                               ; preds = %33
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %10, align 8, !tbaa !11
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %43, 32
  br i1 %44, label %45, label %48

45:                                               ; preds = %38
  %46 = load i64, ptr %10, align 8, !tbaa !11
  %47 = add i64 %46, 1
  store i64 %47, ptr %10, align 8, !tbaa !11
  br label %33, !llvm.loop !14

48:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %10, align 8, !tbaa !11
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !13
  %53 = zext i8 %52 to i64
  %54 = getelementptr inbounds [256 x i8], ptr @hex_inverse, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !13
  store i8 %55, ptr %11, align 1, !tbaa !13
  %56 = load i8, ptr %11, align 1, !tbaa !13
  %57 = zext i8 %56 to i32
  %58 = icmp eq i32 %57, 255
  br i1 %58, label %59, label %62

59:                                               ; preds = %48
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.9) #5
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %101

62:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i64, ptr %10, align 8, !tbaa !11
  %65 = add i64 %64, 1
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !13
  %68 = zext i8 %67 to i64
  %69 = getelementptr inbounds [256 x i8], ptr @hex_inverse, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !13
  store i8 %70, ptr %13, align 1, !tbaa !13
  %71 = load i8, ptr %13, align 1, !tbaa !13
  %72 = zext i8 %71 to i32
  %73 = icmp eq i32 %72, 255
  br i1 %73, label %74, label %77

74:                                               ; preds = %62
  %75 = load ptr, ptr @stderr, align 8, !tbaa !5
  %76 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %75, ptr noundef @.str.9) #5
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %100

77:                                               ; preds = %62
  %78 = load i32, ptr %7, align 4, !tbaa !9
  %79 = zext i32 %78 to i64
  %80 = load i64, ptr %9, align 8, !tbaa !11
  %81 = icmp ult i64 %79, %80
  br i1 %81, label %82, label %85

82:                                               ; preds = %77
  %83 = load ptr, ptr @stderr, align 8, !tbaa !5
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.10) #5
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %100

85:                                               ; preds = %77
  %86 = load i8, ptr %11, align 1, !tbaa !13
  %87 = zext i8 %86 to i32
  %88 = shl i32 %87, 4
  %89 = load i8, ptr %13, align 1, !tbaa !13
  %90 = zext i8 %89 to i32
  %91 = or i32 %88, %90
  %92 = trunc i32 %91 to i8
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = load i64, ptr %9, align 8, !tbaa !11
  %95 = getelementptr inbounds i8, ptr %93, i64 %94
  store i8 %92, ptr %95, align 1, !tbaa !13
  %96 = load i64, ptr %9, align 8, !tbaa !11
  %97 = add i64 %96, 1
  store i64 %97, ptr %9, align 8, !tbaa !11
  %98 = load i64, ptr %10, align 8, !tbaa !11
  %99 = add i64 %98, 2
  store i64 %99, ptr %10, align 8, !tbaa !11
  store i32 0, ptr %12, align 4
  br label %100

100:                                              ; preds = %85, %82, %74
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  br label %101

101:                                              ; preds = %100, %59
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  %102 = load i32, ptr %12, align 4
  switch i32 %102, label %105 [
    i32 0, label %103
  ]

103:                                              ; preds = %101
  br label %33, !llvm.loop !14

104:                                              ; preds = %33
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %105

105:                                              ; preds = %104, %101
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %106 = load i32, ptr %4, align 4
  ret i32 %106
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

attributes #0 = { nounwind "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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1
@hex_inverse = external hidden local_unnamed_addr constant [256 x i8], align 16
@.str.9 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [74 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @s2n_str_hex_to_bytes(ptr noundef readonly %0, ptr noundef writeonly %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %5, label %8

5:                                                ; preds = %3
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

8:                                                ; preds = %3
  %9 = icmp eq ptr %1, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

13:                                               ; preds = %8
  %14 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  %15 = and i64 %14, 4294967295
  %invariant.gep = getelementptr i8, ptr %0, i64 1
  %.not = icmp eq i64 %15, 0
  br i1 %.not, label %.thread, label %.lr.ph.lr.ph

.lr.ph.lr.ph:                                     ; preds = %13
  %16 = zext i32 %2 to i64
  %17 = add nuw nsw i64 %16, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %.outer
  %.025.ph43 = phi i64 [ 0, %.lr.ph.lr.ph ], [ %40, %.outer ]
  %.028.ph42 = phi i64 [ 0, %.lr.ph.lr.ph ], [ %41, %.outer ]
  br label %18

18:                                               ; preds = %.lr.ph, %22
  %.02841 = phi i64 [ %.028.ph42, %.lr.ph ], [ %23, %22 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 %.02841
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = icmp eq i8 %20, 32
  br i1 %21, label %22, label %25

22:                                               ; preds = %18
  %23 = add nuw nsw i64 %.02841, 1
  %24 = icmp ult i64 %23, %15
  br i1 %24, label %18, label %.thread, !llvm.loop !10

25:                                               ; preds = %18
  %26 = zext i8 %20 to i64
  %27 = getelementptr inbounds [256 x i8], ptr @hex_inverse, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = icmp eq i8 %28, -1
  br i1 %29, label %.thread.sink.split, label %30

30:                                               ; preds = %25
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.02841
  %31 = load i8, ptr %gep, align 1, !tbaa !9
  %32 = zext i8 %31 to i64
  %33 = getelementptr inbounds [256 x i8], ptr @hex_inverse, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = icmp eq i8 %34, -1
  br i1 %35, label %.thread.sink.split, label %36

36:                                               ; preds = %30
  %exitcond = icmp eq i64 %.025.ph43, %17
  br i1 %exitcond, label %.thread.sink.split, label %.outer

.outer:                                           ; preds = %36
  %37 = shl i8 %28, 4
  %38 = or i8 %34, %37
  %39 = getelementptr inbounds i8, ptr %1, i64 %.025.ph43
  store i8 %38, ptr %39, align 1, !tbaa !9
  %40 = add nuw nsw i64 %.025.ph43, 1
  %41 = add nuw nsw i64 %.02841, 2
  %42 = icmp ult i64 %41, %15
  br i1 %42, label %.lr.ph, label %.thread, !llvm.loop !10

.thread.sink.split:                               ; preds = %36, %30, %25
  %.str.10.sink = phi ptr [ @.str.9, %25 ], [ @.str.9, %30 ], [ @.str.10, %36 ]
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull %.str.10.sink) #4
  br label %.thread

.thread:                                          ; preds = %.outer, %22, %.thread.sink.split, %13
  %.3 = phi i32 [ 0, %13 ], [ -1, %.thread.sink.split ], [ 0, %22 ], [ 0, %.outer ]
  ret i32 %.3
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { nofree nounwind "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 = { noreturn nounwind "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 = { 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 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 #4 = { cold nounwind }
attributes #5 = { noreturn 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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