; LLVM IR from tangjz/acm-icpc :: hdu/6087.ll (Z5Mergeii)

; 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.Treap = type { i32, i32, i32, i32, i64 }

@pool = external dso_local global [2500001 x %struct.Treap], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8Snapshoti(i32 noundef) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5Mergeii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %15, label %11

11:                                               ; preds = %8, %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = or i32 %12, %13
  store i32 %14, ptr %3, align 4
  br label %67

15:                                               ; preds = %8
  %16 = call noundef i32 @_Z5randLv()
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.Treap, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.Treap, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = add nsw i32 %21, %26
  %28 = srem i32 %16, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Treap, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = icmp slt i32 %28, %33
  br i1 %34, label %35, label %51

35:                                               ; preds = %15
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = call noundef i32 @_Z8Snapshoti(i32 noundef %36)
  store i32 %37, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Treap, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !12
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = call noundef i32 @_Z5Mergeii(i32 noundef %42, i32 noundef %43)
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.Treap, ptr %47, i32 0, i32 1
  store i32 %44, ptr %48, align 4, !tbaa !12
  %49 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z8Maintaini(i32 noundef %49)
  %50 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %50, ptr %3, align 4
  br label %67

51:                                               ; preds = %15
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = call noundef i32 @_Z8Snapshoti(i32 noundef %52)
  store i32 %53, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Treap, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !13
  %60 = call noundef i32 @_Z5Mergeii(i32 noundef %54, i32 noundef %59)
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Treap, ptr %63, i32 0, i32 0
  store i32 %60, ptr %64, align 8, !tbaa !13
  %65 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z8Maintaini(i32 noundef %65)
  %66 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %66, ptr %3, align 4
  br label %67

67:                                               ; preds = %51, %35, %11
  %68 = load i32, ptr %3, align 4
  ret i32 %68
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5randLv() #2

attributes #0 = { 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 #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 = { inlinehint 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" }

!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, !6, i64 8}
!10 = !{!"_ZTS5Treap", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !11, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !6, i64 0}


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

%struct.Treap = type { i32, i32, i32, i32, i64 }

@pool = external dso_local local_unnamed_addr global [2500001 x %struct.Treap], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5Mergeii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ne i32 %0, 0
  %4 = icmp ne i32 %1, 0
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %6, label %common.ret

common.ret:                                       ; preds = %2
  %5 = or i32 %1, %0
  br label %common.ret23

6:                                                ; preds = %2
  %7 = tail call noundef i32 @_Z5randLv()
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %8, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %11, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = add nsw i32 %13, %10
  %15 = srem i32 %7, %14
  %16 = icmp slt i32 %15, %10
  br i1 %16, label %17, label %23

common.ret23:                                     ; preds = %23, %17, %common.ret
  %common.ret23.op = phi i32 [ %5, %common.ret ], [ %18, %17 ], [ %24, %23 ]
  ret i32 %common.ret23.op

17:                                               ; preds = %6
  %18 = tail call noundef i32 @_Z8Snapshoti(i32 noundef %0)
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %19, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = tail call noundef i32 @_Z5Mergeii(i32 noundef %21, i32 noundef %1)
  store i32 %22, ptr %20, align 4, !tbaa !11
  tail call void @_Z8Maintaini(i32 noundef %18)
  br label %common.ret23

23:                                               ; preds = %6
  %24 = tail call noundef i32 @_Z8Snapshoti(i32 noundef %1)
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %25
  %27 = load i32, ptr %26, align 8, !tbaa !12
  %28 = tail call noundef i32 @_Z5Mergeii(i32 noundef %0, i32 noundef %27)
  store i32 %28, ptr %26, align 8, !tbaa !12
  tail call void @_Z8Maintaini(i32 noundef %24)
  br label %common.ret23
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5randLv() local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

!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, !7, i64 8}
!6 = !{!"_ZTS5Treap", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass