; LLVM IR from hpcg-benchmark/hpcg :: src/ReadHpcgDat.ll (Z11ReadHpcgDatPiS_S_)

; 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 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z11ReadHpcgDatPiS_S_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = 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) #3
  %12 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %102

16:                                               ; preds = %3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef %17)
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %46, %16
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 3
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %49

25:                                               ; preds = %21
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %26, ptr noundef @.str.2, ptr noundef %30)
  %32 = icmp ne i32 %31, 1
  br i1 %32, label %40, label %33

33:                                               ; preds = %25
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = icmp slt i32 %38, 16
  br i1 %39, label %40, label %45

40:                                               ; preds = %33, %25
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  store i32 16, ptr %44, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %40, %33
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %10, align 4, !tbaa !9
  br label %21, !llvm.loop !11

49:                                               ; preds = %24
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef %50)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %68

54:                                               ; preds = %49
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %55, ptr noundef @.str.2, ptr noundef %56)
  %58 = icmp ne i32 %57, 1
  br i1 %58, label %64, label %59

59:                                               ; preds = %54
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds i32, ptr %60, i64 0
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = icmp slt i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %59, %54
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds i32, ptr %65, i64 0
  store i32 1800, ptr %66, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %64, %59
  br label %68

68:                                               ; preds = %67, %49
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef %69)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %96, %68
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = icmp slt i32 %72, 3
  br i1 %73, label %75, label %74

74:                                               ; preds = %71
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %99

75:                                               ; preds = %71
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i32, ptr %77, i64 %79
  %81 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %76, ptr noundef @.str.2, ptr noundef %80)
  %82 = icmp ne i32 %81, 1
  br i1 %82, label %90, label %83

83:                                               ; preds = %75
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load i32, ptr %11, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i32, ptr %84, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !9
  %89 = icmp slt i32 %88, 1
  br i1 %89, label %90, label %95

90:                                               ; preds = %83, %75
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load i32, ptr %11, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i32, ptr %91, i64 %93
  store i32 0, ptr %94, align 4, !tbaa !9
  br label %95

95:                                               ; preds = %90, %83
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %11, align 4, !tbaa !9
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %11, align 4, !tbaa !9
  br label %71, !llvm.loop !13

99:                                               ; preds = %74
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = call i32 @fclose(ptr noundef %100)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %102

102:                                              ; preds = %99, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %103 = load i32, ptr %4, align 4
  ret i32 %103
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef) #0

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) #2

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

declare i32 @fclose(ptr noundef) #2

attributes #0 = { mustprogress 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 = { "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1, 1) i32 @_Z11ReadHpcgDatPiS_S_(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %58, label %5

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef nonnull %4)
  %7 = tail call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef nonnull %4)
  %8 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef %0)
  %.not36 = icmp eq i32 %8, 1
  br i1 %.not36, label %9, label %12

9:                                                ; preds = %5
  %10 = load i32, ptr %0, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 16
  br i1 %11, label %12, label %13

12:                                               ; preds = %9, %5
  store i32 16, ptr %0, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %9, %12
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef nonnull %14)
  %.not36.1 = icmp eq i32 %15, 1
  br i1 %.not36.1, label %16, label %19

16:                                               ; preds = %13
  %17 = load i32, ptr %14, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 16
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %13
  store i32 16, ptr %14, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %19, %16
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef nonnull %21)
  %.not36.2 = icmp eq i32 %22, 1
  br i1 %.not36.2, label %23, label %26

23:                                               ; preds = %20
  %24 = load i32, ptr %21, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 16
  br i1 %25, label %26, label %27

26:                                               ; preds = %23, %20
  store i32 16, ptr %21, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %26, %23
  %28 = tail call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef nonnull %4)
  %.not33 = icmp eq ptr %1, null
  br i1 %.not33, label %35, label %29

29:                                               ; preds = %27
  %30 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef nonnull %1)
  %.not34 = icmp eq i32 %30, 1
  br i1 %.not34, label %31, label %34

31:                                               ; preds = %29
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %31, %29
  store i32 1800, ptr %1, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %31, %34, %27
  %36 = tail call noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef nonnull %4)
  %37 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef %2)
  %.not35 = icmp eq i32 %37, 1
  br i1 %.not35, label %38, label %41

38:                                               ; preds = %35
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 1
  br i1 %40, label %41, label %42

41:                                               ; preds = %38, %35
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %38, %41
  %43 = getelementptr inbounds i8, ptr %2, i64 4
  %44 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef nonnull %43)
  %.not35.1 = icmp eq i32 %44, 1
  br i1 %.not35.1, label %45, label %48

45:                                               ; preds = %42
  %46 = load i32, ptr %43, align 4, !tbaa !5
  %47 = icmp slt i32 %46, 1
  br i1 %47, label %48, label %49

48:                                               ; preds = %45, %42
  store i32 0, ptr %43, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %48, %45
  %50 = getelementptr inbounds i8, ptr %2, i64 8
  %51 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef nonnull %50)
  %.not35.2 = icmp eq i32 %51, 1
  br i1 %.not35.2, label %52, label %55

52:                                               ; preds = %49
  %53 = load i32, ptr %50, align 4, !tbaa !5
  %54 = icmp slt i32 %53, 1
  br i1 %54, label %55, label %56

55:                                               ; preds = %52, %49
  store i32 0, ptr %50, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %55, %52
  %57 = tail call i32 @fclose(ptr noundef nonnull %4)
  br label %58

58:                                               ; preds = %3, %56
  %.030 = phi i32 [ 0, %56 ], [ -1, %3 ]
  ret i32 %.030
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL12SkipUntilEolP8_IO_FILE(ptr noundef) local_unnamed_addr #0

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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" }

!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++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass