; LLVM IR from tangjz/acm-icpc :: usaco/Training/Chapter 6 Contest Practice (clocks)

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

@data = external dso_local global [9 x i32], align 16
@ans = external dso_local global [1001 x i32], align 16
@len = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #0

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

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

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

7:                                                ; preds = %24, %0
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 9
  br i1 %9, label %10, label %27

10:                                               ; preds = %7
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [9 x i32], ptr @data, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %13)
  %15 = load i32, ptr %2, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [9 x i32], ptr @data, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = sdiv i32 %18, 3
  %20 = and i32 %19, 3
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [9 x i32], ptr @data, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %10
  %25 = load i32, ptr %2, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !9
  br label %7, !llvm.loop !11

27:                                               ; preds = %7
  call void @_Z3dfsi(i32 noundef 1)
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %38, %27
  %29 = load i32, ptr %2, align 4, !tbaa !9
  %30 = load i32, ptr @len, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %41

32:                                               ; preds = %28
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1001 x i32], ptr @ans, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %36)
  br label %38

38:                                               ; preds = %32
  %39 = load i32, ptr %2, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %2, align 4, !tbaa !9
  br label %28, !llvm.loop !13

41:                                               ; preds = %28
  %42 = load i32, ptr @len, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1001 x i32], ptr @ans, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %45)
  %47 = load ptr, ptr @stdin, align 8, !tbaa !5
  %48 = call i32 @fclose(ptr noundef %47)
  %49 = load ptr, ptr @stdout, align 8, !tbaa !5
  %50 = call i32 @fclose(ptr noundef %49)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

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

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

declare i32 @fclose(ptr noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@data = external dso_local global [9 x i32], align 16
@ans = external dso_local local_unnamed_addr global [1001 x i32], align 16
@len = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = load ptr, ptr @stdin, align 8, !tbaa !5
  %2 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %1)
  %3 = load ptr, ptr @stdout, align 8, !tbaa !5
  %4 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %3)
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull @data)
  %6 = load i32, ptr @data, align 16, !tbaa !9
  %7 = sdiv i32 %6, 3
  %8 = and i32 %7, 3
  store i32 %8, ptr @data, align 16, !tbaa !9
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 4))
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 4), align 4, !tbaa !9
  %11 = sdiv i32 %10, 3
  %12 = and i32 %11, 3
  store i32 %12, ptr getelementptr inbounds (i8, ptr @data, i64 4), align 4, !tbaa !9
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 8))
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 8), align 8, !tbaa !9
  %15 = sdiv i32 %14, 3
  %16 = and i32 %15, 3
  store i32 %16, ptr getelementptr inbounds (i8, ptr @data, i64 8), align 8, !tbaa !9
  %17 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 12))
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 12), align 4, !tbaa !9
  %19 = sdiv i32 %18, 3
  %20 = and i32 %19, 3
  store i32 %20, ptr getelementptr inbounds (i8, ptr @data, i64 12), align 4, !tbaa !9
  %21 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 16))
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 16), align 16, !tbaa !9
  %23 = sdiv i32 %22, 3
  %24 = and i32 %23, 3
  store i32 %24, ptr getelementptr inbounds (i8, ptr @data, i64 16), align 16, !tbaa !9
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 20))
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 20), align 4, !tbaa !9
  %27 = sdiv i32 %26, 3
  %28 = and i32 %27, 3
  store i32 %28, ptr getelementptr inbounds (i8, ptr @data, i64 20), align 4, !tbaa !9
  %29 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 24))
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 24), align 8, !tbaa !9
  %31 = sdiv i32 %30, 3
  %32 = and i32 %31, 3
  store i32 %32, ptr getelementptr inbounds (i8, ptr @data, i64 24), align 8, !tbaa !9
  %33 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 28))
  %34 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 28), align 4, !tbaa !9
  %35 = sdiv i32 %34, 3
  %36 = and i32 %35, 3
  store i32 %36, ptr getelementptr inbounds (i8, ptr @data, i64 28), align 4, !tbaa !9
  %37 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull getelementptr inbounds (i8, ptr @data, i64 32))
  %38 = load i32, ptr getelementptr inbounds (i8, ptr @data, i64 32), align 16, !tbaa !9
  %39 = sdiv i32 %38, 3
  %40 = and i32 %39, 3
  store i32 %40, ptr getelementptr inbounds (i8, ptr @data, i64 32), align 16, !tbaa !9
  tail call void @_Z3dfsi(i32 noundef 1)
  %41 = load i32, ptr @len, align 4, !tbaa !9
  %42 = icmp sgt i32 %41, 1
  br i1 %42, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %41 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %43 = getelementptr inbounds [1001 x i32], ptr @ans, i64 0, i64 %indvars.iv
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %44)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %46 = load i32, ptr @len, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = icmp slt i64 %indvars.iv.next, %47
  br i1 %48, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %47, %.lr.ph ]
  %49 = getelementptr inbounds [1001 x i32], ptr @ans, i64 0, i64 %.pre-phi
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %50)
  %52 = load ptr, ptr @stdin, align 8, !tbaa !5
  %53 = tail call i32 @fclose(ptr noundef %52)
  %54 = load ptr, ptr @stdout, align 8, !tbaa !5
  %55 = tail call i32 @fclose(ptr noundef %54)
  ret i32 0
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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