; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-29/E - Furniture Factory - dby.ll (Z5printv)

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

%struct.Edge = type { i32, i32, ptr, ptr }

@l = external dso_local global [830 x i32], align 16
@r = external dso_local global [830 x i32], align 16
@n = external dso_local global i32, align 4
@first = external dso_local global [830 x ptr], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 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 @_Z5printv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %92, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %95

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 -1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [830 x ptr], ptr @first, i64 0, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %64, %13
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %27

21:                                               ; preds = %18
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.Edge, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp sgt i32 %24, %25
  br label %27

27:                                               ; preds = %21, %18
  %28 = phi i1 [ false, %18 ], [ %26, %21 ]
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %27
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.Edge, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %63

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Edge, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  store i32 %40, ptr %6, align 4, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = icmp eq i32 %41, %43
  br i1 %44, label %45, label %51

45:                                               ; preds = %35
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [830 x i32], ptr @r, i64 0, i64 %49
  store i32 %46, ptr %50, align 4, !tbaa !5
  br label %61

51:                                               ; preds = %35
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [830 x i32], ptr @r, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [830 x i32], ptr @l, i64 0, i64 %57
  store i32 %52, ptr %58, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %51, %45
  %62 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %62, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %63

63:                                               ; preds = %61, %30
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.Edge, ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !14
  store ptr %67, ptr %5, align 8, !tbaa !9
  br label %18, !llvm.loop !15

68:                                               ; preds = %29
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %69)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %87, %68
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = icmp slt i32 %72, %73
  br i1 %74, label %76, label %75

75:                                               ; preds = %71
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %90

76:                                               ; preds = %71
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [830 x i32], ptr @l, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [830 x i32], ptr @r, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %80, i32 noundef %85)
  br label %87

87:                                               ; preds = %76
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %7, align 4, !tbaa !5
  br label %71, !llvm.loop !17

90:                                               ; preds = %75
  %91 = call i32 @puts(ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %92

92:                                               ; preds = %90
  %93 = load i32, ptr %1, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !18

95:                                               ; preds = %12
  ret void
}

declare i32 @printf(ptr noundef, ...) #2

declare i32 @puts(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, !6, i64 0}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !10, i64 8}
!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"

@l = external dso_local local_unnamed_addr global [830 x i32], align 16
@r = external dso_local local_unnamed_addr global [830 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@first = external dso_local local_unnamed_addr global [830 x ptr], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5printv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not41 = icmp slt i32 %1, 1
  br i1 %.not41, label %._crit_edge45, label %.lr.ph44

._crit_edge45:                                    ; preds = %._crit_edge, %0
  ret void

.lr.ph44:                                         ; preds = %0, %._crit_edge
  %indvars.iv47 = phi i64 [ %indvars.iv.next48, %._crit_edge ], [ 1, %0 ]
  %2 = phi i32 [ %29, %._crit_edge ], [ %1, %0 ]
  %3 = getelementptr inbounds [830 x ptr], ptr @first, i64 0, i64 %indvars.iv47
  %.02332 = load ptr, ptr %3, align 8, !tbaa !9
  %.not3133 = icmp eq ptr %.02332, null
  br i1 %.not3133, label %.critedge.thread, label %.lr.ph

.critedge.thread:                                 ; preds = %.lr.ph44
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 0)
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph44, %26
  %.02336 = phi ptr [ %.023, %26 ], [ %.02332, %.lr.ph44 ]
  %.02435 = phi i32 [ %.1, %26 ], [ -1, %.lr.ph44 ]
  %.02534 = phi i32 [ %.2, %26 ], [ 0, %.lr.ph44 ]
  %5 = load i32, ptr %.02336, align 8, !tbaa !11
  %6 = icmp sgt i32 %5, %2
  br i1 %6, label %9, label %.critedge

.critedge:                                        ; preds = %.lr.ph, %26
  %.025.lcssa = phi i32 [ %.02534, %.lr.ph ], [ %.2, %26 ]
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.025.lcssa)
  %8 = icmp sgt i32 %.025.lcssa, 0
  br i1 %8, label %.lr.ph40.preheader, label %._crit_edge

.lr.ph40.preheader:                               ; preds = %.critedge
  %wide.trip.count = zext nneg i32 %.025.lcssa to i64
  br label %.lr.ph40

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.02336, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %26

13:                                               ; preds = %9
  %14 = sub nsw i32 %5, %2
  %15 = add nsw i32 %.02435, 1
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %13
  %18 = add nsw i32 %.02534, -1
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [830 x i32], ptr @r, i64 0, i64 %19
  store i32 %14, ptr %20, align 4, !tbaa !5
  br label %26

21:                                               ; preds = %13
  %22 = sext i32 %.02534 to i64
  %23 = getelementptr inbounds [830 x i32], ptr @r, i64 0, i64 %22
  store i32 %14, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds [830 x i32], ptr @l, i64 0, i64 %22
  store i32 %14, ptr %24, align 4, !tbaa !5
  %25 = add nsw i32 %.02534, 1
  br label %26

26:                                               ; preds = %17, %21, %9
  %.2 = phi i32 [ %.02534, %9 ], [ %.02534, %17 ], [ %25, %21 ]
  %.1 = phi i32 [ %.02435, %9 ], [ %14, %17 ], [ %14, %21 ]
  %27 = getelementptr inbounds i8, ptr %.02336, i64 8
  %.023 = load ptr, ptr %27, align 8, !tbaa !9
  %.not31 = icmp eq ptr %.023, null
  br i1 %.not31, label %.critedge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph40, %.critedge.thread, %.critedge
  %28 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %.not.not = icmp slt i64 %indvars.iv47, %30
  br i1 %.not.not, label %.lr.ph44, label %._crit_edge45, !llvm.loop !16

.lr.ph40:                                         ; preds = %.lr.ph40.preheader, %.lr.ph40
  %indvars.iv = phi i64 [ 0, %.lr.ph40.preheader ], [ %indvars.iv.next, %.lr.ph40 ]
  %31 = getelementptr inbounds [830 x i32], ptr @l, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = getelementptr inbounds [830 x i32], ptr @r, i64 0, i64 %indvars.iv
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %32, i32 noundef %35)
  %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 %._crit_edge, label %.lr.ph40, !llvm.loop !17
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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