; LLVM IR from ahr9n/psolving-paradigms :: 4.dynamic-programming/09.grids-and-paths/SPOJ BYTESM2 - Philosophers Stone.ll (Z3solii)

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

%"class.std::initializer_list" = type { ptr, i64 }

@r = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@arr = external dso_local global [101 x [101 x i32]], align 16
@dp = external dso_local global [101 x [101 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3solii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %"class.std::initializer_list", align 8
  %9 = alloca [3 x i32], align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr @r, align 4, !tbaa !5
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %20, label %13

13:                                               ; preds = %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr @c, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %20, label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %13, %2
  store i32 0, ptr %3, align 4
  br label %82

21:                                               ; preds = %17
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr @r, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = icmp eq i32 %22, %24
  br i1 %25, label %26, label %34

26:                                               ; preds = %21
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [101 x [101 x i32]], ptr @arr, i64 0, i64 %28
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [101 x i32], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %3, align 4
  br label %82

34:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [101 x [101 x i32]], ptr @dp, i64 0, i64 %36
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [101 x i32], ptr %37, i64 0, i64 %39
  store ptr %40, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = xor i32 %42, -1
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %34
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = load i32, ptr %46, align 4, !tbaa !5
  store i32 %47, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %81

48:                                               ; preds = %34
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [101 x [101 x i32]], ptr @arr, i64 0, i64 %50
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [101 x i32], ptr %51, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %9) #3
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = call noundef i32 @_Z3solii(i32 noundef %57, i32 noundef %58)
  store i32 %59, ptr %9, align 4, !tbaa !5
  %60 = getelementptr inbounds i32, ptr %9, i64 1
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = call noundef i32 @_Z3solii(i32 noundef %62, i32 noundef %64)
  store i32 %65, ptr %60, align 4, !tbaa !5
  %66 = getelementptr inbounds i32, ptr %9, i64 2
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = sub nsw i32 %69, 1
  %71 = call noundef i32 @_Z3solii(i32 noundef %68, i32 noundef %70)
  store i32 %71, ptr %66, align 4, !tbaa !5
  %72 = getelementptr inbounds %"class.std::initializer_list", ptr %8, i32 0, i32 0
  store ptr %9, ptr %72, align 8, !tbaa !11
  %73 = getelementptr inbounds %"class.std::initializer_list", ptr %8, i32 0, i32 1
  store i64 3, ptr %73, align 8, !tbaa !14
  %74 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8
  %76 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 1
  %77 = load i64, ptr %76, align 8
  %78 = call noundef i32 @_ZSt3maxIiET_St16initializer_listIS0_E(ptr %75, i64 %77)
  %79 = add nsw i32 %55, %78
  %80 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %79, ptr %80, align 4, !tbaa !5
  store i32 %79, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #3
  store i32 1, ptr %7, align 4
  br label %81

81:                                               ; preds = %48, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %82

82:                                               ; preds = %81, %26, %20
  %83 = load i32, ptr %3, align 4
  ret i32 %83
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZSt3maxIiET_St16initializer_listIS0_E(ptr, i64) #2

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSSt16initializer_listIiE", !10, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}


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

@r = external dso_local local_unnamed_addr global i32, align 4
@c = external dso_local local_unnamed_addr global i32, align 4
@arr = external dso_local local_unnamed_addr global [101 x [101 x i32]], align 16
@dp = external dso_local local_unnamed_addr global [101 x [101 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3solii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [3 x i32], align 4
  %4 = load i32, ptr @r, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %common.ret23, label %6

6:                                                ; preds = %2
  %7 = load i32, ptr @c, align 4, !tbaa !5
  %8 = icmp eq i32 %7, %1
  %9 = icmp slt i32 %1, 0
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %common.ret23, label %10

10:                                               ; preds = %6
  %11 = add nsw i32 %4, -1
  %12 = icmp eq i32 %11, %0
  %13 = sext i32 %0 to i64
  %14 = zext nneg i32 %1 to i64
  br i1 %12, label %15, label %18

15:                                               ; preds = %10
  %16 = getelementptr inbounds [101 x [101 x i32]], ptr @arr, i64 0, i64 %13, i64 %14
  %17 = load i32, ptr %16, align 4, !tbaa !5
  br label %common.ret23

18:                                               ; preds = %10
  %19 = getelementptr inbounds [101 x [101 x i32]], ptr @dp, i64 0, i64 %13, i64 %14
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not = icmp eq i32 %20, -1
  br i1 %.not, label %21, label %common.ret23

common.ret23:                                     ; preds = %18, %2, %6, %15, %21
  %common.ret23.op = phi i32 [ %33, %21 ], [ %17, %15 ], [ 0, %6 ], [ 0, %2 ], [ %20, %18 ]
  ret i32 %common.ret23.op

21:                                               ; preds = %18
  %22 = getelementptr inbounds [101 x [101 x i32]], ptr @arr, i64 0, i64 %13, i64 %14
  %23 = load i32, ptr %22, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #3
  %24 = add nsw i32 %0, 1
  %25 = tail call noundef i32 @_Z3solii(i32 noundef %24, i32 noundef %1)
  store i32 %25, ptr %3, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %3, i64 4
  %27 = add nuw nsw i32 %1, 1
  %28 = tail call noundef i32 @_Z3solii(i32 noundef %24, i32 noundef %27)
  store i32 %28, ptr %26, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %3, i64 8
  %30 = add nsw i32 %1, -1
  %31 = tail call noundef i32 @_Z3solii(i32 noundef %24, i32 noundef %30)
  store i32 %31, ptr %29, align 4, !tbaa !5
  %32 = call noundef i32 @_ZSt3maxIiET_St16initializer_listIS0_E(ptr nonnull %3, i64 3)
  %33 = add nsw i32 %32, %23
  store i32 %33, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #3
  br label %common.ret23
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZSt3maxIiET_St16initializer_listIS0_E(ptr, i64) 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 = { mustprogress 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 = { inlinehint mustprogress 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 #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++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass