; LLVM IR from tangjz/acm-icpc :: hackerrank (security-involution)

; 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
@perm = external dso_local global [21 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

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

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

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr @perm, i64 %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %14)
  br label %16

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

19:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 1, ptr %3, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %42, %19
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %45

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp eq i32 %32, %33
  %35 = zext i1 %34 to i32
  %36 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %37 = trunc i8 %36 to i1
  %38 = zext i1 %37 to i32
  %39 = and i32 %38, %35
  %40 = icmp ne i32 %39, 0
  %41 = zext i1 %40 to i8
  store i8 %41, ptr %3, align 1, !tbaa !11
  br label %42

42:                                               ; preds = %25
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !15

45:                                               ; preds = %24
  %46 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %47 = trunc i8 %46 to i1
  %48 = zext i1 %47 to i64
  %49 = select i1 %47, ptr @.str.1, ptr @.str.2
  %50 = call i32 @puts(ptr noundef %49)
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i32 0
}

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

; 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

declare i32 @puts(ptr noundef) #1

attributes #0 = { mustprogress norecurse 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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}


; 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 global i32, align 4
@perm = external dso_local global [21 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not12 = icmp slt i32 %2, 1
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not1114 = icmp slt i32 %7, 1
  br i1 %.not1114, label %._crit_edge, label %.lr.ph17.preheader

.lr.ph17.preheader:                               ; preds = %.preheader
  %3 = zext nneg i32 %7 to i64
  %xtraiter = and i64 %3, 3
  %4 = icmp ult i32 %7, 4
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph17.preheader.new

.lr.ph17.preheader.new:                           ; preds = %.lr.ph17.preheader
  %unroll_iter = and i64 %3, 2147483644
  br label %.lr.ph17

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %5 = getelementptr inbounds i32, ptr @perm, i64 %indvars.iv
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %.not.not = icmp slt i64 %indvars.iv, %8
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph17, %.lr.ph17.preheader
  %.lcssa.ph = phi i1 [ poison, %.lr.ph17.preheader ], [ %50, %.lr.ph17 ]
  %indvars.iv22.unr = phi i64 [ 1, %.lr.ph17.preheader ], [ %indvars.iv.next23.3, %.lr.ph17 ]
  %.0915.unr = phi i1 [ true, %.lr.ph17.preheader ], [ %50, %.lr.ph17 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph17.epil

.lr.ph17.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph17.epil
  %indvars.iv22.epil = phi i64 [ %indvars.iv.next23.epil, %.lr.ph17.epil ], [ %indvars.iv22.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.0915.epil = phi i1 [ %16, %.lr.ph17.epil ], [ %.0915.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph17.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %9 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %indvars.iv22.epil
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = icmp eq i64 %indvars.iv22.epil, %14
  %16 = and i1 %.0915.epil, %15
  %indvars.iv.next23.epil = add nuw nsw i64 %indvars.iv22.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.lr.ph17.epil, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph17.epil, %._crit_edge.loopexit.unr-lcssa
  %.lcssa = phi i1 [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %16, %.lr.ph17.epil ]
  %17 = select i1 %.lcssa, ptr @.str.1, ptr @.str.2
  br label %._crit_edge

._crit_edge:                                      ; preds = %0, %._crit_edge.loopexit, %.preheader
  %.09.lcssa = phi ptr [ @.str.1, %.preheader ], [ %17, %._crit_edge.loopexit ], [ @.str.1, %0 ]
  %18 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.09.lcssa)
  ret i32 0

.lr.ph17:                                         ; preds = %.lr.ph17, %.lr.ph17.preheader.new
  %indvars.iv22 = phi i64 [ 1, %.lr.ph17.preheader.new ], [ %indvars.iv.next23.3, %.lr.ph17 ]
  %.0915 = phi i1 [ true, %.lr.ph17.preheader.new ], [ %50, %.lr.ph17 ]
  %niter = phi i64 [ 0, %.lr.ph17.preheader.new ], [ %niter.next.3, %.lr.ph17 ]
  %19 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %indvars.iv22
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = icmp eq i64 %indvars.iv22, %24
  %26 = and i1 %.0915, %25
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %27 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %indvars.iv.next23
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = icmp eq i64 %indvars.iv.next23, %32
  %34 = and i1 %26, %33
  %indvars.iv.next23.1 = add nuw nsw i64 %indvars.iv22, 2
  %35 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %indvars.iv.next23.1
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = zext i32 %39 to i64
  %41 = icmp eq i64 %indvars.iv.next23.1, %40
  %42 = and i1 %34, %41
  %indvars.iv.next23.2 = add nuw nsw i64 %indvars.iv22, 3
  %43 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %indvars.iv.next23.2
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [21 x i32], ptr @perm, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = zext i32 %47 to i64
  %49 = icmp eq i64 %indvars.iv.next23.2, %48
  %50 = and i1 %42, %49
  %indvars.iv.next23.3 = add nuw nsw i64 %indvars.iv22, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph17, !llvm.loop !13
}

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


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