; LLVM IR from xuxping/codelife :: foroffer (question17)

; 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"

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @increment(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = sub nsw i32 %10, 1
  store i32 %11, ptr %7, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %63, %2
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %8, align 4
  br label %66

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = sub nsw i32 %22, 48
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = add nsw i32 %23, %24
  store i32 %25, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  %29 = icmp eq i32 %26, %28
  br i1 %29, label %30, label %33

30:                                               ; preds = %16
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %9, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %30, %16
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp sge i32 %34, 10
  br i1 %35, label %36, label %51

36:                                               ; preds = %33
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %50

40:                                               ; preds = %36
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 10
  store i32 %42, ptr %9, align 4, !tbaa !9
  store i32 1, ptr %6, align 4, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add nsw i32 48, %43
  %45 = trunc i32 %44 to i8
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  store i8 %45, ptr %49, align 1, !tbaa !11
  br label %50

50:                                               ; preds = %40, %39
  br label %59

51:                                               ; preds = %33
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = add nsw i32 48, %52
  %54 = trunc i32 %53 to i8
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  store i8 %54, ptr %58, align 1, !tbaa !11
  store i32 2, ptr %8, align 4
  br label %60

59:                                               ; preds = %50
  store i32 0, ptr %8, align 4
  br label %60

60:                                               ; preds = %59, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %61 = load i32, ptr %8, align 4
  switch i32 %61, label %66 [
    i32 0, label %62
  ]

62:                                               ; preds = %60
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = add nsw i32 %64, -1
  store i32 %65, ptr %7, align 4, !tbaa !9
  br label %12, !llvm.loop !12

66:                                               ; preds = %60, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @increment(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = add nsw i32 %1, -1
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph.peel, label %.loopexit

.lr.ph.peel:                                      ; preds = %2
  %5 = zext nneg i32 %3 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = sext i8 %7 to i32
  %spec.select.peel = add nsw i32 %8, -47
  %9 = icmp sgt i8 %7, 56
  br i1 %9, label %10, label %.loopexit47

10:                                               ; preds = %.lr.ph.peel
  %11 = icmp eq i32 %3, 0
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %10
  %13 = trunc i32 %spec.select.peel to i8
  %14 = add nuw nsw i8 %13, 38
  store i8 %14, ptr %6, align 1, !tbaa !5
  %15 = add nsw i32 %1, -2
  %.not = icmp eq i32 %1, 1
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %25
  %.02033 = phi i32 [ %28, %25 ], [ %15, %12 ]
  %16 = zext nneg i32 %.02033 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = sext i8 %18 to i32
  %spec.select = add nsw i32 %19, -47
  %20 = icmp sgt i8 %18, 56
  br i1 %20, label %21, label %.loopexit47

21:                                               ; preds = %.lr.ph
  %22 = icmp eq i32 %.02033, 0
  br i1 %22, label %.loopexit, label %25

.loopexit47:                                      ; preds = %.lr.ph, %.lr.ph.peel
  %.lcssa = phi ptr [ %6, %.lr.ph.peel ], [ %17, %.lr.ph ]
  %spec.select.lcssa = phi i32 [ %spec.select.peel, %.lr.ph.peel ], [ %spec.select, %.lr.ph ]
  %23 = trunc i32 %spec.select.lcssa to i8
  %24 = add i8 %23, 48
  store i8 %24, ptr %.lcssa, align 1, !tbaa !5
  br label %.loopexit

25:                                               ; preds = %21
  %26 = trunc i32 %spec.select to i8
  %27 = add nuw nsw i8 %26, 38
  store i8 %27, ptr %17, align 1, !tbaa !5
  %28 = add nsw i32 %.02033, -1
  %29 = icmp sgt i32 %.02033, 0
  br i1 %29, label %.lr.ph, label %.loopexit, !llvm.loop !8

.loopexit:                                        ; preds = %10, %12, %21, %25, %2, %.loopexit47
  %.02230 = phi i32 [ 0, %.loopexit47 ], [ 0, %2 ], [ 1, %10 ], [ 0, %12 ], [ 0, %25 ], [ 1, %21 ]
  ret i32 %.02230
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.peeled.count", i32 1}


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