; LLVM IR from tangjz/acm-icpc :: self_training/2015-09-24/H.ll (Z4pathi)

; 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
@cur_e = external dso_local global ptr, align 8
@cur_match = external dso_local global ptr, align 8
@lx = external dso_local global [51 x i32], align 16
@ly = external dso_local global [51 x i32], align 16
@sx = external dso_local global [51 x i8], align 16
@sy = external dso_local global [51 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4pathi(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [51 x i8], ptr @sx, i64 0, i64 %7
  store i8 1, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %9

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

13:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  br label %67

14:                                               ; preds = %9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [51 x i8], ptr @sy, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9, !range !11, !noundef !12
  %19 = trunc i8 %18 to i1
  br i1 %19, label %39, label %20

20:                                               ; preds = %14
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [51 x i32], ptr @lx, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [51 x i32], ptr @ly, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %24, %28
  %30 = load ptr, ptr @cur_e, align 8, !tbaa !13
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [51 x i32], ptr %30, i64 %32
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [51 x i32], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp ne i32 %29, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %20, %14
  br label %64

40:                                               ; preds = %20
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [51 x i8], ptr @sy, i64 0, i64 %42
  store i8 1, ptr %43, align 1, !tbaa !9
  %44 = load ptr, ptr @cur_match, align 8, !tbaa !13
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %57

50:                                               ; preds = %40
  %51 = load ptr, ptr @cur_match, align 8, !tbaa !13
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = call noundef zeroext i1 @_Z4pathi(i32 noundef %55)
  br i1 %56, label %57, label %63

57:                                               ; preds = %50, %40
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = load ptr, ptr @cur_match, align 8, !tbaa !13
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  store i32 %58, ptr %62, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %67

63:                                               ; preds = %50
  br label %64

64:                                               ; preds = %63, %39
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %4, align 4, !tbaa !5
  br label %9, !llvm.loop !15

67:                                               ; preds = %57, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %68 = load i32, ptr %5, align 4
  switch i32 %68, label %72 [
    i32 2, label %69
    i32 1, label %70
  ]

69:                                               ; preds = %67
  store i1 false, ptr %2, align 1
  br label %70

70:                                               ; preds = %69, %67
  %71 = load i1, ptr %2, align 1
  ret i1 %71

72:                                               ; preds = %67
  unreachable
}

; 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

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 = { 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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
@cur_e = external dso_local local_unnamed_addr global ptr, align 8
@cur_match = external dso_local local_unnamed_addr global ptr, align 8
@lx = external dso_local local_unnamed_addr global [51 x i32], align 16
@ly = external dso_local local_unnamed_addr global [51 x i32], align 16
@sx = external dso_local local_unnamed_addr global [51 x i8], align 16
@sy = external dso_local local_unnamed_addr global [51 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4pathi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [51 x i8], ptr @sx, i64 0, i64 %2
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %.not21 = icmp sgt i32 %4, 0
  br i1 %.not21, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds [51 x i32], ptr @lx, i64 0, i64 %2
  br label %6

6:                                                ; preds = %.lr.ph, %27
  %7 = phi i32 [ %4, %.lr.ph ], [ %28, %27 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %27 ]
  %8 = getelementptr inbounds [51 x i8], ptr @sy, i64 0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !5, !range !11, !noundef !12
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %27, label %11

11:                                               ; preds = %6
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = getelementptr inbounds [51 x i32], ptr @ly, i64 0, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = add nsw i32 %14, %12
  %16 = load ptr, ptr @cur_e, align 8, !tbaa !13
  %17 = getelementptr inbounds [51 x i32], ptr %16, i64 %2, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %.not17 = icmp eq i32 %15, %18
  br i1 %.not17, label %19, label %27

19:                                               ; preds = %11
  store i8 1, ptr %8, align 1, !tbaa !5
  %20 = load ptr, ptr @cur_match, align 8, !tbaa !13
  %21 = getelementptr inbounds i32, ptr %20, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %.not18 = icmp eq i32 %22, 0
  br i1 %.not18, label %split, label %23

23:                                               ; preds = %19
  %24 = tail call noundef zeroext i1 @_Z4pathi(i32 noundef %22)
  br i1 %24, label %._crit_edge, label %._crit_edge26

._crit_edge26:                                    ; preds = %23
  %.pre27 = load i32, ptr @n, align 4, !tbaa !9
  br label %27

._crit_edge:                                      ; preds = %23
  %.pre = load ptr, ptr @cur_match, align 8, !tbaa !13
  br label %split

split:                                            ; preds = %19, %._crit_edge
  %25 = phi ptr [ %.pre, %._crit_edge ], [ %20, %19 ]
  %26 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv
  store i32 %0, ptr %26, align 4, !tbaa !9
  br label %.loopexit

27:                                               ; preds = %._crit_edge26, %6, %11
  %28 = phi i32 [ %.pre27, %._crit_edge26 ], [ %7, %6 ], [ %7, %11 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = sext i32 %28 to i64
  %.not = icmp slt i64 %indvars.iv, %29
  br i1 %.not, label %6, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %27, %1, %split
  %.not20 = phi i1 [ true, %split ], [ false, %1 ], [ false, %27 ]
  ret i1 %.not20
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, 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" }

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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