; LLVM IR from guanzhi/GmSSL :: src (hex)

; 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 [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__FUNCTION__.hex2bin = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @hex2bin(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = urem i64 %10, 2
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %21

13:                                               ; preds = %3
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 108, ptr noundef @__FUNCTION__.hex2bin, ptr noundef %16, i64 noundef %17) #3
  br label %19

19:                                               ; preds = %14
  br label %20

20:                                               ; preds = %19
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %69

21:                                               ; preds = %3
  br label %22

22:                                               ; preds = %55, %21
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %68

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %5, align 8, !tbaa !5
  %28 = load i8, ptr %26, align 1, !tbaa !11
  %29 = call i32 @hexchar2int(i8 noundef signext %28)
  store i32 %29, ptr %8, align 4, !tbaa !12
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %31, label %37

31:                                               ; preds = %25
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 114, ptr noundef @__FUNCTION__.hex2bin) #3
  br label %35

35:                                               ; preds = %32
  br label %36

36:                                               ; preds = %35
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %69

37:                                               ; preds = %25
  %38 = load i32, ptr %8, align 4, !tbaa !12
  %39 = trunc i32 %38 to i8
  %40 = zext i8 %39 to i32
  %41 = shl i32 %40, 4
  %42 = trunc i32 %41 to i8
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 %42, ptr %43, align 1, !tbaa !11
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i32 1
  store ptr %45, ptr %5, align 8, !tbaa !5
  %46 = load i8, ptr %44, align 1, !tbaa !11
  %47 = call i32 @hexchar2int(i8 noundef signext %46)
  store i32 %47, ptr %8, align 4, !tbaa !12
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %49, label %55

49:                                               ; preds = %37
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 119, ptr noundef @__FUNCTION__.hex2bin) #3
  br label %53

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %69

55:                                               ; preds = %37
  %56 = load i32, ptr %8, align 4, !tbaa !12
  %57 = trunc i32 %56 to i8
  %58 = zext i8 %57 to i32
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i8, ptr %59, align 1, !tbaa !11
  %61 = zext i8 %60 to i32
  %62 = or i32 %61, %58
  %63 = trunc i32 %62 to i8
  store i8 %63, ptr %59, align 1, !tbaa !11
  %64 = load i64, ptr %6, align 8, !tbaa !9
  %65 = sub i64 %64, 2
  store i64 %65, ptr %6, align 8, !tbaa !9
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i32 1
  store ptr %67, ptr %7, align 8, !tbaa !5
  br label %22, !llvm.loop !14

68:                                               ; preds = %22
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %69

69:                                               ; preds = %68, %54, %36, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %70 = load i32, ptr %4, align 4
  ret i32 %70
}

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

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

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

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

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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 }

!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 = !{!13, !13, i64 0}
!13 = !{!"int", !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 [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__FUNCTION__.hex2bin = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

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

.preheader:                                       ; preds = %3
  %.not1718 = icmp eq i64 %1, 0
  br i1 %.not1718, label %.loopexit, label %.lr.ph

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, ptr noundef nonnull @.str.1, i32 noundef 108, ptr noundef nonnull @__FUNCTION__.hex2bin, ptr noundef %0, i64 noundef %1) #2
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %23
  %.021 = phi ptr [ %29, %23 ], [ %2, %.preheader ]
  %.01220 = phi i64 [ %28, %23 ], [ %1, %.preheader ]
  %.01319 = phi ptr [ %24, %23 ], [ %0, %.preheader ]
  %8 = load i8, ptr %.01319, align 1, !tbaa !9
  %9 = tail call i32 @hexchar2int(i8 noundef signext %8)
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %.lr.ph
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 114, ptr noundef nonnull @__FUNCTION__.hex2bin) #2
  br label %.loopexit

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %.01319, i64 1
  %.tr = trunc i32 %9 to i8
  %16 = shl i8 %.tr, 4
  store i8 %16, ptr %.021, align 1, !tbaa !9
  %17 = load i8, ptr %15, align 1, !tbaa !9
  %18 = tail call i32 @hexchar2int(i8 noundef signext %17)
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %14
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 119, ptr noundef nonnull @__FUNCTION__.hex2bin) #2
  br label %.loopexit

23:                                               ; preds = %14
  %24 = getelementptr inbounds i8, ptr %.01319, i64 2
  %25 = load i8, ptr %.021, align 1, !tbaa !9
  %26 = trunc i32 %18 to i8
  %27 = or i8 %25, %26
  store i8 %27, ptr %.021, align 1, !tbaa !9
  %28 = add i64 %.01220, -2
  %29 = getelementptr inbounds i8, ptr %.021, i64 1
  %.not17 = icmp eq i64 %28, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %23, %.preheader, %20, %11, %5
  %.014 = phi i32 [ -1, %5 ], [ -1, %11 ], [ -1, %20 ], [ 1, %.preheader ], [ 1, %23 ]
  ret i32 %.014
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @hexchar2int(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 = { 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 #2 = { cold 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass