; LLVM IR from GGiecold-zz/Cluster_Ensembles :: src/Cluster_Ensembles/Hypergraph_Partitioning/metis-5.1.0/GKlib (memory)

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

@gkmcore = external hidden thread_local global ptr, align 8
@stderr = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [59 x i8], align 1

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

12:                                               ; preds = %3
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = add i64 %13, 1
  store i64 %14, ptr %6, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %12, %3
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @gkmcore)
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %26

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %26

22:                                               ; preds = %19
  %23 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @gkmcore)
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  call void @gk_gkmcoreDel(ptr noundef %24, ptr noundef %25)
  br label %26

26:                                               ; preds = %22, %19, %15
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = call ptr @realloc(ptr noundef %27, i64 noundef %28) #7
  store ptr %29, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %41

32:                                               ; preds = %26
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i64 @gk_GetMaxMemoryUsed()
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.5, i64 noundef %34) #6
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = call i64 @gk_GetCurMemoryUsed()
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str.6, i64 noundef %37) #6
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %6, align 8, !tbaa !9
  call void (i32, ptr, ...) @gk_errexit(i32 noundef 6, ptr noundef @.str.7, ptr noundef %39, i64 noundef %40)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %52

41:                                               ; preds = %26
  %42 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @gkmcore)
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %50

45:                                               ; preds = %41
  %46 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @gkmcore)
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  call void @gk_gkmcoreAdd(ptr noundef %47, i32 noundef 3, i64 noundef %48, ptr noundef %49)
  br label %50

50:                                               ; preds = %45, %41
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %51, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %52

52:                                               ; preds = %50, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %53 = load ptr, ptr %4, align 8
  ret ptr %53
}

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare void @gk_errexit(i32 noundef, ptr noundef, ...) #4

declare void @gk_gkmcoreAdd(ptr noundef, i32 noundef, i64 noundef, ptr noundef) #4

declare void @gk_gkmcoreDel(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local i64 @gk_GetCurMemoryUsed() #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @gk_GetMaxMemoryUsed() #0

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"long", !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"

@gkmcore = external hidden thread_local local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @gk_realloc(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %spec.select = tail call i64 @llvm.umax.i64(i64 %1, i64 1)
  %4 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @gkmcore)
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  %7 = icmp ne ptr %0, null
  %or.cond = and i1 %7, %6
  br i1 %or.cond, label %8, label %9

8:                                                ; preds = %3
  tail call void @gk_gkmcoreDel(ptr noundef nonnull %5, ptr noundef nonnull %0) #6
  br label %9

9:                                                ; preds = %8, %3
  %10 = tail call ptr @realloc(ptr noundef %0, i64 noundef %spec.select) #7
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %19

12:                                               ; preds = %9
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i64 @gk_GetMaxMemoryUsed()
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.5, i64 noundef %14) #8
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i64 @gk_GetCurMemoryUsed()
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.6, i64 noundef %17) #8
  tail call void (i32, ptr, ...) @gk_errexit(i32 noundef 6, ptr noundef nonnull @.str.7, ptr noundef %2, i64 noundef %spec.select) #6
  br label %22

19:                                               ; preds = %9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %22, label %21

21:                                               ; preds = %19
  tail call void @gk_gkmcoreAdd(ptr noundef nonnull %20, i32 noundef 3, i64 noundef %spec.select, ptr noundef nonnull %10) #6
  br label %22

22:                                               ; preds = %19, %21, %12
  ret ptr %10
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare void @gk_errexit(i32 noundef, ptr noundef, ...) local_unnamed_addr #3

declare void @gk_gkmcoreAdd(ptr noundef, i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare void @gk_gkmcoreDel(ptr noundef, ptr noundef) local_unnamed_addr #3

; 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 #4

; Function Attrs: nounwind uwtable
declare dso_local i64 @gk_GetCurMemoryUsed() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @gk_GetMaxMemoryUsed() local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #5

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 speculatable willreturn memory(none) }
attributes #2 = { nofree 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 #3 = { "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 #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(1) }
attributes #8 = { cold 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"}


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