; 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
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__.buf2hexstr = external hidden unnamed_addr constant [63 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @buf2hexstr(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %4
  br label %14

13:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.3, i32 noundef 78, ptr noundef @__PRETTY_FUNCTION__.buf2hexstr) #5
  unreachable

14:                                               ; preds = %12
  %15 = load ptr, ptr %7, 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.2, ptr noundef @.str.3, i32 noundef 79, ptr noundef @__PRETTY_FUNCTION__.buf2hexstr) #5
  unreachable

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

22:                                               ; preds = %19
  br label %24

23:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.3, i32 noundef 80, ptr noundef @__PRETTY_FUNCTION__.buf2hexstr) #5
  unreachable

24:                                               ; preds = %22
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = mul i64 2, %26
  %28 = icmp uge i64 %25, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  br label %31

30:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.3, i32 noundef 81, ptr noundef @__PRETTY_FUNCTION__.buf2hexstr) #5
  unreachable

31:                                               ; preds = %29
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %32, i8 0, i64 %33, i1 false)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %64, %31
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %38, label %67

38:                                               ; preds = %34
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = ashr i32 %43, 4
  %45 = trunc i32 %44 to i8
  %46 = call signext i8 @byte2hexdigit(i8 noundef zeroext %45)
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = mul i64 2, %48
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  store i8 %46, ptr %50, align 1, !tbaa !11
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %51, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = and i32 %55, 15
  %57 = trunc i32 %56 to i8
  %58 = call signext i8 @byte2hexdigit(i8 noundef zeroext %57)
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = mul i64 2, %60
  %62 = add i64 %61, 1
  %63 = getelementptr inbounds i8, ptr %59, i64 %62
  store i8 %58, ptr %63, align 1, !tbaa !11
  br label %64

64:                                               ; preds = %38
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %9, align 8, !tbaa !9
  br label %34, !llvm.loop !12

67:                                               ; preds = %34
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i64, ptr %9, align 8, !tbaa !9
  %70 = mul i64 2, %69
  %71 = getelementptr inbounds i8, ptr %68, i64 %70
  store i8 0, ptr %71, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn memory(argmem: write) }
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 = { noreturn 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 = !{!"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
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__.buf2hexstr = external hidden unnamed_addr constant [63 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @buf2hexstr(ptr noundef writeonly %0, i64 noundef %1, ptr noundef readonly %2, i64 noundef %3) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

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

6:                                                ; preds = %4
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %7, label %8

7:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 79, ptr noundef nonnull @__PRETTY_FUNCTION__.buf2hexstr) #3
  unreachable

8:                                                ; preds = %6
  %.not24 = icmp eq i64 %3, 0
  br i1 %.not24, label %9, label %10

9:                                                ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.3, i32 noundef 80, ptr noundef nonnull @__PRETTY_FUNCTION__.buf2hexstr) #3
  unreachable

10:                                               ; preds = %8
  %11 = shl i64 %3, 1
  %.not25 = icmp ugt i64 %11, %1
  br i1 %.not25, label %12, label %13

12:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.3, i32 noundef 81, ptr noundef nonnull @__PRETTY_FUNCTION__.buf2hexstr) #3
  unreachable

13:                                               ; preds = %10
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %0, i8 0, i64 %1, i1 false)
  br label %14

14:                                               ; preds = %13, %14
  %.026 = phi i64 [ 0, %13 ], [ %26, %14 ]
  %15 = getelementptr inbounds i8, ptr %2, i64 %.026
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = lshr i8 %16, 4
  %18 = tail call signext i8 @byte2hexdigit(i8 noundef zeroext %17)
  %19 = shl i64 %.026, 1
  %20 = getelementptr inbounds i8, ptr %0, i64 %19
  store i8 %18, ptr %20, align 1, !tbaa !5
  %21 = load i8, ptr %15, align 1, !tbaa !5
  %22 = and i8 %21, 15
  %23 = tail call signext i8 @byte2hexdigit(i8 noundef zeroext %22)
  %24 = or disjoint i64 %19, 1
  %25 = getelementptr inbounds i8, ptr %0, i64 %24
  store i8 %23, ptr %25, align 1, !tbaa !5
  %26 = add nuw i64 %.026, 1
  %exitcond.not = icmp eq i64 %26, %3
  br i1 %exitcond.not, label %27, label %14, !llvm.loop !8

27:                                               ; preds = %14
  %28 = getelementptr inbounds i8, ptr %0, i64 %11
  store i8 0, ptr %28, align 1, !tbaa !5
  ret void
}

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { noreturn 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass