; LLVM IR from pingcap/tidb-bench :: ssb/dbgen (bcd2)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @bin_bcd2(i64 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [15 x i8], align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 15, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !9
  store i64 0, ptr %11, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  store i64 0, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds [15 x i8], ptr %7, i64 0, i64 0
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %13, ptr noundef @.str, i64 noundef %14) #3
  %16 = getelementptr inbounds [15 x i8], ptr %7, i64 0, i64 0
  store ptr %16, ptr %8, align 8, !tbaa !9
  store i32 13, ptr %9, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %42, %3
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = load i8, ptr %18, align 1, !tbaa !13
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %47

21:                                               ; preds = %17
  %22 = load i32, ptr %9, align 4, !tbaa !11
  %23 = icmp slt i32 %22, 7
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  br label %28

26:                                               ; preds = %21
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %26, %24
  %29 = phi ptr [ %25, %24 ], [ %27, %26 ]
  store ptr %29, ptr %10, align 8, !tbaa !9
  %30 = load ptr, ptr %10, align 8, !tbaa !9
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = shl i64 %31, 4
  %33 = load ptr, ptr %10, align 8, !tbaa !9
  store i64 %32, ptr %33, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = load i8, ptr %34, align 1, !tbaa !13
  %36 = sext i8 %35 to i32
  %37 = sub nsw i32 %36, 48
  %38 = sext i32 %37 to i64
  %39 = load ptr, ptr %10, align 8, !tbaa !9
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = or i64 %40, %38
  store i64 %41, ptr %39, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %28
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %8, align 8, !tbaa !9
  %45 = load i32, ptr %9, align 4, !tbaa !11
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %9, align 4, !tbaa !11
  br label %17, !llvm.loop !14

47:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 15, ptr %7) #3
  ret i32 0
}

; 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 @sprintf(ptr noundef, ptr noundef, ...) #2

; 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @bin_bcd2(i64 noundef %0, ptr nocapture noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = alloca [15 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 15, ptr nonnull %4) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  store i64 0, ptr %1, align 8, !tbaa !5
  %5 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %0) #3
  %6 = load i8, ptr %4, align 1, !tbaa !9
  %.not13 = icmp eq i8 %6, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = shl i64 %7, 4
  %9 = sext i8 %6 to i64
  %10 = add nsw i64 %9, -48
  %11 = or i64 %8, %10
  store i64 %11, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %4, i64 1
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %.not.peel = icmp eq i8 %13, 0
  br i1 %.not.peel, label %._crit_edge, label %.lr.ph.peel.next

.lr.ph.peel.next:                                 ; preds = %.lr.ph.preheader
  %14 = shl i64 %11, 4
  %15 = sext i8 %13 to i64
  %16 = add nsw i64 %15, -48
  %17 = or i64 %14, %16
  store i64 %17, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %4, i64 2
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %.not.peel18 = icmp eq i8 %19, 0
  br i1 %.not.peel18, label %._crit_edge, label %.lr.ph.peel.next16

.lr.ph.peel.next16:                               ; preds = %.lr.ph.peel.next
  %20 = shl i64 %17, 4
  %21 = sext i8 %19 to i64
  %22 = add nsw i64 %21, -48
  %23 = or i64 %20, %22
  store i64 %23, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %4, i64 3
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %.not.peel21 = icmp eq i8 %25, 0
  br i1 %.not.peel21, label %._crit_edge, label %.lr.ph.peel.next19

.lr.ph.peel.next19:                               ; preds = %.lr.ph.peel.next16
  %26 = shl i64 %23, 4
  %27 = sext i8 %25 to i64
  %28 = add nsw i64 %27, -48
  %29 = or i64 %26, %28
  store i64 %29, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %4, i64 4
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %.not.peel24 = icmp eq i8 %31, 0
  br i1 %.not.peel24, label %._crit_edge, label %.lr.ph.peel.next22

.lr.ph.peel.next22:                               ; preds = %.lr.ph.peel.next19
  %32 = shl i64 %29, 4
  %33 = sext i8 %31 to i64
  %34 = add nsw i64 %33, -48
  %35 = or i64 %32, %34
  store i64 %35, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %4, i64 5
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %.not.peel27 = icmp eq i8 %37, 0
  br i1 %.not.peel27, label %._crit_edge, label %.lr.ph.peel.next25

.lr.ph.peel.next25:                               ; preds = %.lr.ph.peel.next22
  %38 = shl i64 %35, 4
  %39 = sext i8 %37 to i64
  %40 = add nsw i64 %39, -48
  %41 = or i64 %38, %40
  store i64 %41, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %4, i64 6
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %.not.peel30 = icmp eq i8 %43, 0
  br i1 %.not.peel30, label %._crit_edge, label %.lr.ph.peel.next28

.lr.ph.peel.next28:                               ; preds = %.lr.ph.peel.next25
  %44 = shl i64 %41, 4
  %45 = sext i8 %43 to i64
  %46 = add nsw i64 %45, -48
  %47 = or i64 %44, %46
  store i64 %47, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %4, i64 7
  %49 = load i8, ptr %48, align 1, !tbaa !9
  %.not.peel33 = icmp eq i8 %49, 0
  br i1 %.not.peel33, label %._crit_edge, label %.lr.ph.peel.next31

.lr.ph.peel.next31:                               ; preds = %.lr.ph.peel.next28
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.peel.next31, %.lr.ph
  %50 = phi i64 [ %55, %.lr.ph ], [ %.pre, %.lr.ph.peel.next31 ]
  %51 = phi i8 [ %57, %.lr.ph ], [ %49, %.lr.ph.peel.next31 ]
  %.015 = phi ptr [ %56, %.lr.ph ], [ %48, %.lr.ph.peel.next31 ]
  %52 = shl i64 %50, 4
  %53 = sext i8 %51 to i64
  %54 = add nsw i64 %53, -48
  %55 = or i64 %52, %54
  %56 = getelementptr inbounds i8, ptr %.015, i64 1
  %57 = load i8, ptr %56, align 1, !tbaa !9
  %.not = icmp eq i8 %57, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !10

._crit_edge.loopexit:                             ; preds = %.lr.ph
  store i64 %55, ptr %1, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph.preheader, %.lr.ph.peel.next, %.lr.ph.peel.next16, %.lr.ph.peel.next19, %.lr.ph.peel.next22, %.lr.ph.peel.next25, %.lr.ph.peel.next28, %3
  call void @llvm.lifetime.end.p0(i64 15, ptr nonnull %4) #3
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

attributes #0 = { nofree 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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11, !12}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.peeled.count", i32 7}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass