; LLVM IR from tum-i4/obfuscation-benchmarks :: basic-algorithms (binarymult)

; 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 [36 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 3
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  br label %58

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 1, ptr %10, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !13
  %20 = sext i8 %19 to i64
  store i64 %20, ptr %6, align 8, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds ptr, ptr %21, i64 2
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %23, i64 0
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = sext i8 %25 to i64
  store i64 %26, ptr %7, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %52, %14
  %28 = load i64, ptr %7, align 8, !tbaa !11
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %55

30:                                               ; preds = %27
  %31 = load i64, ptr %7, align 8, !tbaa !11
  %32 = srem i64 %31, 10
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %47

36:                                               ; preds = %30
  %37 = load i64, ptr %6, align 8, !tbaa !11
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %37, %39
  store i64 %40, ptr %6, align 8, !tbaa !11
  %41 = load i64, ptr %6, align 8, !tbaa !11
  %42 = trunc i64 %41 to i32
  %43 = load i64, ptr %8, align 8, !tbaa !11
  %44 = trunc i64 %43 to i32
  %45 = call i32 @binaryAddition(i32 noundef %42, i32 noundef %44)
  %46 = sext i32 %45 to i64
  store i64 %46, ptr %8, align 8, !tbaa !11
  br label %52

47:                                               ; preds = %30
  %48 = load i64, ptr %6, align 8, !tbaa !11
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 %48, %50
  store i64 %51, ptr %6, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %47, %36
  %53 = load i64, ptr %7, align 8, !tbaa !11
  %54 = sdiv i64 %53, 10
  store i64 %54, ptr %7, align 8, !tbaa !11
  store i32 10, ptr %10, align 4, !tbaa !5
  br label %27, !llvm.loop !14

55:                                               ; preds = %27
  %56 = load i64, ptr %8, align 8, !tbaa !11
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %56)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, 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 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %58

58:                                               ; preds = %55, %13
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @binaryAddition(i32 noundef, i32 noundef) #0

declare i32 @printf(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 = { "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 = !{!"int", !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 = !{!"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"

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 3
  br i1 %3, label %28, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = sext i8 %7 to i32
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i64
  %.not19 = icmp eq i8 %11, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %13 = srem i8 %11, 10
  %14 = icmp eq i8 %13, 1
  br i1 %14, label %15, label %18

15:                                               ; preds = %.lr.ph.preheader
  %16 = tail call i32 @binaryAddition(i32 noundef %8, i32 noundef 0)
  %17 = sext i32 %16 to i64
  br label %18

18:                                               ; preds = %.lr.ph.preheader, %15
  %.1.peel = phi i64 [ %17, %15 ], [ 0, %.lr.ph.preheader ]
  %.01621.off.peel = add nsw i64 %12, 9
  %.not.peel = icmp ult i64 %.01621.off.peel, 19
  br i1 %.not.peel, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %18, %26
  %.01522 = phi i64 [ %.1, %26 ], [ %.1.peel, %18 ]
  %.01621.in = phi i64 [ %.01621, %26 ], [ %12, %18 ]
  %.01720 = phi i32 [ %21, %26 ], [ %8, %18 ]
  %.01621 = sdiv i64 %.01621.in, 10
  %19 = srem i64 %.01621, 10
  %20 = icmp eq i64 %19, 1
  %21 = mul i32 %.01720, 10
  br i1 %20, label %22, label %26

22:                                               ; preds = %.lr.ph
  %23 = trunc nsw i64 %.01522 to i32
  %24 = tail call i32 @binaryAddition(i32 noundef %21, i32 noundef %23)
  %25 = sext i32 %24 to i64
  br label %26

26:                                               ; preds = %.lr.ph, %22
  %.1 = phi i64 [ %25, %22 ], [ %.01522, %.lr.ph ]
  %.01621.off = add nsw i64 %.01621, 9
  %.not = icmp ult i64 %.01621.off, 19
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %26, %18, %4
  %.015.lcssa = phi i64 [ 0, %4 ], [ %.1.peel, %18 ], [ %.1, %26 ]
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.015.lcssa)
  br label %28

28:                                               ; preds = %2, %._crit_edge
  %.014 = phi i32 [ 0, %._crit_edge ], [ 1, %2 ]
  ret i32 %.014
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @binaryAddition(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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" }

!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, !12}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.peeled.count", i32 1}


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