; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (155)

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

%struct.MinStack = type { ptr, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @minStackPush(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.MinStack, ptr %5, i32 0, i32 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = add nsw i32 %7, 1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MinStack, ptr %9, i32 0, i32 3
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp eq i32 %8, %11
  br i1 %12, label %13, label %31

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MinStack, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = sitofp i32 %16 to double
  %18 = fmul double %17, 1.500000e+00
  %19 = fptosi double %18 to i32
  store i32 %19, ptr %15, align 8, !tbaa !13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MinStack, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MinStack, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = sext i32 %25 to i64
  %27 = mul i64 %26, 4
  %28 = call ptr @realloc(ptr noundef %22, i64 noundef %27) #2
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MinStack, ptr %29, i32 0, i32 0
  store ptr %28, ptr %30, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %13, %2
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.MinStack, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.MinStack, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %37, align 4, !tbaa !11
  %40 = sext i32 %38 to i64
  %41 = getelementptr inbounds i32, ptr %35, i64 %40
  store i32 %32, ptr %41, align 4, !tbaa !9
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MinStack, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %52

46:                                               ; preds = %31
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MinStack, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !16
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = icmp sgt i32 %49, %50
  br i1 %51, label %52, label %58

52:                                               ; preds = %46, %31
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.MinStack, ptr %54, i32 0, i32 1
  store i32 %53, ptr %55, align 8, !tbaa !16
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.MinStack, ptr %56, i32 0, i32 2
  store i32 1, ptr %57, align 4, !tbaa !15
  br label %58

58:                                               ; preds = %52, %46
  ret void
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #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 = { nounwind allocsize(1) "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 allocsize(1) }

!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 = !{!12, !10, i64 20}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, 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"

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @minStackPush(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 20
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %5, %7
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br i1 %8, label %9, label %16

9:                                                ; preds = %2
  %10 = sitofp i32 %5 to double
  %11 = fmul double %10, 1.500000e+00
  %12 = fptosi double %11 to i32
  store i32 %12, ptr %6, align 8, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = shl nsw i64 %13, 2
  %15 = tail call ptr @realloc(ptr noundef %.pre, i64 noundef %14) #2
  store ptr %15, ptr %0, align 8, !tbaa !12
  %.pre14 = load i32, ptr %3, align 4, !tbaa !5
  %.pre15 = add nsw i32 %.pre14, 1
  br label %16

16:                                               ; preds = %9, %2
  %.pre-phi = phi i32 [ %.pre15, %9 ], [ %5, %2 ]
  %17 = phi i32 [ %.pre14, %9 ], [ %4, %2 ]
  %18 = phi ptr [ %15, %9 ], [ %.pre, %2 ]
  store i32 %.pre-phi, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds i32, ptr %18, i64 %19
  store i32 %1, ptr %20, align 4, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %27, label %23

23:                                               ; preds = %16
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = icmp sgt i32 %25, %1
  br i1 %26, label %27, label %29

27:                                               ; preds = %23, %16
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %1, ptr %28, align 8, !tbaa !15
  store i32 1, ptr %21, align 4, !tbaa !14
  br label %29

29:                                               ; preds = %27, %23
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind willreturn 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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(1) }

!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, !10, i64 20}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 12}
!15 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass