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

; 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] }

@tot = external dso_local global i32, align 4
@__ = external dso_local global [262144 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Segment4initEii(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.Segment, align 8
  %9 = 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
  %10 = load ptr, ptr %4, align 8
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 0
  store i32 %11, ptr %12, align 8, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 1
  store i32 %13, ptr %14, align 4, !tbaa !13
  %15 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = add nsw i32 %16, %18
  %20 = ashr i32 %19, 1
  %21 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 2
  store i32 %20, ptr %21, align 8, !tbaa !14
  %22 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp eq i32 %23, %25
  br i1 %26, label %27, label %39

27:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %7)
  %29 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 3
  %30 = getelementptr inbounds [4 x i64], ptr %29, i64 0, i64 2
  store i64 -1061109567, ptr %30, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 3
  %32 = getelementptr inbounds [4 x i64], ptr %31, i64 0, i64 1
  store i64 -1061109567, ptr %32, align 8, !tbaa !15
  %33 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 3
  %34 = getelementptr inbounds [4 x i64], ptr %33, i64 0, i64 0
  store i64 -1061109567, ptr %34, align 8, !tbaa !15
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 3
  %38 = getelementptr inbounds [4 x i64], ptr %37, i64 0, i64 3
  store i64 %36, ptr %38, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %73

39:                                               ; preds = %3
  %40 = load i32, ptr @tot, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @tot, align 4, !tbaa !9
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds %struct.Segment, ptr @__, i64 %42
  %44 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 4
  %45 = getelementptr inbounds [2 x ptr], ptr %44, i64 0, i64 0
  store ptr %43, ptr %45, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 4
  %47 = getelementptr inbounds [2 x ptr], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !14
  call void @_ZN7Segment4initEii(ptr noundef nonnull align 8 dereferenceable(64) %48, i32 noundef %50, i32 noundef %52)
  %53 = load i32, ptr @tot, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr @tot, align 4, !tbaa !9
  %55 = sext i32 %53 to i64
  %56 = getelementptr inbounds %struct.Segment, ptr @__, i64 %55
  %57 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 4
  %58 = getelementptr inbounds [2 x ptr], ptr %57, i64 0, i64 1
  store ptr %56, ptr %58, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 4
  %60 = getelementptr inbounds [2 x ptr], ptr %59, i64 0, i64 1
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !14
  %64 = add nsw i32 %63, 1
  %65 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !13
  call void @_ZN7Segment4initEii(ptr noundef nonnull align 8 dereferenceable(64) %61, i32 noundef %64, i32 noundef %66)
  %67 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 4
  %68 = getelementptr inbounds [2 x ptr], ptr %67, i64 0, i64 0
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %69, i64 64, i1 false), !tbaa.struct !17
  %70 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 4
  %71 = getelementptr inbounds [2 x ptr], ptr %70, i64 0, i64 1
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %72, i64 64, i1 false), !tbaa.struct !17
  call void @_ZN7Segment5mergeES_S_(ptr noundef nonnull align 8 dereferenceable(64) %10, ptr noundef byval(%struct.Segment) align 8 %8, ptr noundef byval(%struct.Segment) align 8 %9)
  br label %73

73:                                               ; preds = %39, %27
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; 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) #3 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) #4

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 = { "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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"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 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!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] }

@tot = external dso_local local_unnamed_addr global i32, align 4
@__ = external dso_local global [262144 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7Segment4initEii(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = alloca i32, align 4
  store i32 %1, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %5, align 4, !tbaa !10
  %6 = add nsw i32 %2, %1
  %7 = ashr i32 %6, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %7, ptr %8, align 8, !tbaa !11
  %9 = icmp eq i32 %1, %2
  br i1 %9, label %common.ret, label %17

common.ret:                                       ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 -1061109567, ptr %12, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 -1061109567, ptr %13, align 8, !tbaa !12
  store i64 -1061109567, ptr %11, align 8, !tbaa !12
  %14 = load i32, ptr %4, align 4, !tbaa !14
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %15, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %common.ret2

common.ret2:                                      ; preds = %17, %common.ret
  ret void

17:                                               ; preds = %3
  %18 = load i32, ptr @tot, align 4, !tbaa !14
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @tot, align 4, !tbaa !14
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds %struct.Segment, ptr @__, i64 %20
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %21, ptr %22, align 8, !tbaa !15
  %23 = load i32, ptr %0, align 8, !tbaa !5
  tail call void @_ZN7Segment4initEii(ptr noundef nonnull align 8 dereferenceable(64) %21, i32 noundef %23, i32 noundef %7)
  %24 = load i32, ptr @tot, align 4, !tbaa !14
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @tot, align 4, !tbaa !14
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds %struct.Segment, ptr @__, i64 %26
  %28 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %27, ptr %28, align 8, !tbaa !15
  %29 = load i32, ptr %8, align 8, !tbaa !11
  %30 = add nsw i32 %29, 1
  %31 = load i32, ptr %5, align 4, !tbaa !10
  tail call void @_ZN7Segment4initEii(ptr noundef nonnull align 8 dereferenceable(64) %27, i32 noundef %30, i32 noundef %31)
  %32 = load ptr, ptr %22, align 8, !tbaa !15
  %33 = load ptr, ptr %28, align 8, !tbaa !15
  tail call void @_ZN7Segment5mergeES_S_(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull byval(%struct.Segment) align 8 %32, ptr noundef nonnull byval(%struct.Segment) align 8 %33)
  br label %common.ret2
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; 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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !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 = !{!6, !7, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !8, i64 0}


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