; LLVM IR from ekoontz/graphlab :: src/graphlab/extern/metis/GKlib (io)

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

@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1

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

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

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

14:                                               ; preds = %3
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %74

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %23, label %19

19:                                               ; preds = %15
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %30

23:                                               ; preds = %19, %15
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 1024, ptr %24, align 8, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = mul i64 %26, 1
  %28 = call ptr @gk_malloc(i64 noundef %27, ptr noundef @.str.2)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %28, ptr %29, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %23, %19
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %64, %30
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = call i32 @getc(ptr noundef %32)
  store i32 %33, ptr %9, align 4, !tbaa !11
  %34 = icmp ne i32 %33, -1
  br i1 %34, label %35, label %67

35:                                               ; preds = %31
  %36 = load i32, ptr %9, align 4, !tbaa !11
  %37 = trunc i32 %36 to i8
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  store i8 %37, ptr %41, align 1, !tbaa !13
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = add i64 %42, 2
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = icmp eq i64 %43, %45
  br i1 %46, label %47, label %59

47:                                               ; preds = %35
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = mul i64 2, %49
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %50, ptr %51, align 8, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = mul i64 %55, 1
  %57 = call ptr @gk_realloc(ptr noundef %53, i64 noundef %56, ptr noundef @.str.2)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %57, ptr %58, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %47, %35
  %60 = load i32, ptr %9, align 4, !tbaa !11
  %61 = icmp eq i32 %60, 10
  br i1 %61, label %62, label %63

62:                                               ; preds = %59
  br label %67

63:                                               ; preds = %59
  br label %64

64:                                               ; preds = %63
  %65 = load i64, ptr %8, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %8, align 8, !tbaa !9
  br label %31, !llvm.loop !14

67:                                               ; preds = %62, %31
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = add i64 %70, 1
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  store i8 0, ptr %72, align 1, !tbaa !13
  %73 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %73, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %74

74:                                               ; preds = %67, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %75 = load i64, ptr %4, align 8
  ret i64 %75
}

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #2

declare ptr @gk_malloc(i64 noundef, ptr noundef) #3

declare i32 @getc(ptr noundef) #3

declare ptr @gk_realloc(ptr noundef, i64 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @gk_getline(ptr nocapture noundef %0, ptr nocapture noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @feof(ptr noundef %2) #3
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %34

5:                                                ; preds = %3
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %11, label %8

8:                                                ; preds = %5
  %9 = load i64, ptr %1, align 8, !tbaa !9
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %8, %5
  store i64 1024, ptr %1, align 8, !tbaa !9
  %12 = tail call ptr @gk_malloc(i64 noundef 1024, ptr noundef nonnull @.str.2) #3
  store ptr %12, ptr %0, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11, %8
  %14 = tail call i32 @getc(ptr noundef %2)
  %.not2526 = icmp eq i32 %14, -1
  br i1 %.not2526, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %28
  %15 = phi i32 [ %30, %28 ], [ %14, %13 ]
  %.02227 = phi i64 [ %29, %28 ], [ 0, %13 ]
  %16 = trunc i32 %15 to i8
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 %.02227
  store i8 %16, ptr %18, align 1, !tbaa !11
  %19 = add i64 %.02227, 2
  %20 = load i64, ptr %1, align 8, !tbaa !9
  %21 = icmp eq i64 %19, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %.lr.ph
  %23 = shl i64 %19, 1
  store i64 %23, ptr %1, align 8, !tbaa !9
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %25 = tail call ptr @gk_realloc(ptr noundef %24, i64 noundef %23, ptr noundef nonnull @.str.2) #3
  store ptr %25, ptr %0, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %22, %.lr.ph
  %27 = icmp eq i32 %15, 10
  br i1 %27, label %._crit_edge, label %28

28:                                               ; preds = %26
  %29 = add i64 %.02227, 1
  %30 = tail call i32 @getc(ptr noundef %2)
  %.not25 = icmp eq i32 %30, -1
  br i1 %.not25, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %28, %26, %13
  %.022.lcssa = phi i64 [ 0, %13 ], [ %.02227, %26 ], [ %29, %28 ]
  %31 = load ptr, ptr %0, align 8, !tbaa !5
  %32 = getelementptr i8, ptr %31, i64 %.022.lcssa
  %33 = getelementptr i8, ptr %32, i64 1
  store i8 0, ptr %33, align 1, !tbaa !11
  br label %34

34:                                               ; preds = %3, %._crit_edge
  %.0 = phi i64 [ %.022.lcssa, %._crit_edge ], [ -1, %3 ]
  ret i64 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @feof(ptr nocapture noundef) local_unnamed_addr #1

declare ptr @gk_malloc(i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @getc(ptr nocapture noundef) local_unnamed_addr #1

declare ptr @gk_realloc(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

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 = { 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 #2 = { "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 = !{!"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}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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