; LLVM IR from tangjz/acm-icpc :: 51nod/1152.ll (Z10num_to_seqi)

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

@seq = external dso_local global [9 x i32], align 16
@low = external dso_local global [9 x i32], align 16
@upp = external dso_local global [9 x i32], align 16

; 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 nounwind uwtable
define dso_local void @_Z10num_to_seqi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %17, %1
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 7
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %12
  store i32 -1, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %15
  store i32 -1, ptr %16, align 4, !tbaa !5
  br label %17

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

20:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 5, ptr %4, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %47, %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp sge i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %50

25:                                               ; preds = %21
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = srem i32 %26, 7
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [9 x i32], ptr @seq, i64 0, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sdiv i32 %31, 7
  store i32 %32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [9 x i32], ptr @seq, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %46

38:                                               ; preds = %25
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [9 x i32], ptr @seq, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %44
  store i32 %39, ptr %45, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %38, %25
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %4, align 4, !tbaa !5
  br label %21, !llvm.loop !11

50:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %70, %50
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = icmp slt i32 %52, 6
  br i1 %53, label %55, label %54

54:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %73

55:                                               ; preds = %51
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [9 x i32], ptr @seq, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %69

61:                                               ; preds = %55
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [9 x i32], ptr @seq, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %67
  store i32 %62, ptr %68, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %61, %55
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %5, align 4, !tbaa !5
  br label %51, !llvm.loop !12

73:                                               ; preds = %54
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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}


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

@seq = external dso_local local_unnamed_addr global [9 x i32], align 16
@low = external dso_local local_unnamed_addr global [9 x i32], align 16
@upp = external dso_local local_unnamed_addr global [9 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z10num_to_seqi(i32 noundef %0) local_unnamed_addr #0 {
.preheader23.preheader:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) getelementptr inbounds (i8, ptr @upp, i64 4), i8 -1, i64 24, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) getelementptr inbounds (i8, ptr @low, i64 4), i8 -1, i64 24, i1 false), !tbaa !5
  %1 = srem i32 %0, 7
  store i32 %1, ptr getelementptr inbounds (i8, ptr @seq, i64 20), align 4, !tbaa !5
  %2 = sdiv i32 %0, 7
  %.not22 = icmp eq i32 %1, 0
  br i1 %.not22, label %.preheader23.1, label %3

3:                                                ; preds = %.preheader23.preheader
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %4
  store i32 5, ptr %5, align 4, !tbaa !5
  br label %.preheader23.1

.preheader23.1:                                   ; preds = %.preheader23.preheader, %3
  %6 = srem i32 %2, 7
  store i32 %6, ptr getelementptr inbounds (i8, ptr @seq, i64 16), align 16, !tbaa !5
  %7 = sdiv i32 %0, 49
  %.not22.1 = icmp eq i32 %6, 0
  br i1 %.not22.1, label %.preheader23.2, label %8

8:                                                ; preds = %.preheader23.1
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %9
  store i32 4, ptr %10, align 4, !tbaa !5
  br label %.preheader23.2

.preheader23.2:                                   ; preds = %8, %.preheader23.1
  %11 = srem i32 %7, 7
  store i32 %11, ptr getelementptr inbounds (i8, ptr @seq, i64 12), align 4, !tbaa !5
  %12 = sdiv i32 %0, 343
  %.not22.2 = icmp eq i32 %11, 0
  br i1 %.not22.2, label %.preheader23.3, label %13

13:                                               ; preds = %.preheader23.2
  %14 = sext i32 %11 to i64
  %15 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %14
  store i32 3, ptr %15, align 4, !tbaa !5
  br label %.preheader23.3

.preheader23.3:                                   ; preds = %13, %.preheader23.2
  %16 = srem i32 %12, 7
  store i32 %16, ptr getelementptr inbounds (i8, ptr @seq, i64 8), align 8, !tbaa !5
  %17 = sdiv i32 %0, 2401
  %.not22.3 = icmp eq i32 %16, 0
  br i1 %.not22.3, label %.preheader23.4, label %18

18:                                               ; preds = %.preheader23.3
  %19 = sext i32 %16 to i64
  %20 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %19
  store i32 2, ptr %20, align 4, !tbaa !5
  br label %.preheader23.4

.preheader23.4:                                   ; preds = %18, %.preheader23.3
  %21 = srem i32 %17, 7
  store i32 %21, ptr getelementptr inbounds (i8, ptr @seq, i64 4), align 4, !tbaa !5
  %22 = sdiv i32 %0, 16807
  %.not22.4 = icmp eq i32 %21, 0
  br i1 %.not22.4, label %.preheader23.5, label %23

23:                                               ; preds = %.preheader23.4
  %24 = sext i32 %21 to i64
  %25 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %24
  store i32 1, ptr %25, align 4, !tbaa !5
  br label %.preheader23.5

.preheader23.5:                                   ; preds = %23, %.preheader23.4
  %26 = srem i32 %22, 7
  store i32 %26, ptr @seq, align 16, !tbaa !5
  %.not22.5 = icmp eq i32 %26, 0
  br i1 %.not22.5, label %.preheader.1, label %27

27:                                               ; preds = %.preheader23.5
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [9 x i32], ptr @low, i64 0, i64 %28
  store i32 0, ptr %29, align 4, !tbaa !5
  %30 = sext i32 %26 to i64
  %31 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %30
  store i32 0, ptr %31, align 4, !tbaa !5
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader23.5, %27
  br i1 %.not22.4, label %.preheader.2, label %32

32:                                               ; preds = %.preheader.1
  %33 = sext i32 %21 to i64
  %34 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %33
  store i32 1, ptr %34, align 4, !tbaa !5
  br label %.preheader.2

.preheader.2:                                     ; preds = %32, %.preheader.1
  br i1 %.not22.3, label %.preheader.3, label %35

35:                                               ; preds = %.preheader.2
  %36 = sext i32 %16 to i64
  %37 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %36
  store i32 2, ptr %37, align 4, !tbaa !5
  br label %.preheader.3

.preheader.3:                                     ; preds = %35, %.preheader.2
  br i1 %.not22.2, label %.preheader.4, label %38

38:                                               ; preds = %.preheader.3
  %39 = sext i32 %11 to i64
  %40 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %39
  store i32 3, ptr %40, align 4, !tbaa !5
  br label %.preheader.4

.preheader.4:                                     ; preds = %38, %.preheader.3
  br i1 %.not22.1, label %.preheader.5, label %41

41:                                               ; preds = %.preheader.4
  %42 = sext i32 %6 to i64
  %43 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %42
  store i32 4, ptr %43, align 4, !tbaa !5
  br label %.preheader.5

.preheader.5:                                     ; preds = %41, %.preheader.4
  br i1 %.not22, label %47, label %44

44:                                               ; preds = %.preheader.5
  %45 = sext i32 %1 to i64
  %46 = getelementptr inbounds [9 x i32], ptr @upp, i64 0, i64 %45
  store i32 5, ptr %46, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %44, %.preheader.5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }

!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"}


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