; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-10-05/F - Fund Management - tjz.ll (Z5printii)

; 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
@p = external dso_local global [110 x [233333 x i32]], align 16
@que = external dso_local global [233333 x i64], align 16
@str = external dso_local global [10 x [15 x i8]], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 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

; 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 void @_Z5printii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %11, label %21

11:                                               ; preds = %2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [110 x [233333 x i32]], ptr @p, i64 0, i64 %15
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [233333 x i32], ptr %16, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  call void @_Z5printii(i32 noundef %13, i32 noundef %20)
  br label %21

21:                                               ; preds = %11, %2
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [110 x [233333 x i32]], ptr @p, i64 0, i64 %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [233333 x i32], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %21
  %32 = call i32 @puts(ptr noundef @.str)
  br label %103

33:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [110 x [233333 x i32]], ptr @p, i64 0, i64 %35
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [233333 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [233333 x i64], ptr @que, i64 0, i64 %41
  store ptr %42, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [233333 x i64], ptr @que, i64 0, i64 %44
  store ptr %45, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %98, %33
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 2, ptr %8, align 4
  br label %101

51:                                               ; preds = %46
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = mul nsw i64 4, %55
  %57 = ashr i64 %53, %56
  %58 = and i64 %57, 15
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = mul nsw i64 4, %62
  %64 = ashr i64 %60, %63
  %65 = and i64 %64, 15
  %66 = icmp ne i64 %58, %65
  br i1 %66, label %67, label %97

67:                                               ; preds = %51
  %68 = load ptr, ptr %5, align 8, !tbaa !9
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = mul nsw i64 4, %71
  %73 = ashr i64 %69, %72
  %74 = and i64 %73, 15
  %75 = add nsw i64 %74, 1
  %76 = load ptr, ptr %6, align 8, !tbaa !9
  %77 = load i64, ptr %76, align 8, !tbaa !11
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = mul nsw i64 4, %79
  %81 = ashr i64 %77, %80
  %82 = and i64 %81, 15
  %83 = icmp eq i64 %75, %82
  br i1 %83, label %84, label %90

84:                                               ; preds = %67
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [10 x [15 x i8]], ptr @str, i64 0, i64 %86
  %88 = getelementptr inbounds [15 x i8], ptr %87, i64 0, i64 0
  %89 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %88)
  br label %96

90:                                               ; preds = %67
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [10 x [15 x i8]], ptr @str, i64 0, i64 %92
  %94 = getelementptr inbounds [15 x i8], ptr %93, i64 0, i64 0
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %94)
  br label %96

96:                                               ; preds = %90, %84
  store i32 2, ptr %8, align 4
  br label %101

97:                                               ; preds = %51
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %7, align 4, !tbaa !5
  br label %46, !llvm.loop !13

101:                                              ; preds = %96, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %102

102:                                              ; preds = %101
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %103

103:                                              ; preds = %102, %31
  ret void
}

declare i32 @puts(ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #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 = { "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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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
@p = external dso_local local_unnamed_addr global [110 x [233333 x i32]], align 16
@que = external dso_local local_unnamed_addr global [233333 x i64], align 16
@str = external dso_local global [10 x [15 x i8]], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5printii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 1
  br i1 %3, label %4, label %._crit_edge

._crit_edge:                                      ; preds = %2
  %.pre = sext i32 %1 to i64
  br label %10

4:                                                ; preds = %2
  %5 = add nsw i32 %0, -1
  %6 = zext nneg i32 %0 to i64
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds [110 x [233333 x i32]], ptr @p, i64 0, i64 %6, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  tail call void @_Z5printii(i32 noundef %5, i32 noundef %9)
  br label %10

10:                                               ; preds = %._crit_edge, %4
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %7, %4 ]
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [110 x [233333 x i32]], ptr @p, i64 0, i64 %11, i64 %.pre-phi
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %13, %1
  br i1 %14, label %15, label %17

15:                                               ; preds = %10
  %16 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str)
  br label %.loopexit

17:                                               ; preds = %10
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %17
  %20 = getelementptr inbounds [233333 x i64], ptr @que, i64 0, i64 %.pre-phi
  %21 = sext i32 %13 to i64
  %22 = getelementptr inbounds [233333 x i64], ptr @que, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i64, ptr %20, align 8, !tbaa !9
  %wide.trip.count = zext nneg i32 %18 to i64
  br label %26

25:                                               ; preds = %26
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %26, !llvm.loop !11

26:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %27 = shl nuw nsw i64 %indvars.iv, 2
  %28 = ashr i64 %23, %27
  %29 = and i64 %28, 15
  %30 = ashr i64 %24, %27
  %31 = and i64 %30, 15
  %.not = icmp eq i64 %29, %31
  br i1 %.not, label %25, label %32

32:                                               ; preds = %26
  %33 = add nuw nsw i64 %29, 1
  %34 = icmp eq i64 %33, %31
  %35 = getelementptr inbounds [10 x [15 x i8]], ptr @str, i64 0, i64 %indvars.iv
  br i1 %34, label %36, label %38

36:                                               ; preds = %32
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull %35)
  br label %.loopexit

38:                                               ; preds = %32
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %35)
  br label %.loopexit

.loopexit:                                        ; preds = %25, %17, %38, %36, %15
  ret void
}

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

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

attributes #0 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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