; LLVM IR from VastoLorde95/Competitive-Programming :: Codejam/2017/Qualification/D/D.ll (Z4flipiii)

; 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
@row = external dso_local global { [2 x i64] }, align 8
@col = external dso_local global { [2 x i64] }, align 8
@d1 = external dso_local global { [4 x i64] }, align 8
@d2 = external dso_local global { [4 x i64] }, align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4flipiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %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 %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %14, label %11

11:                                               ; preds = %3
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 3
  br i1 %13, label %14, label %29

14:                                               ; preds = %11, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sub nsw i32 %15, %16
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = add nsw i32 %17, %18
  store i32 %19, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = add nsw i32 %20, %21
  store i32 %22, ptr %8, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6bitsetILm220EE4flipEm(ptr noundef nonnull align 8 dereferenceable(32) @d1, i64 noundef %24)
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6bitsetILm220EE4flipEm(ptr noundef nonnull align 8 dereferenceable(32) @d2, i64 noundef %27)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %43

29:                                               ; preds = %11
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 3
  br i1 %34, label %35, label %42

35:                                               ; preds = %32, %29
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm110EE4flipEm(ptr noundef nonnull align 8 dereferenceable(16) @row, i64 noundef %37)
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm110EE4flipEm(ptr noundef nonnull align 8 dereferenceable(16) @col, i64 noundef %40)
  br label %42

42:                                               ; preds = %35, %32
  br label %43

43:                                               ; preds = %42, %14
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6bitsetILm220EE4flipEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm110EE4flipEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #1 align 2

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


; 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
@row = external dso_local global { [2 x i64] }, align 8
@col = external dso_local global { [2 x i64] }, align 8
@d1 = external dso_local global { [4 x i64] }, align 8
@d2 = external dso_local global { [4 x i64] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4flipiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = and i32 %2, -3
  %or.cond = icmp eq i32 %4, 1
  br i1 %or.cond, label %5, label %14

5:                                                ; preds = %3
  %6 = sub i32 %0, %1
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = add nsw i32 %6, %7
  %9 = add nsw i32 %1, %0
  %10 = sext i32 %8 to i64
  %11 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6bitsetILm220EE4flipEm(ptr noundef nonnull align 8 dereferenceable(32) @d1, i64 noundef %10)
  %12 = sext i32 %9 to i64
  %13 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6bitsetILm220EE4flipEm(ptr noundef nonnull align 8 dereferenceable(32) @d2, i64 noundef %12)
  br label %21

14:                                               ; preds = %3
  %15 = icmp eq i32 %2, 2
  br i1 %15, label %16, label %21

16:                                               ; preds = %14
  %17 = sext i32 %0 to i64
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm110EE4flipEm(ptr noundef nonnull align 8 dereferenceable(16) @row, i64 noundef %17)
  %19 = sext i32 %1 to i64
  %20 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm110EE4flipEm(ptr noundef nonnull align 8 dereferenceable(16) @col, i64 noundef %19)
  br label %21

21:                                               ; preds = %16, %14, %5
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6bitsetILm220EE4flipEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm110EE4flipEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #0 align 2

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

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


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