; LLVM IR from Discngine/fpocket :: src (utils)

; 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.tab_str = type { ptr, i32 }

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

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

declare i32 @fclose(ptr noundef) #1

; 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 ptr @f_readl(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 1
  %18 = call ptr @my_malloc(i64 noundef %17)
  store ptr %18, ptr %10, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call noalias ptr @fopen(ptr noundef %19, ptr noundef @.str)
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %2
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  call void @my_free(ptr noundef %24)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %114

25:                                               ; preds = %2
  br label %26

26:                                               ; preds = %39, %25
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call ptr @fgets(ptr noundef %27, i32 noundef %28, ptr noundef %29)
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %40

32:                                               ; preds = %26
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = call i32 @strcmp(ptr noundef @.str.1, ptr noundef %33) #6
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %9, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %36, %32
  br label %26, !llvm.loop !11

40:                                               ; preds = %26
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = call i32 @fclose(ptr noundef %41)
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = call noalias ptr @fopen(ptr noundef %43, ptr noundef @.str)
  store ptr %44, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %40
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  call void @my_free(ptr noundef %48)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %114

49:                                               ; preds = %40
  %50 = call ptr @my_malloc(i64 noundef 16)
  store ptr %50, ptr %12, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = mul i64 %52, 8
  %54 = call ptr @my_malloc(i64 noundef %53)
  store ptr %54, ptr %11, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %102, %49
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = call ptr @fgets(ptr noundef %56, i32 noundef %57, ptr noundef %58)
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %103

61:                                               ; preds = %55
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = call i32 @strcmp(ptr noundef @.str.1, ptr noundef %62) #6
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %102

65:                                               ; preds = %61
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = call i64 @strlen(ptr noundef %66) #6
  %68 = trunc i64 %67 to i32
  store i32 %68, ptr %8, align 4, !tbaa !9
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = sub nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %69, i64 %72
  %74 = load i8, ptr %73, align 1, !tbaa !13
  %75 = sext i8 %74 to i32
  %76 = icmp eq i32 %75, 10
  br i1 %76, label %77, label %84

77:                                               ; preds = %65
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %8, align 4, !tbaa !9
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  store i8 0, ptr %83, align 1, !tbaa !13
  br label %84

84:                                               ; preds = %77, %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = mul i64 %87, 1
  %89 = call ptr @my_malloc(i64 noundef %88)
  store ptr %89, ptr %14, align 8, !tbaa !5
  %90 = load ptr, ptr %14, align 8, !tbaa !5
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = load i32, ptr %8, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  %94 = sext i32 %93 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %90, ptr align 1 %91, i64 %94, i1 false)
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  %97 = load i32, ptr %7, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds ptr, ptr %96, i64 %98
  store ptr %95, ptr %99, align 8, !tbaa !5
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %102

102:                                              ; preds = %84, %61
  br label %55, !llvm.loop !14

103:                                              ; preds = %55
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = load ptr, ptr %12, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.tab_str, ptr %105, i32 0, i32 1
  store i32 %104, ptr %106, align 8, !tbaa !15
  %107 = load ptr, ptr %11, align 8, !tbaa !5
  %108 = load ptr, ptr %12, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.tab_str, ptr %108, i32 0, i32 0
  store ptr %107, ptr %109, align 8, !tbaa !17
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = call i32 @fclose(ptr noundef %110)
  %112 = load ptr, ptr %10, align 8, !tbaa !5
  call void @my_free(ptr noundef %112)
  %113 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %113, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %114

114:                                              ; preds = %103, %47, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %115 = load ptr, ptr %3, align 8
  ret ptr %115
}

declare ptr @my_malloc(i64 noundef) #1

declare void @my_free(ptr noundef) #1

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { nounwind willreturn 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}
!15 = !{!16, !10, i64 8}
!16 = !{!"tab_str", !6, i64 0, !10, i64 8}
!17 = !{!16, !6, i64 0}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @f_readl(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = sext i32 %1 to i64
  %4 = tail call ptr @my_malloc(i64 noundef %3) #5
  %5 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %44, label %.preheader

.preheader:                                       ; preds = %2
  %7 = tail call ptr @fgets(ptr noundef %4, i32 noundef %1, ptr noundef nonnull %5)
  %.not47 = icmp eq ptr %7, null
  br i1 %.not47, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.04148 = phi i32 [ %spec.select, %.lr.ph ], [ 0, %.preheader ]
  %8 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull dereferenceable(1) %4) #6
  %.not46 = icmp ne i32 %8, 0
  %9 = zext i1 %.not46 to i32
  %spec.select = add nuw nsw i32 %.04148, %9
  %10 = tail call ptr @fgets(ptr noundef %4, i32 noundef %1, ptr noundef nonnull %5)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.041.lcssa = phi i32 [ 0, %.preheader ], [ %spec.select, %.lr.ph ]
  %11 = tail call i32 @fclose(ptr noundef nonnull %5)
  %12 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str)
  %13 = icmp eq ptr %12, null
  br i1 %13, label %44, label %14

14:                                               ; preds = %._crit_edge
  %15 = tail call ptr @my_malloc(i64 noundef 16) #5
  %16 = zext nneg i32 %.041.lcssa to i64
  %17 = shl nuw nsw i64 %16, 3
  %18 = tail call ptr @my_malloc(i64 noundef %17) #5
  %19 = tail call ptr @fgets(ptr noundef %4, i32 noundef %1, ptr noundef nonnull %12)
  %.not4449 = icmp eq ptr %19, null
  br i1 %.not4449, label %._crit_edge53, label %.lr.ph52

.lr.ph52:                                         ; preds = %14, %40
  %.03950 = phi i32 [ %.1, %40 ], [ 0, %14 ]
  %20 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull dereferenceable(1) %4) #6
  %.not45 = icmp eq i32 %20, 0
  br i1 %.not45, label %40, label %21

21:                                               ; preds = %.lr.ph52
  %22 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #6
  %23 = trunc i64 %22 to i32
  %24 = shl i64 %22, 32
  %sext = add i64 %24, -4294967296
  %25 = ashr exact i64 %sext, 32
  %26 = getelementptr inbounds i8, ptr %4, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !7
  %28 = icmp eq i8 %27, 10
  br i1 %28, label %29, label %33

29:                                               ; preds = %21
  %30 = add nsw i32 %23, -1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %4, i64 %31
  store i8 0, ptr %32, align 1, !tbaa !7
  br label %33

33:                                               ; preds = %29, %21
  %.040 = phi i32 [ %30, %29 ], [ %23, %21 ]
  %34 = add nsw i32 %.040, 1
  %35 = sext i32 %34 to i64
  %36 = tail call ptr @my_malloc(i64 noundef %35) #5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr nonnull align 1 %4, i64 %35, i1 false)
  %37 = sext i32 %.03950 to i64
  %38 = getelementptr inbounds ptr, ptr %18, i64 %37
  store ptr %36, ptr %38, align 8, !tbaa !10
  %39 = add nsw i32 %.03950, 1
  br label %40

40:                                               ; preds = %33, %.lr.ph52
  %.1 = phi i32 [ %39, %33 ], [ %.03950, %.lr.ph52 ]
  %41 = tail call ptr @fgets(ptr noundef %4, i32 noundef %1, ptr noundef nonnull %12)
  %.not44 = icmp eq ptr %41, null
  br i1 %.not44, label %._crit_edge53, label %.lr.ph52, !llvm.loop !12

._crit_edge53:                                    ; preds = %40, %14
  %42 = getelementptr inbounds i8, ptr %15, i64 8
  store i32 %.041.lcssa, ptr %42, align 8, !tbaa !13
  store ptr %18, ptr %15, align 8, !tbaa !16
  %43 = tail call i32 @fclose(ptr noundef nonnull %12)
  br label %44

44:                                               ; preds = %._crit_edge, %2, %._crit_edge53
  %.0 = phi ptr [ %15, %._crit_edge53 ], [ null, %2 ], [ null, %._crit_edge ]
  tail call void @my_free(ptr noundef %4) #5
  ret ptr %.0
}

declare ptr @my_malloc(i64 noundef) local_unnamed_addr #2

declare void @my_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { 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 #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 = { "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 nounwind willreturn memory(argmem: 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = distinct !{!12, !6}
!13 = !{!14, !15, i64 8}
!14 = !{!"tab_str", !11, i64 0, !15, i64 8}
!15 = !{!"int", !8, i64 0}
!16 = !{!14, !11, i64 0}


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