; LLVM IR from tangjz/acm-icpc :: poj (1338)

; 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
@pos = external dso_local global [3 x i32], align 4
@ans = external dso_local global [1500 x i32], align 16
@_ZL4fact = external hidden constant [3 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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 i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr @ans, align 16, !tbaa !5
  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 = %96, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 1500
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %99

10:                                               ; preds = %6
  %11 = load i32, ptr @pos, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr @_ZL4fact, align 4, !tbaa !5
  %16 = mul nsw i32 %14, %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !5
  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 = %59, %10
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 3
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %62

24:                                               ; preds = %20
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [3 x i32], ptr @pos, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [3 x i32], ptr @_ZL4fact, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = mul nsw i32 %35, %39
  %41 = icmp sgt i32 %28, %40
  br i1 %41, label %42, label %58

42:                                               ; preds = %24
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [3 x i32], ptr @pos, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [3 x i32], ptr @_ZL4fact, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = mul nsw i32 %49, %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %56
  store i32 %54, ptr %57, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %42, %24
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !9

62:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %92, %62
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = icmp slt i32 %64, 3
  br i1 %65, label %67, label %66

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

67:                                               ; preds = %63
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [3 x i32], ptr @pos, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [3 x i32], ptr @_ZL4fact, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = mul nsw i32 %78, %82
  %84 = icmp eq i32 %71, %83
  br i1 %84, label %85, label %91

85:                                               ; preds = %67
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [3 x i32], ptr @pos, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %88, align 4, !tbaa !5
  br label %91

91:                                               ; preds = %85, %67
  br label %92

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

95:                                               ; preds = %66
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !12

99:                                               ; preds = %9
  br label %100

100:                                              ; preds = %108, %99
  %101 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %102 = icmp ne i32 %101, -1
  br i1 %102, label %103, label %106

103:                                              ; preds = %100
  %104 = load i32, ptr @n, align 4, !tbaa !5
  %105 = icmp ne i32 %104, 0
  br label %106

106:                                              ; preds = %103, %100
  %107 = phi i1 [ false, %100 ], [ %105, %103 ]
  br i1 %107, label %108, label %115

108:                                              ; preds = %106
  %109 = load i32, ptr @n, align 4, !tbaa !5
  %110 = sub nsw i32 %109, 1
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %111
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %113)
  br label %100, !llvm.loop !13

115:                                              ; preds = %106
  ret i32 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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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
@pos = external dso_local local_unnamed_addr global [3 x i32], align 4
@ans = external dso_local local_unnamed_addr global [1500 x i32], align 16
@_ZL4fact = external hidden local_unnamed_addr constant [3 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  store i32 1, ptr @ans, align 16, !tbaa !5
  %1 = load i32, ptr @_ZL4fact, align 4, !tbaa !5
  %.pre = load i32, ptr @pos, align 4, !tbaa !5
  %.pre28 = load i32, ptr getelementptr inbounds (i8, ptr @pos, i64 4), align 4, !tbaa !5
  %.pre29 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL4fact, i64 4), align 4, !tbaa !5
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL4fact, i64 8), align 4, !tbaa !5
  %.promoted = load i32, ptr getelementptr inbounds (i8, ptr @pos, i64 8), align 4, !tbaa !5
  br label %.preheader21

.preheader:                                       ; preds = %44
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = icmp ne i32 %3, -1
  %5 = load i32, ptr @n, align 4
  %6 = icmp ne i32 %5, 0
  %7 = select i1 %4, i1 %6, i1 false
  br i1 %7, label %.lr.ph, label %._crit_edge

.preheader21:                                     ; preds = %0, %44
  %8 = phi i32 [ %.promoted, %0 ], [ %45, %44 ]
  %9 = phi i32 [ %.pre28, %0 ], [ %38, %44 ]
  %10 = phi i32 [ %.pre, %0 ], [ %31, %44 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next, %44 ]
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = mul nsw i32 %1, %13
  %15 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %indvars.iv
  store i32 %14, ptr %15, align 4, !tbaa !5
  %16 = sext i32 %9 to i64
  %17 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = mul nsw i32 %.pre29, %18
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %14, i32 %19)
  store i32 %spec.store.select, ptr %15, align 4
  %spec.select = tail call i32 @llvm.smin.i32(i32 %14, i32 %19)
  %20 = sext i32 %8 to i64
  %21 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = mul nsw i32 %2, %22
  %24 = icmp sgt i32 %spec.select, %23
  %spec.store.select30 = select i1 %24, i32 %23, i32 %spec.store.select
  store i32 %spec.store.select30, ptr %15, align 4
  %spec.select31 = tail call i32 @llvm.smin.i32(i32 %spec.select, i32 %23)
  %25 = load i32, ptr %12, align 4, !tbaa !5
  %26 = mul nsw i32 %1, %25
  %27 = icmp eq i32 %spec.select31, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %.preheader21
  %29 = add nsw i32 %10, 1
  store i32 %29, ptr @pos, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.preheader21, %28
  %31 = phi i32 [ %10, %.preheader21 ], [ %29, %28 ]
  %32 = load i32, ptr %17, align 4, !tbaa !5
  %33 = mul nsw i32 %.pre29, %32
  %34 = icmp eq i32 %spec.select31, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %30
  %36 = add nsw i32 %9, 1
  store i32 %36, ptr getelementptr inbounds (i8, ptr @pos, i64 4), align 4, !tbaa !5
  br label %37

37:                                               ; preds = %35, %30
  %38 = phi i32 [ %36, %35 ], [ %9, %30 ]
  %39 = load i32, ptr %21, align 4, !tbaa !5
  %40 = mul nsw i32 %2, %39
  %41 = icmp eq i32 %spec.select31, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %37
  %43 = add nsw i32 %8, 1
  store i32 %43, ptr getelementptr inbounds (i8, ptr @pos, i64 8), align 4, !tbaa !5
  br label %44

44:                                               ; preds = %42, %37
  %45 = phi i32 [ %43, %42 ], [ %8, %37 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1500
  br i1 %exitcond.not, label %.preheader, label %.preheader21, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %46 = phi i32 [ %54, %.lr.ph ], [ %5, %.preheader ]
  %47 = add nsw i32 %46, -1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1500 x i32], ptr @ans, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %50)
  %52 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %53 = icmp ne i32 %52, -1
  %54 = load i32, ptr @n, align 4
  %55 = icmp ne i32 %54, 0
  %56 = select i1 %53, i1 %55, i1 false
  br i1 %56, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !10}


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