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

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

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

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 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, 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 i64
  store i64 %20, ptr %6, align 8, !tbaa !12
  %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 !11
  %26 = sext i8 %25 to i64
  store i64 %26, ptr %7, align 8, !tbaa !12
  br label %27

27:                                               ; preds = %35, %14
  %28 = load i64, ptr %6, align 8, !tbaa !12
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %33, label %30

30:                                               ; preds = %27
  %31 = load i64, ptr %7, align 8, !tbaa !12
  %32 = icmp ne i64 %31, 0
  br label %33

33:                                               ; preds = %30, %27
  %34 = phi i1 [ true, %27 ], [ %32, %30 ]
  br i1 %34, label %35, label %64

35:                                               ; preds = %33
  %36 = load i64, ptr %6, align 8, !tbaa !12
  %37 = srem i64 %36, 10
  %38 = load i64, ptr %7, align 8, !tbaa !12
  %39 = srem i64 %38, 10
  %40 = add nsw i64 %37, %39
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = add nsw i64 %40, %42
  %44 = srem i64 %43, 2
  %45 = trunc i64 %44 to i32
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %8, align 4, !tbaa !5
  %48 = sext i32 %46 to i64
  %49 = getelementptr inbounds [20 x i32], ptr %10, i64 0, i64 %48
  store i32 %45, ptr %49, align 4, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !12
  %51 = srem i64 %50, 10
  %52 = load i64, ptr %7, align 8, !tbaa !12
  %53 = srem i64 %52, 10
  %54 = add nsw i64 %51, %53
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = add nsw i64 %54, %56
  %58 = sdiv i64 %57, 2
  %59 = trunc i64 %58 to i32
  store i32 %59, ptr %9, align 4, !tbaa !5
  %60 = load i64, ptr %6, align 8, !tbaa !12
  %61 = sdiv i64 %60, 10
  store i64 %61, ptr %6, align 8, !tbaa !12
  %62 = load i64, ptr %7, align 8, !tbaa !12
  %63 = sdiv i64 %62, 10
  store i64 %63, ptr %7, align 8, !tbaa !12
  br label %27, !llvm.loop !14

64:                                               ; preds = %33
  %65 = load i32, ptr %9, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %73

67:                                               ; preds = %64
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %8, align 4, !tbaa !5
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds [20 x i32], ptr %10, i64 0, i64 %71
  store i32 %68, ptr %72, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %67, %64
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = add nsw i32 %74, -1
  store i32 %75, ptr %8, align 4, !tbaa !5
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %77

77:                                               ; preds = %80, %73
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = icmp sge i32 %78, 0
  br i1 %79, label %80, label %87

80:                                               ; preds = %77
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = add nsw i32 %81, -1
  store i32 %82, ptr %8, align 4, !tbaa !5
  %83 = sext i32 %81 to i64
  %84 = getelementptr inbounds [20 x i32], ptr %10, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %85)
  br label %77, !llvm.loop !16

87:                                               ; preds = %77
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 80, 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 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %89

89:                                               ; preds = %87, %13
  %90 = load i32, ptr %3, align 4
  ret i32 %90
}

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


; 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 [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; 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 [20 x i32], align 16
  %4 = icmp slt i32 %0, 3
  br i1 %4, label %48, label %5

5:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 80, 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
  %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 = icmp ne i8 %8, 0
  %13 = icmp ne i8 %11, 0
  %14 = select i1 %12, i1 true, i1 %13
  br i1 %14, label %.lr.ph.preheader, label %.thread

.thread:                                          ; preds = %5
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %._crit_edge32

.lr.ph.preheader:                                 ; preds = %5
  %16 = sext i8 %11 to i64
  %17 = sext i8 %8 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.027 = phi i64 [ 0, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %.02125 = phi i64 [ %16, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %.02224 = phi i64 [ %17, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %18 = srem i64 %.02224, 10
  %19 = srem i64 %.02125, 10
  %20 = add nsw i64 %19, %18
  %21 = add nsw i64 %20, %.027
  %22 = srem i64 %21, 2
  %23 = trunc nsw i64 %22 to i32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = getelementptr inbounds [20 x i32], ptr %3, i64 0, i64 %indvars.iv
  store i32 %23, ptr %24, align 4, !tbaa !10
  %25 = sdiv i64 %21, 2
  %26 = sdiv i64 %.02224, 10
  %27 = sdiv i64 %.02125, 10
  %28 = add nsw i64 %.02224, -10
  %29 = icmp ult i64 %28, -19
  %30 = add nsw i64 %.02125, -10
  %31 = icmp ult i64 %30, -19
  %32 = select i1 %29, i1 true, i1 %31
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph
  %33 = trunc nuw i64 %indvars.iv.next to i32
  %.off = add i64 %21, 1
  %.not = icmp ult i64 %.off, 3
  br i1 %.not, label %39, label %34

34:                                               ; preds = %._crit_edge
  %35 = trunc nsw i64 %25 to i32
  %36 = add nuw nsw i32 %33, 1
  %37 = and i64 %indvars.iv.next, 4294967295
  %38 = getelementptr inbounds [20 x i32], ptr %3, i64 0, i64 %37
  store i32 %35, ptr %38, align 4, !tbaa !10
  br label %39

39:                                               ; preds = %34, %._crit_edge
  %.1 = phi i32 [ %36, %34 ], [ %33, %._crit_edge ]
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %41 = icmp sgt i32 %.1, 0
  br i1 %41, label %.lr.ph31.preheader, label %._crit_edge32

.lr.ph31.preheader:                               ; preds = %39
  %42 = zext nneg i32 %.1 to i64
  br label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %.lr.ph31
  %indvars.iv35 = phi i64 [ %42, %.lr.ph31.preheader ], [ %indvars.iv.next36, %.lr.ph31 ]
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, -1
  %43 = getelementptr inbounds [20 x i32], ptr %3, i64 0, i64 %indvars.iv.next36
  %44 = load i32, ptr %43, align 4, !tbaa !10
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %44)
  %46 = icmp ugt i64 %indvars.iv35, 1
  br i1 %46, label %.lr.ph31, label %._crit_edge32, !llvm.loop !14

._crit_edge32:                                    ; preds = %.lr.ph31, %.thread, %39
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #3
  br label %48

48:                                               ; preds = %2, %._crit_edge32
  %.023 = phi i32 [ 0, %._crit_edge32 ], [ 1, %2 ]
  ret i32 %.023
}

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


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