; LLVM IR from PyCee/NUS_library :: src (NUS_save)

; 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.NUS_absolute_path = type { [100 x i8] }
%struct.NUS_save = type { %struct.NUS_string_group }
%struct.NUS_string_group = type { ptr, i32 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_save_build(ptr noundef byval(%struct.NUS_absolute_path) align 8 %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [100 x i8], align 16
  %8 = alloca [100 x i8], align 16
  %9 = alloca [100 x i8], align 16
  %10 = alloca ptr, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.NUS_save, ptr %11, i32 0, i32 0
  call void @nus_string_group_build(ptr noundef %12)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %13 = getelementptr inbounds %struct.NUS_absolute_path, ptr %0, i32 0, i32 0
  %14 = getelementptr inbounds [100 x i8], ptr %13, i64 0, i64 0
  %15 = call noalias ptr @fopen(ptr noundef %14, ptr noundef @.str)
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %21

17:                                               ; preds = %2
  %18 = getelementptr inbounds %struct.NUS_absolute_path, ptr %0, i32 0, i32 0
  %19 = getelementptr inbounds [100 x i8], ptr %18, i64 0, i64 0
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %19)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %82

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 100, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 100, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 100, ptr %9) #6
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %24 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %22, ptr noundef @.str.2, ptr noundef %23)
  %25 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %26 = call i32 @strcmp(ptr noundef @.str.3, ptr noundef %25) #7
  %27 = icmp ne i32 0, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %21
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef @.str.3)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %81

30:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  br label %31

31:                                               ; preds = %45, %30
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %34 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %32, ptr noundef @.str.5, ptr noundef %33)
  %35 = icmp ne i32 %34, -1
  br i1 %35, label %36, label %77

36:                                               ; preds = %31
  %37 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %37, i8 0, i64 100, i1 false)
  %38 = getelementptr inbounds [100 x i8], ptr %9, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %38, i8 0, i64 100, i1 false)
  %39 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %40 = call ptr @strstr(ptr noundef %39, ptr noundef @.str.6) #7
  store ptr %40, ptr %10, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %45

42:                                               ; preds = %36
  %43 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %43)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %80

45:                                               ; preds = %36
  %46 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  %47 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %50 = ptrtoint ptr %48 to i64
  %51 = ptrtoint ptr %49 to i64
  %52 = sub i64 %50, %51
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %46, ptr align 16 %47, i64 %52, i1 false)
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %55 = ptrtoint ptr %53 to i64
  %56 = ptrtoint ptr %54 to i64
  %57 = sub i64 %55, %56
  %58 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 %57
  store i8 0, ptr %58, align 1, !tbaa !9
  %59 = getelementptr inbounds [100 x i8], ptr %9, i64 0, i64 0
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 1
  %62 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %63 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %64 = call i64 @strlen(ptr noundef %63) #7
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 1
  %68 = ptrtoint ptr %65 to i64
  %69 = ptrtoint ptr %67 to i64
  %70 = sub i64 %68, %69
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %59, ptr align 1 %61, i64 %70, i1 false)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.NUS_save, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  call void @nus_string_group_append(ptr noundef %72, ptr noundef %73)
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.NUS_save, ptr %74, i32 0, i32 0
  %76 = getelementptr inbounds [100 x i8], ptr %9, i64 0, i64 0
  call void @nus_string_group_append(ptr noundef %75, ptr noundef %76)
  br label %31, !llvm.loop !10

77:                                               ; preds = %31
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = call i32 @fclose(ptr noundef %78)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %80

80:                                               ; preds = %77, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %81

81:                                               ; preds = %80, %28
  call void @llvm.lifetime.end.p0(i64 100, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 100, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 100, ptr %7) #6
  br label %82

82:                                               ; preds = %81, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  %83 = load i32, ptr %3, align 4
  ret i32 %83
}

declare void @nus_string_group_build(ptr noundef) #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) #1

declare i32 @printf(ptr noundef, ...) #1

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, 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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, 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) #5

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

declare void @nus_string_group_append(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) #2

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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: write) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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.NUS_absolute_path = type { [100 x i8] }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_save_build(ptr noundef byval(%struct.NUS_absolute_path) align 8 %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [100 x i8], align 16
  %4 = alloca [100 x i8], align 16
  %5 = alloca [100 x i8], align 16
  tail call void @nus_string_group_build(ptr noundef %1) #7
  %6 = call noalias ptr @fopen(ptr noundef nonnull %0, ptr noundef nonnull @.str)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull %0)
  br label %35

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %4) #7
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %5) #7
  %11 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %6, ptr noundef nonnull @.str.2, ptr noundef nonnull %3) #7
  %12 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull dereferenceable(1) %3) #8
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %.preheader, label %15

.preheader:                                       ; preds = %10
  %13 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %6, ptr noundef nonnull @.str.5, ptr noundef nonnull %3) #7
  %.not1213 = icmp eq i32 %13, -1
  br i1 %.not1213, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %14 = ptrtoint ptr %3 to i64
  br label %17

15:                                               ; preds = %10
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef nonnull @.str.3)
  br label %34

17:                                               ; preds = %.lr.ph, %22
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %4, i8 0, i64 100, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %5, i8 0, i64 100, i1 false)
  %18 = call ptr @strstr(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.6) #8
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %3)
  br label %34

22:                                               ; preds = %17
  %23 = ptrtoint ptr %18 to i64
  %24 = sub i64 %23, %14
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %4, ptr nonnull align 16 %3, i64 %24, i1 false)
  %25 = getelementptr inbounds [100 x i8], ptr %4, i64 0, i64 %24
  store i8 0, ptr %25, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %18, i64 1
  %27 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #8
  %28 = getelementptr inbounds i8, ptr %3, i64 %27
  %29 = ptrtoint ptr %28 to i64
  %30 = ptrtoint ptr %26 to i64
  %31 = sub i64 %29, %30
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %5, ptr nonnull align 1 %26, i64 %31, i1 false)
  call void @nus_string_group_append(ptr noundef %1, ptr noundef nonnull %4) #7
  call void @nus_string_group_append(ptr noundef %1, ptr noundef nonnull %5) #7
  %32 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef nonnull %6, ptr noundef nonnull @.str.5, ptr noundef nonnull %3) #7
  %.not12 = icmp eq i32 %32, -1
  br i1 %.not12, label %._crit_edge, label %17, !llvm.loop !8

._crit_edge:                                      ; preds = %22, %.preheader
  %33 = call i32 @fclose(ptr noundef nonnull %6)
  br label %34

34:                                               ; preds = %20, %._crit_edge, %15
  %.1 = phi i32 [ 0, %15 ], [ 0, %20 ], [ 1, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %3) #7
  br label %35

35:                                               ; preds = %34, %8
  %.2 = phi i32 [ 0, %8 ], [ %.1, %34 ]
  ret i32 %.2
}

declare void @nus_string_group_build(ptr noundef) local_unnamed_addr #1

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

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

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

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

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

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

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

; 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) #6

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

declare void @nus_string_group_append(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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