; LLVM IR from opencryptoki/libzpc :: src (misc)

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

@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [64 x i8], align 1
@__PRETTY_FUNCTION__.hexstr2buf = external hidden unnamed_addr constant [45 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @hexstr2buf(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, 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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %14

13:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 47, ptr noundef @__PRETTY_FUNCTION__.hexstr2buf) #6
  unreachable

14:                                               ; preds = %12
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.3, i32 noundef 48, ptr noundef @__PRETTY_FUNCTION__.hexstr2buf) #6
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  br label %25

24:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.3, i32 noundef 49, ptr noundef @__PRETTY_FUNCTION__.hexstr2buf) #6
  unreachable

25:                                               ; preds = %23
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  br label %30

29:                                               ; preds = %25
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.3, i32 noundef 50, ptr noundef @__PRETTY_FUNCTION__.hexstr2buf) #6
  unreachable

30:                                               ; preds = %28
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call i64 @strlen(ptr noundef %31) #7
  %33 = icmp uge i64 %32, 2
  br i1 %33, label %34, label %49

34:                                               ; preds = %30
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 0
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = icmp eq i32 %38, 48
  br i1 %39, label %40, label %49

40:                                               ; preds = %34
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 1
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 120
  br i1 %45, label %46, label %49

46:                                               ; preds = %40
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 2
  store ptr %48, ptr %7, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %46, %40, %34, %30
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = call i64 @strlen(ptr noundef %50) #7
  %52 = icmp eq i64 %51, 0
  br i1 %52, label %65, label %53

53:                                               ; preds = %49
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = call i64 @strlen(ptr noundef %54) #7
  %56 = urem i64 %55, 2
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %65, label %58

58:                                               ; preds = %53
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = call i64 @strlen(ptr noundef %59) #7
  %61 = udiv i64 %60, 2
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = icmp ugt i64 %61, %63
  br i1 %64, label %65, label %66

65:                                               ; preds = %58, %53, %49
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %128

66:                                               ; preds = %58
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load i64, ptr %68, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %67, i8 0, i64 %69, i1 false)
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %120, %66
  %71 = load i64, ptr %8, align 8, !tbaa !9
  %72 = add i64 %71, 1
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = call i64 @strlen(ptr noundef %73) #7
  %75 = icmp ult i64 %72, %74
  br i1 %75, label %76, label %123

76:                                               ; preds = %70
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i64, ptr %8, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !11
  %81 = call i32 @ishexdigit(i8 noundef signext %80)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %91

83:                                               ; preds = %76
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load i64, ptr %8, align 8, !tbaa !9
  %86 = add i64 %85, 1
  %87 = getelementptr inbounds i8, ptr %84, i64 %86
  %88 = load i8, ptr %87, align 1, !tbaa !11
  %89 = call i32 @ishexdigit(i8 noundef signext %88)
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %92, label %91

91:                                               ; preds = %83, %76
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %128

92:                                               ; preds = %83
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = getelementptr inbounds i8, ptr %93, i64 %94
  %96 = load i8, ptr %95, align 1, !tbaa !11
  %97 = call zeroext i8 @hexdigit2byte(i8 noundef signext %96)
  %98 = zext i8 %97 to i32
  %99 = shl i32 %98, 4
  %100 = trunc i32 %99 to i8
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = load i64, ptr %8, align 8, !tbaa !9
  %103 = udiv i64 %102, 2
  %104 = getelementptr inbounds i8, ptr %101, i64 %103
  store i8 %100, ptr %104, align 1, !tbaa !11
  %105 = load ptr, ptr %7, align 8, !tbaa !5
  %106 = load i64, ptr %8, align 8, !tbaa !9
  %107 = add i64 %106, 1
  %108 = getelementptr inbounds i8, ptr %105, i64 %107
  %109 = load i8, ptr %108, align 1, !tbaa !11
  %110 = call zeroext i8 @hexdigit2byte(i8 noundef signext %109)
  %111 = zext i8 %110 to i32
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = load i64, ptr %8, align 8, !tbaa !9
  %114 = udiv i64 %113, 2
  %115 = getelementptr inbounds i8, ptr %112, i64 %114
  %116 = load i8, ptr %115, align 1, !tbaa !11
  %117 = zext i8 %116 to i32
  %118 = add nsw i32 %117, %111
  %119 = trunc i32 %118 to i8
  store i8 %119, ptr %115, align 1, !tbaa !11
  br label %120

120:                                              ; preds = %92
  %121 = load i64, ptr %8, align 8, !tbaa !9
  %122 = add i64 %121, 2
  store i64 %122, ptr %8, align 8, !tbaa !9
  br label %70, !llvm.loop !12

123:                                              ; preds = %70
  %124 = load ptr, ptr %7, align 8, !tbaa !5
  %125 = call i64 @strlen(ptr noundef %124) #7
  %126 = udiv i64 %125, 2
  %127 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %126, ptr %127, align 8, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %128

128:                                              ; preds = %123, %91, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %129 = load i32, ptr %4, align 4
  ret i32 %129
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ishexdigit(i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @hexdigit2byte(i8 noundef signext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [64 x i8], align 1
@__PRETTY_FUNCTION__.hexstr2buf = external hidden unnamed_addr constant [45 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1

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

4:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 47, ptr noundef nonnull @__PRETTY_FUNCTION__.hexstr2buf) #4
  unreachable

5:                                                ; preds = %3
  %.not40 = icmp eq ptr %1, null
  br i1 %.not40, label %6, label %7

6:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.3, i32 noundef 48, ptr noundef nonnull @__PRETTY_FUNCTION__.hexstr2buf) #4
  unreachable

7:                                                ; preds = %5
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %.not41 = icmp eq i64 %8, 0
  br i1 %.not41, label %9, label %10

9:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.3, i32 noundef 49, ptr noundef nonnull @__PRETTY_FUNCTION__.hexstr2buf) #4
  unreachable

10:                                               ; preds = %7
  %.not42 = icmp eq ptr %2, null
  br i1 %.not42, label %11, label %12

11:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.3, i32 noundef 50, ptr noundef nonnull @__PRETTY_FUNCTION__.hexstr2buf) #4
  unreachable

12:                                               ; preds = %10
  %13 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #5
  %14 = icmp ugt i64 %13, 1
  br i1 %14, label %15, label %22

15:                                               ; preds = %12
  %16 = load i8, ptr %2, align 1, !tbaa !9
  %17 = icmp eq i8 %16, 48
  br i1 %17, label %18, label %22

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %2, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = icmp eq i8 %20, 120
  %spec.select.idx = select i1 %21, i64 2, i64 0
  %spec.select = getelementptr inbounds i8, ptr %2, i64 %spec.select.idx
  br label %22

22:                                               ; preds = %18, %15, %12
  %.031 = phi ptr [ %2, %15 ], [ %2, %12 ], [ %spec.select, %18 ]
  %23 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.031) #5
  %24 = icmp eq i64 %23, 0
  %25 = and i64 %23, 1
  %.not43 = icmp ne i64 %25, 0
  %or.cond.not49 = or i1 %24, %.not43
  %26 = lshr exact i64 %23, 1
  %27 = icmp ugt i64 %26, %8
  %or.cond47 = select i1 %or.cond.not49, i1 true, i1 %27
  br i1 %or.cond47, label %.loopexit, label %28

28:                                               ; preds = %22
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %0, i8 0, i64 %8, i1 false)
  %29 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.031) #5
  %30 = icmp ugt i64 %29, 1
  br i1 %30, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %28, %39
  %.051 = phi i64 [ %49, %39 ], [ 0, %28 ]
  %31 = getelementptr inbounds i8, ptr %.031, i64 %.051
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = tail call i32 @ishexdigit(i8 noundef signext %32)
  %.not44 = icmp eq i32 %33, 0
  br i1 %.not44, label %.loopexit, label %34

34:                                               ; preds = %.lr.ph
  %35 = or disjoint i64 %.051, 1
  %36 = getelementptr inbounds i8, ptr %.031, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = tail call i32 @ishexdigit(i8 noundef signext %37)
  %.not45 = icmp eq i32 %38, 0
  br i1 %.not45, label %.loopexit, label %39

39:                                               ; preds = %34
  %40 = load i8, ptr %31, align 1, !tbaa !9
  %41 = tail call zeroext i8 @hexdigit2byte(i8 noundef signext %40)
  %42 = shl i8 %41, 4
  %43 = lshr exact i64 %.051, 1
  %44 = getelementptr inbounds i8, ptr %0, i64 %43
  store i8 %42, ptr %44, align 1, !tbaa !9
  %45 = load i8, ptr %36, align 1, !tbaa !9
  %46 = tail call zeroext i8 @hexdigit2byte(i8 noundef signext %45)
  %47 = load i8, ptr %44, align 1, !tbaa !9
  %48 = add i8 %47, %46
  store i8 %48, ptr %44, align 1, !tbaa !9
  %49 = add i64 %.051, 2
  %50 = or disjoint i64 %49, 1
  %51 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.031) #5
  %52 = icmp ult i64 %50, %51
  br i1 %52, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %39, %28
  %.lcssa = phi i64 [ %29, %28 ], [ %51, %39 ]
  %53 = lshr i64 %.lcssa, 1
  store i64 %53, ptr %1, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %34, %22, %._crit_edge
  %.032 = phi i32 [ 0, %._crit_edge ], [ -1, %22 ], [ -1, %34 ], [ -1, %.lr.ph ]
  ret i32 %.032
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ishexdigit(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @hexdigit2byte(i8 noundef signext) local_unnamed_addr #0

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 = { 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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { noreturn 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, !6, i64 0}
!6 = !{!"long", !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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass