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

; 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
@g = external dso_local global [309 x [309 x double]], align 16
@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
@mat = external dso_local global [309 x i32], 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 noundef i32 @_Z4dcmpd(double noundef) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3augi(i32 noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [309 x i8], ptr @usx, i64 0, i64 %8
  store i8 1, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %74, %1
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  br label %77

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

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [309 x [309 x double]], ptr @g, i64 0, i64 %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [309 x double], ptr %24, i64 0, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [309 x double], ptr @lbx, i64 0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !13
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [309 x double], ptr @lby, i64 0, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !13
  %37 = fadd double %32, %36
  %38 = fsub double %28, %37
  store double %38, ptr %6, align 8, !tbaa !13
  %39 = load double, ptr %6, align 8, !tbaa !13
  %40 = call noundef i32 @_Z4dcmpd(double noundef %39)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %47

42:                                               ; preds = %21
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [309 x double], ptr @slk, i64 0, i64 %44
  %46 = load double, ptr %6, align 8, !tbaa !13
  call void @_Z3dngRdd(ptr noundef nonnull align 8 dereferenceable(8) %45, double noundef %46)
  br label %69

47:                                               ; preds = %21
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [309 x i8], ptr @usy, i64 0, i64 %49
  store i8 1, ptr %50, align 1, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [309 x i32], ptr @mat, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %62

56:                                               ; preds = %47
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [309 x i32], ptr @mat, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = call noundef zeroext i1 @_Z3augi(i32 noundef %60)
  br i1 %61, label %62, label %68

62:                                               ; preds = %56, %47
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [309 x i32], ptr @mat, i64 0, i64 %65
  store i32 %63, ptr %66, align 4, !tbaa !5
  %67 = icmp ne i32 %63, 0
  store i1 %67, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %70

68:                                               ; preds = %56
  br label %69

69:                                               ; preds = %68, %42
  store i32 0, ptr %5, align 4
  br label %70

70:                                               ; preds = %69, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %71 = load i32, ptr %5, align 4
  switch i32 %71, label %77 [
    i32 0, label %72
  ]

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72, %15
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !15

77:                                               ; preds = %70, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %78 = load i32, ptr %5, align 4
  switch i32 %78, label %82 [
    i32 2, label %79
    i32 1, label %80
  ]

79:                                               ; preds = %77
  store i1 false, ptr %2, align 1
  br label %80

80:                                               ; preds = %79, %77
  %81 = load i1, ptr %2, align 1
  ret i1 %81

82:                                               ; preds = %77
  unreachable
}

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

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

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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4
@g = external dso_local local_unnamed_addr global [309 x [309 x double]], align 16
@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 global [309 x double], align 16
@mat = external dso_local local_unnamed_addr global [309 x i32], 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 noundef i32 @_Z4dcmpd(double noundef) local_unnamed_addr #0

; 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 nounwind uwtable
define dso_local noundef zeroext i1 @_Z3augi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [309 x i8], ptr @usx, i64 0, i64 %2
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %.not29 = icmp sgt i32 %4, 0
  br i1 %.not29, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds [309 x double], ptr @lbx, i64 0, i64 %2
  br label %6

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

10:                                               ; preds = %6
  %11 = getelementptr inbounds [309 x [309 x double]], ptr @g, i64 0, i64 %2, i64 %indvars.iv
  %12 = load double, ptr %11, align 8, !tbaa !13
  %13 = load double, ptr %5, align 8, !tbaa !13
  %14 = getelementptr inbounds [309 x double], ptr @lby, i64 0, i64 %indvars.iv
  %15 = load double, ptr %14, align 8, !tbaa !13
  %16 = fadd double %13, %15
  %17 = fsub double %12, %16
  %18 = tail call noundef i32 @_Z4dcmpd(double noundef %17)
  %.not22 = icmp eq i32 %18, 0
  br i1 %.not22, label %21, label %19

19:                                               ; preds = %10
  %20 = getelementptr inbounds [309 x double], ptr @slk, i64 0, i64 %indvars.iv
  tail call void @_Z3dngRdd(ptr noundef nonnull align 8 dereferenceable(8) %20, double noundef %17)
  br label %.thread

21:                                               ; preds = %10
  store i8 1, ptr %7, align 1, !tbaa !5
  %22 = getelementptr inbounds [309 x i32], ptr @mat, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %.not23 = icmp eq i32 %23, 0
  br i1 %.not23, label %26, label %24

24:                                               ; preds = %21
  %25 = tail call noundef zeroext i1 @_Z3augi(i32 noundef %23)
  br i1 %25, label %26, label %.thread

26:                                               ; preds = %21, %24
  %27 = getelementptr inbounds [309 x i32], ptr @mat, i64 0, i64 %indvars.iv
  store i32 %0, ptr %27, align 4, !tbaa !9
  %28 = icmp ne i32 %0, 0
  br label %.loopexit

.thread:                                          ; preds = %19, %24, %6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = load i32, ptr @n, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %.not = icmp slt i64 %indvars.iv, %30
  br i1 %.not, label %6, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.thread, %1, %26
  %.not27 = phi i1 [ true, %26 ], [ false, %1 ], [ false, %.thread ]
  %.3 = phi i1 [ %28, %26 ], [ undef, %1 ], [ undef, %.thread ]
  %spec.select = and i1 %.not27, %.3
  ret i1 %spec.select
}

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

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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