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

; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 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 i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [1000 x ptr], align 16
  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, 2
  br i1 %12, label %13, label %14

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

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8000, ptr %10) #3
  %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 !11
  %20 = sext i8 %19 to i32
  store i32 %20, ptr %6, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %80, %14
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %81

24:                                               ; preds = %21
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = srem i32 %25, 10
  store i32 %26, ptr %9, align 4, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = sdiv i32 %27, 10
  store i32 %28, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !5
  switch i32 %29, label %80 [
    i32 0, label %30
    i32 1, label %35
    i32 2, label %40
    i32 3, label %45
    i32 4, label %50
    i32 5, label %55
    i32 6, label %60
    i32 7, label %65
    i32 8, label %70
    i32 9, label %75
  ]

30:                                               ; preds = %24
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %33
  store ptr @.str, ptr %34, align 8, !tbaa !9
  br label %80

35:                                               ; preds = %24
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !5
  %38 = sext i32 %36 to i64
  %39 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %38
  store ptr @.str.1, ptr %39, align 8, !tbaa !9
  br label %80

40:                                               ; preds = %24
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %43
  store ptr @.str.2, ptr %44, align 8, !tbaa !9
  br label %80

45:                                               ; preds = %24
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %46 to i64
  %49 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %48
  store ptr @.str.3, ptr %49, align 8, !tbaa !9
  br label %80

50:                                               ; preds = %24
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !5
  %53 = sext i32 %51 to i64
  %54 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %53
  store ptr @.str.4, ptr %54, align 8, !tbaa !9
  br label %80

55:                                               ; preds = %24
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %7, align 4, !tbaa !5
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %58
  store ptr @.str.5, ptr %59, align 8, !tbaa !9
  br label %80

60:                                               ; preds = %24
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %63
  store ptr @.str.6, ptr %64, align 8, !tbaa !9
  br label %80

65:                                               ; preds = %24
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !5
  %68 = sext i32 %66 to i64
  %69 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %68
  store ptr @.str.7, ptr %69, align 8, !tbaa !9
  br label %80

70:                                               ; preds = %24
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %7, align 4, !tbaa !5
  %73 = sext i32 %71 to i64
  %74 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %73
  store ptr @.str.8, ptr %74, align 8, !tbaa !9
  br label %80

75:                                               ; preds = %24
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %7, align 4, !tbaa !5
  %78 = sext i32 %76 to i64
  %79 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %78
  store ptr @.str.9, ptr %79, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %75, %70, %65, %60, %55, %50, %45, %40, %35, %30, %24
  br label %21, !llvm.loop !12

81:                                               ; preds = %21
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = sub nsw i32 %82, 1
  store i32 %83, ptr %8, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %93, %81
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = icmp sge i32 %85, 0
  br i1 %86, label %87, label %96

87:                                               ; preds = %84
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1000 x ptr], ptr %10, i64 0, i64 %89
  %91 = load ptr, ptr %90, align 8, !tbaa !9
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, ptr noundef %91)
  br label %93

93:                                               ; preds = %87
  %94 = load i32, ptr %8, align 4, !tbaa !5
  %95 = add nsw i32 %94, -1
  store i32 %95, ptr %8, align 4, !tbaa !5
  br label %84, !llvm.loop !14

96:                                               ; preds = %84
  %97 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8000, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %98

98:                                               ; preds = %96, %13
  %99 = load i32, ptr %3, align 4
  ret i32 %99
}

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

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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1
@switch.table.main = private unnamed_addr constant [10 x ptr] [ptr @.str, ptr @.str.1, ptr @.str.2, ptr @.str.3, ptr @.str.4, ptr @.str.5, ptr @.str.6, ptr @.str.7, ptr @.str.8, ptr @.str.9], align 8

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [1000 x ptr], align 16
  %4 = icmp slt i32 %0, 2
  br i1 %4, label %25, label %5

5:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8000, ptr nonnull %3) #3
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %.not23 = icmp eq i8 %8, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %9 = sext i8 %8 to i32
  br label %.lr.ph

.preheader:                                       ; preds = %19
  %10 = icmp sgt i32 %.1, 0
  br i1 %10, label %.lr.ph27.preheader, label %._crit_edge

.lr.ph27.preheader:                               ; preds = %.preheader
  %11 = zext nneg i32 %.1 to i64
  br label %.lr.ph27

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %.02125 = phi i32 [ %.1, %19 ], [ 0, %.lr.ph.preheader ]
  %.02224 = phi i32 [ %13, %19 ], [ %9, %.lr.ph.preheader ]
  %12 = srem i32 %.02224, 10
  %13 = sdiv i32 %.02224, 10
  %14 = icmp ult i32 %12, 10
  br i1 %14, label %switch.lookup, label %19

switch.lookup:                                    ; preds = %.lr.ph
  %15 = zext nneg i32 %12 to i64
  %switch.gep = getelementptr inbounds [10 x ptr], ptr @switch.table.main, i64 0, i64 %15
  %switch.load = load ptr, ptr %switch.gep, align 8
  %16 = add nsw i32 %.02125, 1
  %17 = sext i32 %.02125 to i64
  %18 = getelementptr inbounds [1000 x ptr], ptr %3, i64 0, i64 %17
  store ptr %switch.load, ptr %18, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %.lr.ph, %switch.lookup
  %.1 = phi i32 [ %.02125, %.lr.ph ], [ %16, %switch.lookup ]
  %.02224.off = add nsw i32 %.02224, 9
  %.not = icmp ult i32 %.02224.off, 19
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !10

.lr.ph27:                                         ; preds = %.lr.ph27.preheader, %.lr.ph27
  %indvars.iv = phi i64 [ %11, %.lr.ph27.preheader ], [ %indvars.iv.next, %.lr.ph27 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %20 = getelementptr inbounds [1000 x ptr], ptr %3, i64 0, i64 %indvars.iv.next
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, ptr noundef %21)
  %23 = icmp ugt i64 %indvars.iv, 1
  br i1 %23, label %.lr.ph27, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph27, %5, %.preheader
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  call void @llvm.lifetime.end.p0(i64 8000, ptr nonnull %3) #3
  br label %25

25:                                               ; preds = %2, %._crit_edge
  %.0 = phi i32 [ 0, %._crit_edge ], [ 1, %2 ]
  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 @printf(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 = !{!"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"}
!12 = distinct !{!12, !11}


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