; LLVM IR from SanLiWuXun/2phase-LBM-DNS :: LBMDNS.ll (Z13writefile_gasi)

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

@rhog = external dso_local global [201 x [801 x double]], align 16
@ugx = external dso_local global [201 x [801 x double]], align 16
@ugy = external dso_local global [201 x [801 x double]], align 16
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [41 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

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

declare i32 @fclose(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13writefile_gasi(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca [100 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 100, ptr %4) #4
  %7 = getelementptr inbounds [100 x i8], ptr %4, i64 0, i64 0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %7, ptr noundef @.str.3, i32 noundef %8) #4
  %10 = getelementptr inbounds [100 x i8], ptr %4, i64 0, i64 0
  %11 = call noalias ptr @fopen(ptr noundef %10, ptr noundef @.str.4)
  store ptr %11, ptr %3, align 8, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !9
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str.5, i32 noundef 201, i32 noundef 801) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %55, %1
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp sle i32 %15, 800
  br i1 %16, label %17, label %58

17:                                               ; preds = %14
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %51, %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp sle i32 %19, 200
  br i1 %20, label %21, label %54

21:                                               ; preds = %18
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sitofp i32 %23 to double
  %25 = fmul double %24, 1.000000e+00
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = sitofp i32 %26 to double
  %28 = fmul double %27, 1.000000e+00
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [201 x [801 x double]], ptr @rhog, i64 0, i64 %30
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [801 x double], ptr %31, i64 0, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [201 x [801 x double]], ptr @ugx, i64 0, i64 %37
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [801 x double], ptr %38, i64 0, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [201 x [801 x double]], ptr @ugy, i64 0, i64 %44
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [801 x double], ptr %45, i64 0, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.6, double noundef %25, double noundef %28, double noundef %35, double noundef %42, double noundef %49) #4
  br label %51

51:                                               ; preds = %21
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %18, !llvm.loop !13

54:                                               ; preds = %18
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !5
  br label %14, !llvm.loop !15

58:                                               ; preds = %14
  %59 = load ptr, ptr %3, align 8, !tbaa !9
  %60 = call i32 @fclose(ptr noundef %59)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

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

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 = { mustprogress 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 "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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"

@rhog = external dso_local local_unnamed_addr global [201 x [801 x double]], align 16
@ugx = external dso_local local_unnamed_addr global [201 x [801 x double]], align 16
@ugy = external dso_local local_unnamed_addr global [201 x [801 x double]], align 16
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [41 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: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z13writefile_gasi(i32 noundef %0) local_unnamed_addr #2 {
  %2 = alloca [100 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %2) #3
  %3 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %0) #3
  %4 = call noalias ptr @fopen(ptr noundef nonnull %2, ptr noundef nonnull @.str.4)
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.5, i32 noundef 201, i32 noundef 801) #3
  br label %.preheader

.preheader:                                       ; preds = %1, %18
  %indvars.iv19 = phi i64 [ 0, %1 ], [ %indvars.iv.next20, %18 ]
  %6 = trunc nuw nsw i64 %indvars.iv19 to i32
  %7 = uitofp nneg i32 %6 to double
  br label %8

8:                                                ; preds = %.preheader, %8
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %8 ]
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  %10 = uitofp nneg i32 %9 to double
  %11 = getelementptr inbounds [201 x [801 x double]], ptr @rhog, i64 0, i64 %indvars.iv, i64 %indvars.iv19
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds [201 x [801 x double]], ptr @ugx, i64 0, i64 %indvars.iv, i64 %indvars.iv19
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds [201 x [801 x double]], ptr @ugy, i64 0, i64 %indvars.iv, i64 %indvars.iv19
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.6, double noundef %10, double noundef %7, double noundef %12, double noundef %14, double noundef %16) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 201
  br i1 %exitcond.not, label %18, label %8, !llvm.loop !9

18:                                               ; preds = %8
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %exitcond22.not = icmp eq i64 %indvars.iv.next20, 801
  br i1 %exitcond22.not, label %19, label %.preheader, !llvm.loop !11

19:                                               ; preds = %18
  %20 = tail call i32 @fclose(ptr noundef %4)
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %2) #3
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, 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

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

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass