; LLVM IR from wuzhouhui/leetcode :: 77_combination (combine)

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

@col = external hidden global ptr, align 8
@p = external hidden global i32, align 4
@ans = external hidden global ptr, align 8
@res = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @combine(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %19, label %12

12:                                               ; preds = %4
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 1
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp sgt i32 %16, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %15, %12, %4
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr null, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %9, align 8, !tbaa !9
  store i32 0, ptr %21, align 4, !tbaa !5
  store ptr null, ptr %5, align 8
  br label %32

22:                                               ; preds = %15
  %23 = load i32, ptr %7, align 4, !tbaa !5
  call void @do_init(i32 noundef %23)
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  call void @do_comb(i32 noundef %24, i32 noundef %25, i32 noundef 0)
  %26 = load ptr, ptr @col, align 8, !tbaa !9
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %26, ptr %27, align 8, !tbaa !9
  %28 = load i32, ptr @p, align 4, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  store i32 %28, ptr %29, align 4, !tbaa !5
  %30 = load ptr, ptr @ans, align 8, !tbaa !9
  call void @free(ptr noundef %30) #2
  %31 = load ptr, ptr @res, align 8, !tbaa !9
  store ptr %31, ptr %5, align 8
  br label %32

32:                                               ; preds = %22, %19
  %33 = load ptr, ptr %5, align 8
  ret ptr %33
}

; Function Attrs: nounwind uwtable
declare hidden void @do_init(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @do_comb(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind
declare void @free(ptr 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 "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 = !{!"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}


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

@col = external hidden local_unnamed_addr global ptr, align 8
@p = external hidden local_unnamed_addr global i32, align 4
@ans = external hidden local_unnamed_addr global ptr, align 8
@res = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @combine(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %1, 1
  %6 = icmp slt i32 %0, 1
  %or.cond = or i1 %6, %5
  %7 = icmp sgt i32 %1, %0
  %or.cond14 = or i1 %7, %or.cond
  br i1 %or.cond14, label %8, label %9

8:                                                ; preds = %4
  store ptr null, ptr %2, align 8, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %14

9:                                                ; preds = %4
  tail call void @do_init(i32 noundef %1)
  tail call void @do_comb(i32 noundef %0, i32 noundef %1, i32 noundef 0)
  %10 = load ptr, ptr @col, align 8, !tbaa !5
  store ptr %10, ptr %2, align 8, !tbaa !5
  %11 = load i32, ptr @p, align 4, !tbaa !9
  store i32 %11, ptr %3, align 4, !tbaa !9
  %12 = load ptr, ptr @ans, align 8, !tbaa !5
  tail call void @free(ptr noundef %12) #2
  %13 = load ptr, ptr @res, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %9, %8
  %.0 = phi ptr [ null, %8 ], [ %13, %9 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @do_init(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @do_comb(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 nounwind willreturn allockind("free") 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 }

!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}


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