; LLVM IR from int32bit/leetcode :: algorithms/HouseRobber (src)

; 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: nounwind uwtable
declare dso_local i32 @max(i32 noundef, i32 noundef) #0

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

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %13, i64 0
  %15 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %15, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %73

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %17, i64 0
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  store i32 %19, ptr %20, align 4, !tbaa !9
  %21 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds i32, ptr %23, i64 1
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = call i32 @max(i32 noundef %22, i32 noundef %25)
  %27 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 1
  store i32 %26, ptr %27, align 4, !tbaa !9
  %28 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 1
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = call i32 @max(i32 noundef %29, i32 noundef %31)
  store i32 %32, ptr %8, align 4, !tbaa !9
  store i32 2, ptr %7, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %68, %16
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %71

37:                                               ; preds = %33
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sub nsw i32 %38, 2
  %40 = srem i32 %39, 2
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = add nsw i32 %43, %48
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = srem i32 %51, 2
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = call i32 @max(i32 noundef %49, i32 noundef %55)
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = srem i32 %57, 2
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 %59
  store i32 %56, ptr %60, align 4, !tbaa !9
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = srem i32 %62, 2
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = call i32 @max(i32 noundef %61, i32 noundef %66)
  store i32 %67, ptr %8, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %37
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %7, align 4, !tbaa !9
  br label %33, !llvm.loop !11

71:                                               ; preds = %33
  %72 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %72, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %73

73:                                               ; preds = %71, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

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

; 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 = { 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 = distinct !{!11, !12}
!12 = !{!"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: nounwind uwtable
declare dso_local i32 @max(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rob(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [2 x i32], align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %4 = icmp eq i32 %1, 1
  %5 = load i32, ptr %0, align 4, !tbaa !5
  br i1 %4, label %.loopexit, label %6

6:                                                ; preds = %2
  store i32 %5, ptr %3, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call i32 @max(i32 noundef %5, i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %9, ptr %10, align 4, !tbaa !5
  %11 = tail call i32 @max(i32 noundef %5, i32 noundef %9)
  %12 = icmp sgt i32 %1, 2
  br i1 %12, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.019 = phi i32 [ %11, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %.urem20 = and i64 %indvars.iv, 1
  %13 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 %.urem20
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, %14
  %18 = and i64 %indvars.iv, 1
  %.urem = xor i64 %18, 1
  %19 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 %.urem
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = tail call i32 @max(i32 noundef %17, i32 noundef %20)
  %22 = and i64 %indvars.iv, 1
  %23 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 %22
  store i32 %21, ptr %23, align 4, !tbaa !5
  %24 = tail call i32 @max(i32 noundef %.019, i32 noundef %21)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %2, %6
  %.016 = phi i32 [ %11, %6 ], [ %5, %2 ], [ %24, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret i32 %.016
}

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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