; LLVM IR from Montimage/mmt-security :: src/lib (config)

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

@spin_lock = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [50 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 zeroext i1 @mmt_sec_load_default_config() #1 {
  %1 = alloca i1, align 1
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 6, ptr %5, align 4, !tbaa !11
  %8 = call i32 @pthread_spin_init(ptr noundef @spin_lock, i32 noundef 0) #4
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %0
  call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 4, ptr noundef @.str)
  br label %11

11:                                               ; preds = %10, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = call noalias ptr @fopen(ptr noundef @.str.1, ptr noundef @.str.2)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %11
  %16 = call noalias ptr @fopen(ptr noundef @.str.3, ptr noundef @.str.2)
  store ptr %16, ptr %6, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %15, %11
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i1 false, ptr %1, align 1
  store i32 1, ptr %7, align 4
  br label %52

21:                                               ; preds = %17
  br label %22

22:                                               ; preds = %47, %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call i64 @getline(ptr noundef %2, ptr noundef %3, ptr noundef %23)
  %25 = icmp ne i64 %24, -1
  br i1 %25, label %26, label %48

26:                                               ; preds = %22
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %38, %26
  %28 = load i32, ptr %4, align 4, !tbaa !11
  %29 = load i32, ptr %5, align 4, !tbaa !11
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %41

31:                                               ; preds = %27
  %32 = load i32, ptr %4, align 4, !tbaa !11
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = call i32 @_check_then_set_value(i32 noundef %32, ptr noundef %33)
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  br label %41

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %4, align 4, !tbaa !11
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !11
  br label %27, !llvm.loop !13

41:                                               ; preds = %36, %27
  %42 = load i32, ptr %4, align 4, !tbaa !11
  %43 = load i32, ptr %5, align 4, !tbaa !11
  %44 = icmp eq i32 %42, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %41
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 2, ptr noundef @.str.4, ptr noundef %46)
  br label %47

47:                                               ; preds = %45, %41
  br label %22, !llvm.loop !15

48:                                               ; preds = %22
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call i32 @fclose(ptr noundef %49)
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %51) #4
  store i1 true, ptr %1, align 1
  store i32 1, ptr %7, align 4
  br label %52

52:                                               ; preds = %48, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %53 = load i1, ptr %1, align 1
  ret i1 %53
}

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @_check_then_set_value(i32 noundef, ptr noundef) #1

declare i32 @fclose(ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@spin_lock = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [50 x i8], align 1

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

; Function Attrs: mustprogress 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 noundef zeroext i1 @mmt_sec_load_default_config() local_unnamed_addr #1 {
  %1 = alloca ptr, align 8
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store i64 0, ptr %2, align 8, !tbaa !9
  %3 = tail call i32 @pthread_spin_init(ptr noundef nonnull @spin_lock, i32 noundef 0) #6
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %5, label %4

4:                                                ; preds = %0
  tail call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 4, ptr noundef nonnull @.str) #6
  br label %5

5:                                                ; preds = %4, %0
  %6 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %.preheader14

8:                                                ; preds = %5
  %9 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2)
  %.not21 = icmp eq ptr %9, null
  br i1 %.not21, label %39, label %.preheader14

.preheader14:                                     ; preds = %5, %8
  %.020 = phi ptr [ %9, %8 ], [ %6, %5 ]
  %10 = call i64 @getline(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %.020) #6
  %.not1317 = icmp eq i64 %10, -1
  br i1 %.not1317, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %.preheader14, %.thread
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = call i32 @_check_then_set_value(i32 noundef 0, ptr noundef %11)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %.thread, label %14

14:                                               ; preds = %.preheader
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = call i32 @_check_then_set_value(i32 noundef 1, ptr noundef %15)
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.thread, label %18

18:                                               ; preds = %14
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  %20 = call i32 @_check_then_set_value(i32 noundef 2, ptr noundef %19)
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %.thread, label %22

22:                                               ; preds = %18
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = call i32 @_check_then_set_value(i32 noundef 3, ptr noundef %23)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %.thread, label %26

26:                                               ; preds = %22
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = call i32 @_check_then_set_value(i32 noundef 4, ptr noundef %27)
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %.thread, label %30

30:                                               ; preds = %26
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = call i32 @_check_then_set_value(i32 noundef 5, ptr noundef %31)
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %.thread, label %34

34:                                               ; preds = %30
  %35 = load ptr, ptr %1, align 8, !tbaa !5
  call void (i32, ptr, ...) @mmt_sec_log(i32 noundef 2, ptr noundef nonnull @.str.4, ptr noundef %35) #6
  br label %.thread

.thread:                                          ; preds = %.preheader, %14, %18, %22, %26, %30, %34
  %36 = call i64 @getline(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %.020) #6
  %.not13 = icmp eq i64 %36, -1
  br i1 %.not13, label %._crit_edge, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %.thread, %.preheader14
  %37 = call i32 @fclose(ptr noundef nonnull %.020)
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  call void @free(ptr noundef %38) #6
  br label %39

39:                                               ; preds = %8, %._crit_edge
  %40 = phi i1 [ false, %8 ], [ true, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  ret i1 %40
}

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

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

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

declare i64 @getline(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @_check_then_set_value(i32 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

attributes #0 = { mustprogress 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 = { 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 #5 = { 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 #6 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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