; LLVM IR from eyangch/competitive-programming :: BOI/2008/ele.ll (Z6solve2i)

; 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
@a = external dso_local global [300 x i32], align 16
@sum = external dso_local global i32, align 4
@vis = external dso_local global [100001 x i8], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6solve2i(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr @vis, i64 %8
  %10 = getelementptr inbounds i8, ptr %9, i64 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 0, ptr %3, align 1, !tbaa !9
  call void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef @vis, ptr noundef %10, ptr noundef nonnull align 1 dereferenceable(1) %3)
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  store i8 1, ptr @vis, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %66, %1
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr @N, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %69

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [300 x i32], ptr @a, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sub nsw i32 %17, %21
  %23 = load i32, ptr @sum, align 4, !tbaa !5
  %24 = sdiv i32 %23, 2
  %25 = icmp sgt i32 %22, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %16
  br label %66

27:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %28 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %28, ptr %6, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %62, %27
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = icmp sge i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %65

33:                                               ; preds = %29
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [300 x i32], ptr @a, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp sge i32 %34, %38
  br i1 %39, label %40, label %61

40:                                               ; preds = %33
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !9, !range !11, !noundef !12
  %45 = trunc i8 %44 to i1
  br i1 %45, label %61, label %46

46:                                               ; preds = %40
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [300 x i32], ptr @a, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sub nsw i32 %47, %51
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !9, !range !11, !noundef !12
  %56 = trunc i8 %55 to i1
  br i1 %56, label %57, label %61

57:                                               ; preds = %46
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %59
  store i8 1, ptr %60, align 1, !tbaa !9
  br label %61

61:                                               ; preds = %57, %46, %40, %33
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr %6, align 4, !tbaa !5
  br label %29, !llvm.loop !13

65:                                               ; preds = %32
  br label %66

66:                                               ; preds = %65, %26
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !15

69:                                               ; preds = %15
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !9, !range !11, !noundef !12
  %74 = trunc i8 %73 to i1
  ret i1 %74
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) #2

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

!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 = 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"

@N = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [300 x i32], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local global [100001 x i8], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6solve2i(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca i8, align 1
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds i8, ptr @vis, i64 %3
  %5 = getelementptr inbounds i8, ptr %4, i64 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #3
  store i8 0, ptr %2, align 1, !tbaa !5
  call void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef nonnull @vis, ptr noundef nonnull %5, ptr noundef nonnull align 1 dereferenceable(1) %2)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  store i8 1, ptr @vis, align 16, !tbaa !5
  %6 = load i32, ptr @N, align 4, !tbaa !9
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph19, label %._crit_edge

.lr.ph19:                                         ; preds = %1
  %8 = load i32, ptr @sum, align 4, !tbaa !9
  %9 = sdiv i32 %8, 2
  %10 = icmp sgt i32 %0, -1
  br i1 %10, label %.lr.ph19.split.us.preheader, label %._crit_edge

.lr.ph19.split.us.preheader:                      ; preds = %.lr.ph19
  %wide.trip.count = zext nneg i32 %6 to i64
  %11 = and i64 %3, 1
  %lcmp.mod.not.not = icmp eq i64 %11, 0
  %12 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %3
  %indvars.iv.next.prol = add nsw i64 %3, -1
  %13 = icmp eq i32 %0, 0
  br label %.lr.ph19.split.us

.lr.ph19.split.us:                                ; preds = %.lr.ph19.split.us.preheader, %..loopexit_crit_edge.us
  %indvars.iv22 = phi i64 [ 0, %.lr.ph19.split.us.preheader ], [ %indvars.iv.next23, %..loopexit_crit_edge.us ]
  %14 = getelementptr inbounds [300 x i32], ptr @a, i64 0, i64 %indvars.iv22
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = sub nsw i32 %0, %15
  %17 = icmp sgt i32 %16, %9
  br i1 %17, label %..loopexit_crit_edge.us, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.lr.ph19.split.us
  %18 = sext i32 %15 to i64
  br i1 %lcmp.mod.not.not, label %.preheader.us.prol, label %.preheader.us.prol.loopexit

.preheader.us.prol:                               ; preds = %.preheader.us.preheader
  %.not.us.prol = icmp sgt i32 %15, %0
  br i1 %.not.us.prol, label %.preheader.us.prol.loopexit, label %19

19:                                               ; preds = %.preheader.us.prol
  %20 = load i8, ptr %12, align 1, !tbaa !5, !range !11, !noundef !12
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %.preheader.us.prol.loopexit, label %22

22:                                               ; preds = %19
  %23 = sub nsw i64 %3, %18
  %24 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5, !range !11, !noundef !12
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %27, label %.preheader.us.prol.loopexit

27:                                               ; preds = %22
  store i8 1, ptr %12, align 1, !tbaa !5
  br label %.preheader.us.prol.loopexit

.preheader.us.prol.loopexit:                      ; preds = %.preheader.us.prol, %19, %22, %27, %.preheader.us.preheader
  %indvars.iv.unr = phi i64 [ %3, %.preheader.us.preheader ], [ %indvars.iv.next.prol, %27 ], [ %indvars.iv.next.prol, %22 ], [ %indvars.iv.next.prol, %19 ], [ %indvars.iv.next.prol, %.preheader.us.prol ]
  br i1 %13, label %..loopexit_crit_edge.us, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.prol.loopexit, %48
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %48 ], [ %indvars.iv.unr, %.preheader.us.prol.loopexit ]
  %.not.us = icmp slt i64 %indvars.iv, %18
  br i1 %.not.us, label %.preheader.us.1, label %28

28:                                               ; preds = %.preheader.us
  %29 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %indvars.iv
  %30 = load i8, ptr %29, align 1, !tbaa !5, !range !11, !noundef !12
  %31 = trunc nuw i8 %30 to i1
  br i1 %31, label %.preheader.us.1, label %32

32:                                               ; preds = %28
  %33 = sub nsw i64 %indvars.iv, %18
  %34 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5, !range !11, !noundef !12
  %36 = trunc nuw i8 %35 to i1
  br i1 %36, label %37, label %.preheader.us.1

37:                                               ; preds = %32
  store i8 1, ptr %29, align 1, !tbaa !5
  br label %.preheader.us.1

.preheader.us.1:                                  ; preds = %37, %32, %28, %.preheader.us
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not.us.1.not = icmp sgt i64 %indvars.iv, %18
  br i1 %.not.us.1.not, label %38, label %48

38:                                               ; preds = %.preheader.us.1
  %39 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %indvars.iv.next
  %40 = load i8, ptr %39, align 1, !tbaa !5, !range !11, !noundef !12
  %41 = trunc nuw i8 %40 to i1
  br i1 %41, label %48, label %42

42:                                               ; preds = %38
  %43 = sub nsw i64 %indvars.iv.next, %18
  %44 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !5, !range !11, !noundef !12
  %46 = trunc nuw i8 %45 to i1
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  store i8 1, ptr %39, align 1, !tbaa !5
  br label %48

48:                                               ; preds = %47, %42, %38, %.preheader.us.1
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %49 = icmp sgt i64 %indvars.iv, 1
  br i1 %49, label %.preheader.us, label %..loopexit_crit_edge.us, !llvm.loop !13

..loopexit_crit_edge.us:                          ; preds = %.preheader.us.prol.loopexit, %48, %.lr.ph19.split.us
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next23, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph19.split.us, !llvm.loop !15

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.lr.ph19, %1
  %50 = load i8, ptr %4, align 1, !tbaa !5, !range !11, !noundef !12
  %51 = trunc nuw i8 %50 to i1
  ret i1 %51
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #2

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

!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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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