; LLVM IR from stivalaa/EstimNetDirected :: src (estimconfigparser)

; 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.config_param_s = type { ptr, i32, i64, ptr }
%struct.estim_config_s = type { double, double, double, i32, i32, i32, i32, i32, i32, i32, double, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, double, double, i32, ptr, i32, ptr, i32, i32, i32, i32, %struct.param_config_s }
%struct.param_config_s = type { i32, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr }

@ESTIM_CONFIG_PARAMS = external dso_local constant [38 x %struct.config_param_s], align 16
@ESTIM_CONFIG = external dso_local global %struct.estim_config_s, align 8
@TOKSIZE = external constant i64, align 8
@.str.76 = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external global ptr, align 8
@.str.77 = external hidden unnamed_addr constant [50 x i8], align 1
@ESTIM_CONFIG_IS_SET = external hidden global [38 x i32], align 16
@.str.78 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @parse_estim_config_file(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr @TOKSIZE, align 8, !tbaa !9
  %11 = call ptr @llvm.stacksave.p0()
  store ptr %11, ptr %4, align 8
  %12 = alloca i8, i64 %10, align 16
  store i64 %10, ptr %5, align 8
  %13 = load i64, ptr @TOKSIZE, align 8, !tbaa !9
  %14 = alloca i8, i64 %13, align 16
  store i64 %13, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call noalias ptr @fopen(ptr noundef %15, ptr noundef @.str.76)
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %25, label %18

18:                                               ; preds = %1
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call ptr @__errno_location() #7
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = call ptr @strerror(i32 noundef %22) #6
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.77, ptr noundef %20, ptr noundef %23) #6
  store ptr null, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %67

25:                                               ; preds = %1
  br label %26

26:                                               ; preds = %52, %25
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i32 @feof(ptr noundef %27) #6
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %35, label %30

30:                                               ; preds = %26
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call i32 @ferror(ptr noundef %31) #6
  %33 = icmp ne i32 %32, 0
  %34 = xor i1 %33, true
  br label %35

35:                                               ; preds = %30, %26
  %36 = phi i1 [ false, %26 ], [ %34, %30 ]
  br i1 %36, label %37, label %53

37:                                               ; preds = %35
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = call i32 @get_paramname_value(ptr noundef %38, ptr noundef %12, ptr noundef %14)
  store i32 %39, ptr %8, align 4, !tbaa !11
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %37
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call i32 @check_and_set_param_value(ptr noundef %12, ptr noundef %14, ptr noundef %42, ptr noundef @ESTIM_CONFIG, ptr noundef @ESTIM_CONFIG_IS_SET, ptr noundef getelementptr inbounds (%struct.estim_config_s, ptr @ESTIM_CONFIG, i32 0, i32 34), ptr noundef @ESTIM_CONFIG_PARAMS, i32 noundef 38, i32 noundef 0)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store ptr null, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %67

46:                                               ; preds = %41
  br label %52

47:                                               ; preds = %37
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  store ptr null, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %67

51:                                               ; preds = %47
  br label %52

52:                                               ; preds = %51, %46
  br label %26, !llvm.loop !13

53:                                               ; preds = %35
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = call i32 @ferror(ptr noundef %54) #6
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %64

57:                                               ; preds = %53
  %58 = load ptr, ptr @stderr, align 8, !tbaa !5
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = call ptr @__errno_location() #7
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = call ptr @strerror(i32 noundef %61) #6
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef @.str.78, ptr noundef %59, ptr noundef %62) #6
  store ptr null, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %67

64:                                               ; preds = %53
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i32 @fclose(ptr noundef %65)
  store ptr @ESTIM_CONFIG, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %67

67:                                               ; preds = %64, %57, %50, %45, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  %68 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %68)
  %69 = load ptr, ptr %2, align 8
  ret ptr %69
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

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

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #4

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #5

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

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #4

declare i32 @get_paramname_value(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @check_and_set_param_value(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #3

declare i32 @fclose(ptr noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 willreturn memory(none) "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 willreturn memory(none) }

!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 = distinct !{!13, !14}
!14 = !{!"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"

%struct.config_param_s = type { ptr, i32, i64, ptr }
%struct.estim_config_s = type { double, double, double, i32, i32, i32, i32, i32, i32, i32, double, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, double, double, i32, ptr, i32, ptr, i32, i32, i32, i32, %struct.param_config_s }
%struct.param_config_s = type { i32, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr }

@ESTIM_CONFIG_PARAMS = external dso_local constant [38 x %struct.config_param_s], align 16
@ESTIM_CONFIG = external dso_local global %struct.estim_config_s, align 8
@TOKSIZE = external local_unnamed_addr constant i64, align 8
@.str.76 = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.77 = external hidden unnamed_addr constant [50 x i8], align 1
@ESTIM_CONFIG_IS_SET = external hidden global [38 x i32], align 16
@.str.78 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @parse_estim_config_file(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @TOKSIZE, align 8, !tbaa !5
  %3 = alloca i8, i64 %2, align 16
  %4 = alloca i8, i64 %2, align 16
  %5 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str.76)
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %7, label %.preheader

.preheader:                                       ; preds = %1
  %6 = tail call i32 @feof(ptr noundef nonnull %5) #6
  %.not1216 = icmp eq i32 %6, 0
  br i1 %.not1216, label %.lr.ph, label %.critedge

7:                                                ; preds = %1
  %8 = load ptr, ptr @stderr, align 8, !tbaa !9
  %9 = tail call ptr @__errno_location() #7
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = tail call ptr @strerror(i32 noundef %10) #6
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.77, ptr noundef %0, ptr noundef %11) #8
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %21
  %13 = call i32 @ferror(ptr noundef nonnull %5) #6
  %.not13 = icmp eq i32 %13, 0
  br i1 %.not13, label %14, label %.critedge

14:                                               ; preds = %.lr.ph
  %15 = call i32 @get_paramname_value(ptr noundef nonnull %5, ptr noundef nonnull %3, ptr noundef nonnull %4) #6
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = call i32 @check_and_set_param_value(ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull @ESTIM_CONFIG, ptr noundef nonnull @ESTIM_CONFIG_IS_SET, ptr noundef nonnull getelementptr inbounds (i8, ptr @ESTIM_CONFIG, i64 224), ptr noundef nonnull @ESTIM_CONFIG_PARAMS, i32 noundef 38, i32 noundef 0) #6
  %.not14 = icmp eq i32 %18, 0
  br i1 %.not14, label %21, label %.loopexit

19:                                               ; preds = %14
  %20 = icmp slt i32 %15, 0
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %19, %17
  %22 = call i32 @feof(ptr noundef nonnull %5) #6
  %.not12 = icmp eq i32 %22, 0
  br i1 %.not12, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %21, %.preheader
  %23 = call i32 @ferror(ptr noundef nonnull %5) #6
  %.not15 = icmp eq i32 %23, 0
  br i1 %.not15, label %30, label %24

24:                                               ; preds = %.critedge
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = tail call ptr @__errno_location() #7
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = call ptr @strerror(i32 noundef %27) #6
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.78, ptr noundef %0, ptr noundef %28) #8
  br label %.loopexit

30:                                               ; preds = %.critedge
  %31 = call i32 @fclose(ptr noundef nonnull %5)
  br label %.loopexit

.loopexit:                                        ; preds = %19, %17, %30, %24, %7
  %.0 = phi ptr [ null, %24 ], [ @ESTIM_CONFIG, %30 ], [ null, %7 ], [ null, %17 ], [ null, %19 ]
  ret ptr %.0
}

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

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

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

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

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #4

declare i32 @get_paramname_value(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

declare i32 @check_and_set_param_value(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr 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 = { 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 = { 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nofree nounwind memory(read) "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 = { "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 willreturn memory(none) }
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 = !{!"long", !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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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