; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-04-04/H - Laser Cutter - lzy.ll (Z3adjv)

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

@n = external dso_local global i32, align 4
@lbx = external dso_local global [309 x double], align 16
@lby = external dso_local global [309 x double], align 16
@slk = external dso_local global [309 x double], align 16
@usx = external dso_local global [309 x i8], align 16
@usy = external dso_local global [309 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3dngRdd(ptr noundef nonnull align 8 dereferenceable(8), double noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3adjv() #0 {
  %1 = alloca double, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store double 1.000000e+08, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %22, %0
  %6 = load i32, ptr %2, align 4, !tbaa !9
  %7 = load i32, ptr @n, align 4, !tbaa !9
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %25

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [309 x i8], ptr @usy, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11, !range !13, !noundef !14
  %15 = trunc i8 %14 to i1
  br i1 %15, label %21, label %16

16:                                               ; preds = %10
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [309 x double], ptr @slk, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !5
  call void @_Z3dngRdd(ptr noundef nonnull align 8 dereferenceable(8) %1, double noundef %20)
  br label %21

21:                                               ; preds = %16, %10
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %2, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !9
  br label %5, !llvm.loop !15

25:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %45, %25
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = load i32, ptr @n, align 4, !tbaa !9
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %48

31:                                               ; preds = %26
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [309 x i8], ptr @usx, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11, !range !13, !noundef !14
  %36 = trunc i8 %35 to i1
  br i1 %36, label %37, label %44

37:                                               ; preds = %31
  %38 = load double, ptr %1, align 8, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [309 x double], ptr @lbx, i64 0, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fadd double %42, %38
  store double %43, ptr %41, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %37, %31
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %3, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !9
  br label %26, !llvm.loop !17

48:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %75, %48
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = load i32, ptr @n, align 4, !tbaa !9
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %78

54:                                               ; preds = %49
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [309 x i8], ptr @usy, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !11, !range !13, !noundef !14
  %59 = trunc i8 %58 to i1
  br i1 %59, label %60, label %67

60:                                               ; preds = %54
  %61 = load double, ptr %1, align 8, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [309 x double], ptr @lby, i64 0, i64 %63
  %65 = load double, ptr %64, align 8, !tbaa !5
  %66 = fsub double %65, %61
  store double %66, ptr %64, align 8, !tbaa !5
  br label %74

67:                                               ; preds = %54
  %68 = load double, ptr %1, align 8, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [309 x double], ptr @slk, i64 0, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !5
  %73 = fsub double %72, %68
  store double %73, ptr %71, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %67, %60
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %4, align 4, !tbaa !9
  br label %49, !llvm.loop !18

78:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@lbx = external dso_local local_unnamed_addr global [309 x double], align 16
@lby = external dso_local local_unnamed_addr global [309 x double], align 16
@slk = external dso_local local_unnamed_addr global [309 x double], align 16
@usx = external dso_local local_unnamed_addr global [309 x i8], align 16
@usy = external dso_local local_unnamed_addr global [309 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3dngRdd(ptr noundef nonnull align 8 dereferenceable(8), double noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3adjv() local_unnamed_addr #0 {
  %1 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #2
  store double 1.000000e+08, ptr %1, align 8, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %.not18 = icmp slt i32 %2, 1
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.preheader17:                                     ; preds = %15
  %.not1520 = icmp slt i32 %16, 1
  br i1 %.not1520, label %._crit_edge, label %.lr.ph22

.lr.ph22:                                         ; preds = %.preheader17
  %3 = load double, ptr %1, align 8
  %4 = zext nneg i32 %16 to i64
  %5 = zext nneg i32 %16 to i64
  %6 = add nsw i64 %5, -1
  %xtraiter = and i64 %4, 1
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %.preheader.unr-lcssa, label %.lr.ph22.new

.lr.ph22.new:                                     ; preds = %.lr.ph22
  %unroll_iter = and i64 %4, 2147483646
  br label %27

.lr.ph:                                           ; preds = %0, %15
  %8 = phi i32 [ %16, %15 ], [ %2, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %15 ], [ 1, %0 ]
  %9 = getelementptr inbounds [309 x i8], ptr @usy, i64 0, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %15, label %12

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds [309 x double], ptr @slk, i64 0, i64 %indvars.iv
  %14 = load double, ptr %13, align 8, !tbaa !5
  call void @_Z3dngRdd(ptr noundef nonnull align 8 dereferenceable(8) %1, double noundef %14)
  %.pre = load i32, ptr @n, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %.lr.ph, %12
  %16 = phi i32 [ %8, %.lr.ph ], [ %.pre, %12 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = sext i32 %16 to i64
  %.not.not = icmp slt i64 %indvars.iv, %17
  br i1 %.not.not, label %.lr.ph, label %.preheader17, !llvm.loop !15

.preheader.unr-lcssa:                             ; preds = %43, %.lr.ph22
  %indvars.iv28.unr = phi i64 [ 1, %.lr.ph22 ], [ %indvars.iv.next29.1, %43 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader.unr-lcssa
  %18 = getelementptr inbounds [309 x i8], ptr @usx, i64 0, i64 %indvars.iv28.unr
  %19 = load i8, ptr %18, align 1, !tbaa !11, !range !13, !noundef !14
  %20 = trunc nuw i8 %19 to i1
  br i1 %20, label %21, label %.preheader

21:                                               ; preds = %.epil.preheader
  %22 = getelementptr inbounds [309 x double], ptr @lbx, i64 0, i64 %indvars.iv28.unr
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = fadd double %3, %23
  store double %24, ptr %22, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.epil.preheader, %21, %.preheader.unr-lcssa
  br i1 %.not1520, label %._crit_edge, label %.lr.ph25

.lr.ph25:                                         ; preds = %.preheader
  %25 = load double, ptr %1, align 8
  %xtraiter45 = and i64 %4, 1
  %26 = icmp eq i64 %6, 0
  br i1 %26, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph25.new

.lr.ph25.new:                                     ; preds = %.lr.ph25
  %unroll_iter47 = and i64 %4, 2147483646
  br label %50

27:                                               ; preds = %43, %.lr.ph22.new
  %indvars.iv28 = phi i64 [ 1, %.lr.ph22.new ], [ %indvars.iv.next29.1, %43 ]
  %niter = phi i64 [ 0, %.lr.ph22.new ], [ %niter.next.1, %43 ]
  %28 = getelementptr inbounds [309 x i8], ptr @usx, i64 0, i64 %indvars.iv28
  %29 = load i8, ptr %28, align 1, !tbaa !11, !range !13, !noundef !14
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %31, label %35

31:                                               ; preds = %27
  %32 = getelementptr inbounds [309 x double], ptr @lbx, i64 0, i64 %indvars.iv28
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fadd double %3, %33
  store double %34, ptr %32, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %27, %31
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %36 = getelementptr inbounds [309 x i8], ptr @usx, i64 0, i64 %indvars.iv.next29
  %37 = load i8, ptr %36, align 1, !tbaa !11, !range !13, !noundef !14
  %38 = trunc nuw i8 %37 to i1
  br i1 %38, label %39, label %43

39:                                               ; preds = %35
  %40 = getelementptr inbounds [309 x double], ptr @lbx, i64 0, i64 %indvars.iv.next29
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = fadd double %3, %41
  store double %42, ptr %40, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %39, %35
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.unr-lcssa, label %27, !llvm.loop !17

._crit_edge.loopexit.unr-lcssa:                   ; preds = %50, %.lr.ph25
  %indvars.iv31.unr = phi i64 [ 1, %.lr.ph25 ], [ %indvars.iv.next32.1, %50 ]
  %lcmp.mod46.not = icmp eq i64 %xtraiter45, 0
  br i1 %lcmp.mod46.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %44 = getelementptr inbounds [309 x i8], ptr @usy, i64 0, i64 %indvars.iv31.unr
  %45 = load i8, ptr %44, align 1, !tbaa !11, !range !13, !noundef !14
  %46 = trunc nuw i8 %45 to i1
  %lby.slk.epil = select i1 %46, ptr @lby, ptr @slk
  %47 = getelementptr inbounds [309 x double], ptr %lby.slk.epil, i64 0, i64 %indvars.iv31.unr
  %48 = load double, ptr %47, align 8, !tbaa !5
  %49 = fsub double %48, %25
  store double %49, ptr %47, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %0, %.preheader17, %.preheader
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #2
  ret void

50:                                               ; preds = %50, %.lr.ph25.new
  %indvars.iv31 = phi i64 [ 1, %.lr.ph25.new ], [ %indvars.iv.next32.1, %50 ]
  %niter48 = phi i64 [ 0, %.lr.ph25.new ], [ %niter48.next.1, %50 ]
  %51 = getelementptr inbounds [309 x i8], ptr @usy, i64 0, i64 %indvars.iv31
  %52 = load i8, ptr %51, align 1, !tbaa !11, !range !13, !noundef !14
  %53 = trunc nuw i8 %52 to i1
  %lby.slk = select i1 %53, ptr @lby, ptr @slk
  %54 = getelementptr inbounds [309 x double], ptr %lby.slk, i64 0, i64 %indvars.iv31
  %55 = load double, ptr %54, align 8, !tbaa !5
  %56 = fsub double %55, %25
  store double %56, ptr %54, align 8, !tbaa !5
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %57 = getelementptr inbounds [309 x i8], ptr @usy, i64 0, i64 %indvars.iv.next32
  %58 = load i8, ptr %57, align 1, !tbaa !11, !range !13, !noundef !14
  %59 = trunc nuw i8 %58 to i1
  %lby.slk.1 = select i1 %59, ptr @lby, ptr @slk
  %60 = getelementptr inbounds [309 x double], ptr %lby.slk.1, i64 0, i64 %indvars.iv.next32
  %61 = load double, ptr %60, align 8, !tbaa !5
  %62 = fsub double %61, %25
  store double %62, ptr %60, align 8, !tbaa !5
  %indvars.iv.next32.1 = add nuw nsw i64 %indvars.iv31, 2
  %niter48.next.1 = add i64 %niter48, 2
  %niter48.ncmp.1 = icmp eq i64 %niter48.next.1, %unroll_iter47
  br i1 %niter48.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %50, !llvm.loop !18
}

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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