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

; 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.Segment = type { i32, i32, i32, [4 x i64], [2 x ptr] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7Segment5mergeES_S_(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef byval(%struct.Segment) align 8, ptr noundef byval(%struct.Segment) align 8) #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Segment6updateEii(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Segment, align 8
  %8 = alloca %struct.Segment, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 3
  %19 = getelementptr inbounds [4 x i64], ptr %18, i64 0, i64 3
  store i64 %17, ptr %19, align 8, !tbaa !14
  br label %44

20:                                               ; preds = %3
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = icmp sle i32 %21, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %20
  %26 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 4
  %27 = getelementptr inbounds [2 x ptr], ptr %26, i64 0, i64 0
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN7Segment6updateEii(ptr noundef nonnull align 8 dereferenceable(64) %28, i32 noundef %29, i32 noundef %30)
  br label %37

31:                                               ; preds = %20
  %32 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 4
  %33 = getelementptr inbounds [2 x ptr], ptr %32, i64 0, i64 1
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN7Segment6updateEii(ptr noundef nonnull align 8 dereferenceable(64) %34, i32 noundef %35, i32 noundef %36)
  br label %37

37:                                               ; preds = %31, %25
  %38 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 4
  %39 = getelementptr inbounds [2 x ptr], ptr %38, i64 0, i64 0
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %40, i64 64, i1 false), !tbaa.struct !17
  %41 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 4
  %42 = getelementptr inbounds [2 x ptr], ptr %41, i64 0, i64 1
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %43, i64 64, i1 false), !tbaa.struct !17
  call void @_ZN7Segment5mergeES_S_(ptr noundef nonnull align 8 dereferenceable(64) %9, ptr noundef byval(%struct.Segment) align 8 %7, ptr noundef byval(%struct.Segment) align 8 %8)
  br label %44

44:                                               ; preds = %37, %15
  ret void
}

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

!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 = !{!12, !10, i64 0}
!12 = !{!"_ZTS7Segment", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 16, !7, i64 48}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!12, !10, i64 8}
!17 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 16, i64 32, !18, i64 48, i64 16, !18}
!18 = !{!7, !7, 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.Segment = type { i32, i32, i32, [4 x i64], [2 x ptr] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7Segment5mergeES_S_(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef byval(%struct.Segment) align 8, ptr noundef byval(%struct.Segment) align 8) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7Segment6updateEii(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !10
  %7 = icmp eq i32 %4, %6
  br i1 %7, label %8, label %11

8:                                                ; preds = %3
  %9 = sext i32 %2 to i64
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %9, ptr %10, align 8, !tbaa !11
  br label %common.ret

common.ret:                                       ; preds = %8, %11
  ret void

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %.not = icmp slt i32 %13, %1
  %. = select i1 %.not, i64 56, i64 48
  %14 = getelementptr inbounds i8, ptr %0, i64 %.
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  tail call void @_ZN7Segment6updateEii(ptr noundef nonnull align 8 dereferenceable(64) %15, i32 noundef %1, i32 noundef %2)
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %0, i64 56
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  tail call void @_ZN7Segment5mergeES_S_(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull byval(%struct.Segment) align 8 %17, ptr noundef nonnull byval(%struct.Segment) align 8 %19)
  br label %common.ret
}

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

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass