; LLVM IR from buk7456/FreeTX :: tests/parser test (parser_test)

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

@isEndOfFile = external dso_local global i8, align 1
@keyBuff = external dso_local global [3 x [21 x i8]], align 16
@valueBuff = external dso_local global [21 x i8], align 16
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 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
declare dso_local void @parser(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca [131072 x i8], align 16
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 2
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = load ptr, ptr @stderr, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str, ptr noundef %17) #5
  store i32 1, ptr %3, align 4
  br label %73

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %20, i64 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call noalias ptr @fopen(ptr noundef %22, ptr noundef @.str.1)
  store ptr %23, ptr %6, align 8, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  call void @perror(ptr noundef @.str.2)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %72

27:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 131072, ptr %8) #5
  %28 = getelementptr inbounds [131072 x i8], ptr %8, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %28, i8 0, i64 131072, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %29 = getelementptr inbounds [131072 x i8], ptr %8, i64 0, i64 0
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = call i64 @fread(ptr noundef %29, i64 noundef 1, i64 noundef 131072, ptr noundef %30)
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %9, align 4, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = call i32 @fclose(ptr noundef %33)
  store i8 0, ptr @isEndOfFile, align 1, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 16 @keyBuff, i8 0, i64 21, i1 false)
  call void @llvm.memset.p0.i64(ptr align 1 getelementptr inbounds ([3 x [21 x i8]], ptr @keyBuff, i64 0, i64 1), i8 0, i64 21, i1 false)
  call void @llvm.memset.p0.i64(ptr align 2 getelementptr inbounds ([3 x [21 x i8]], ptr @keyBuff, i64 0, i64 2), i8 0, i64 21, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @valueBuff, i8 0, i64 21, i1 false)
  br label %35

35:                                               ; preds = %69, %45, %27
  %36 = load i8, ptr @isEndOfFile, align 1, !tbaa !11, !range !13, !noundef !14
  %37 = trunc i8 %36 to i1
  %38 = xor i1 %37, true
  br i1 %38, label %39, label %71

39:                                               ; preds = %35
  store i8 0, ptr @valueBuff, align 16, !tbaa !15
  %40 = getelementptr inbounds [131072 x i8], ptr %8, i64 0, i64 0
  %41 = load i32, ptr %9, align 4, !tbaa !5
  call void @parser(ptr noundef %40, i32 noundef %41)
  %42 = load i8, ptr @valueBuff, align 16, !tbaa !15
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  br label %35, !llvm.loop !16

46:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  store i8 0, ptr %10, align 1, !tbaa !15
  br label %47

47:                                               ; preds = %66, %46
  %48 = load i8, ptr %10, align 1, !tbaa !15
  %49 = zext i8 %48 to i64
  %50 = icmp ult i64 %49, 3
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i32 4, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %69

52:                                               ; preds = %47
  %53 = load i8, ptr %10, align 1, !tbaa !15
  %54 = zext i8 %53 to i64
  %55 = getelementptr inbounds [3 x [21 x i8]], ptr @keyBuff, i64 0, i64 %54
  %56 = getelementptr inbounds [21 x i8], ptr %55, i64 0, i64 0
  %57 = load i8, ptr %56, align 1, !tbaa !15
  %58 = icmp ne i8 %57, 0
  br i1 %58, label %59, label %65

59:                                               ; preds = %52
  %60 = load i8, ptr %10, align 1, !tbaa !15
  %61 = zext i8 %60 to i64
  %62 = getelementptr inbounds [3 x [21 x i8]], ptr @keyBuff, i64 0, i64 %61
  %63 = getelementptr inbounds [21 x i8], ptr %62, i64 0, i64 0
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %63)
  br label %65

65:                                               ; preds = %59, %52
  br label %66

66:                                               ; preds = %65
  %67 = load i8, ptr %10, align 1, !tbaa !15
  %68 = add i8 %67, 1
  store i8 %68, ptr %10, align 1, !tbaa !15
  br label %47, !llvm.loop !18

69:                                               ; preds = %51
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef @valueBuff)
  br label %35, !llvm.loop !16

71:                                               ; preds = %35
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 131072, ptr %8) #5
  br label %72

72:                                               ; preds = %71, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %73

73:                                               ; preds = %72, %13
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

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

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

declare void @perror(ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

declare i32 @fclose(ptr noundef) #3

declare i32 @printf(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"int", !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 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

@isEndOfFile = external dso_local local_unnamed_addr global i8, align 1
@keyBuff = external dso_local global [3 x [21 x i8]], align 16
@valueBuff = external dso_local global [21 x i8], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 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
declare dso_local void @parser(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca [131072 x i8], align 16
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef %6) #4
  br label %32

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call noalias ptr @fopen(ptr noundef %10, ptr noundef nonnull @.str.1)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %.lr.ph.preheader

13:                                               ; preds = %8
  tail call void @perror(ptr noundef nonnull @.str.2) #5
  br label %32

.lr.ph.preheader:                                 ; preds = %8
  call void @llvm.lifetime.start.p0(i64 131072, ptr nonnull %3) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(131072) %3, i8 0, i64 131072, i1 false)
  %14 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 1, i64 noundef 131072, ptr noundef nonnull %11)
  %15 = trunc i64 %14 to i32
  %16 = tail call i32 @fclose(ptr noundef nonnull %11)
  store i8 0, ptr @isEndOfFile, align 1, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(63) @keyBuff, i8 0, i64 63, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(21) @valueBuff, i8 0, i64 21, i1 false)
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.backedge
  store i8 0, ptr @valueBuff, align 16, !tbaa !11
  call void @parser(ptr noundef nonnull %3, i32 noundef %15)
  %17 = load i8, ptr @valueBuff, align 16, !tbaa !11
  %18 = icmp eq i8 %17, 0
  br i1 %18, label %.backedge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph
  %19 = load i8, ptr @keyBuff, align 16, !tbaa !11
  %.not14 = icmp eq i8 %19, 0
  br i1 %.not14, label %.preheader.1, label %22

.backedge:                                        ; preds = %30, %.lr.ph
  %20 = load i8, ptr @isEndOfFile, align 1, !tbaa !9, !range !12, !noundef !13
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %._crit_edge, label %.lr.ph, !llvm.loop !14

22:                                               ; preds = %.preheader.preheader
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull @keyBuff)
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader, %22
  %24 = load i8, ptr getelementptr inbounds (i8, ptr @keyBuff, i64 21), align 1, !tbaa !11
  %.not14.1 = icmp eq i8 %24, 0
  br i1 %.not14.1, label %.preheader.2, label %25

25:                                               ; preds = %.preheader.1
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull getelementptr inbounds (i8, ptr @keyBuff, i64 21))
  br label %.preheader.2

.preheader.2:                                     ; preds = %25, %.preheader.1
  %27 = load i8, ptr getelementptr inbounds (i8, ptr @keyBuff, i64 42), align 2, !tbaa !11
  %.not14.2 = icmp eq i8 %27, 0
  br i1 %.not14.2, label %30, label %28

28:                                               ; preds = %.preheader.2
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull getelementptr inbounds (i8, ptr @keyBuff, i64 42))
  br label %30

30:                                               ; preds = %28, %.preheader.2
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef nonnull @valueBuff)
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge
  call void @llvm.lifetime.end.p0(i64 131072, ptr nonnull %3) #6
  br label %32

32:                                               ; preds = %13, %._crit_edge, %4
  %.1 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 0, %._crit_edge ]
  ret i32 %.1
}

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

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

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

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

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

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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { cold nounwind }
attributes #5 = { cold }
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 = !{!"_Bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass