; LLVM IR from tangjz/acm-icpc :: codeforces/280D.ll (Z8seg_initii)

; 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 { i8, [2 x ptr] }
%struct.Info = type { i32, i32, i32, i32, i32, i32, i32, i32 }

@tail = external dso_local global ptr, align 8
@seg = external dso_local global [200003 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8seg_initii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = call noundef i32 @_Z7seg_idxii(i32 noundef %9, i32 noundef %10)
  store i32 %11, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.Segment, ptr %14, i32 0, i32 0
  store i8 0, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr @tail, align 8, !tbaa !12
  %17 = getelementptr inbounds %struct.Info, ptr %16, i32 1
  store ptr %17, ptr @tail, align 8, !tbaa !12
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.Segment, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds [2 x ptr], ptr %21, i64 0, i64 0
  store ptr %16, ptr %22, align 8, !tbaa !12
  %23 = load ptr, ptr @tail, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.Info, ptr %23, i32 1
  store ptr %24, ptr @tail, align 8, !tbaa !12
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.Segment, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [2 x ptr], ptr %28, i64 0, i64 1
  store ptr %23, ptr %29, align 8, !tbaa !12
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %67

33:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Segment, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Segment, ptr %41, i32 0, i32 0
  %43 = load i8, ptr %42, align 8, !tbaa !9, !range !14, !noundef !15
  %44 = trunc i8 %43 to i1
  %45 = zext i1 %44 to i64
  %46 = getelementptr inbounds [2 x ptr], ptr %38, i64 0, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !12
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  call void @_ZN4Info4initEii(ptr noundef nonnull align 4 dereferenceable(32) %47, i32 noundef %48, i32 noundef %49)
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.Segment, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.Segment, ptr %56, i32 0, i32 0
  %58 = load i8, ptr %57, align 8, !tbaa !9, !range !14, !noundef !15
  %59 = trunc i8 %58 to i1
  %60 = xor i1 %59, true
  %61 = zext i1 %60 to i64
  %62 = getelementptr inbounds [2 x ptr], ptr %53, i64 0, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !12
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = sub nsw i32 0, %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  call void @_ZN4Info4initEii(ptr noundef nonnull align 4 dereferenceable(32) %63, i32 noundef %65, i32 noundef %66)
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %91

67:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = add nsw i32 %68, %69
  %71 = ashr i32 %70, 1
  store i32 %71, ptr %8, align 4, !tbaa !5
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z8seg_initii(i32 noundef %72, i32 noundef %73)
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z8seg_initii(i32 noundef %75, i32 noundef %76)
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %78
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = call noundef i32 @_Z7seg_idxii(i32 noundef %80, i32 noundef %81)
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %83
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = call noundef i32 @_Z7seg_idxii(i32 noundef %86, i32 noundef %87)
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %89
  call void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24) %79, ptr noundef nonnull align 8 dereferenceable(24) %84, ptr noundef nonnull align 8 dereferenceable(24) %90)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  store i32 0, ptr %7, align 4
  br label %91

91:                                               ; preds = %67, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %92 = load i32, ptr %7, align 4
  switch i32 %92, label %94 [
    i32 0, label %93
    i32 1, label %93
  ]

93:                                               ; preds = %91, %91
  ret void

94:                                               ; preds = %91
  unreachable
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Info4initEii(ptr noundef nonnull align 4 dereferenceable(32), i32 noundef, i32 noundef) #4 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #5

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 = { 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" }
attributes #3 = { "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 = { 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 #5 = { inlinehint 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 #6 = { 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, !11, i64 0}
!10 = !{!"_ZTS7Segment", !11, i64 0, !7, i64 8}
!11 = !{!"bool", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}


; 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 { i8, [2 x ptr] }

@tail = external dso_local local_unnamed_addr global ptr, align 8
@seg = external dso_local global [200003 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8seg_initii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %5
  store i8 0, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr @tail, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %7, i64 32
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %7, ptr %9, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %7, i64 64
  store ptr %10, ptr @tail, align 8, !tbaa !10
  %11 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %8, ptr %11, align 8, !tbaa !10
  %12 = icmp eq i32 %0, %1
  br i1 %12, label %common.ret, label %26

common.ret:                                       ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %14 = load i8, ptr %6, align 8, !tbaa !5, !range !12, !noundef !13
  %15 = zext nneg i8 %14 to i64
  %16 = getelementptr inbounds [2 x ptr], ptr %9, i64 0, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !10
  %18 = load i32, ptr %3, align 4, !tbaa !14
  call void @_ZN4Info4initEii(ptr noundef nonnull align 4 dereferenceable(32) %17, i32 noundef %18, i32 noundef %0)
  %19 = load i8, ptr %6, align 8, !tbaa !5, !range !12, !noundef !13
  %20 = xor i8 %19, 1
  %21 = zext nneg i8 %20 to i64
  %22 = getelementptr inbounds [2 x ptr], ptr %9, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !10
  %24 = load i32, ptr %3, align 4, !tbaa !14
  %25 = sub nsw i32 0, %24
  call void @_ZN4Info4initEii(ptr noundef nonnull align 4 dereferenceable(32) %23, i32 noundef %25, i32 noundef %0)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  br label %common.ret25

common.ret25:                                     ; preds = %26, %common.ret
  ret void

26:                                               ; preds = %2
  %27 = add nsw i32 %1, %0
  %28 = ashr i32 %27, 1
  tail call void @_Z8seg_initii(i32 noundef %0, i32 noundef %28)
  %29 = add nsw i32 %28, 1
  tail call void @_Z8seg_initii(i32 noundef %29, i32 noundef %1)
  %30 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %28)
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %31
  %33 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %29, i32 noundef %1)
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %34
  tail call void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %32, ptr noundef nonnull align 8 dereferenceable(24) %35)
  br label %common.ret25
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Info4initEii(ptr noundef nonnull align 4 dereferenceable(32), i32 noundef, i32 noundef) local_unnamed_addr #4 align 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: inlinehint mustprogress uwtable
declare dso_local void @_Z6seg_upR7SegmentS0_S0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #5

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { 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 #4 = { 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 #5 = { inlinehint 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 #6 = { 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, !8, i64 8}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !8, i64 0}


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