; LLVM IR from alekmaul/pvsneslib :: snes-examples/graphics/Backgrounds/Mode1ContinuosScroll (Mode1ContinuosScroll)

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

; Function Attrs: nounwind uwtable
define dso_local void @updatePos(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %5 = load i16, ptr %4, align 2, !tbaa !9
  %6 = zext i16 %5 to i32
  %7 = and i32 %6, 2048
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %14

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.character, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = sub nsw i32 %12, 2
  store i32 %13, ptr %11, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %9, %2
  %15 = load i16, ptr %4, align 2, !tbaa !9
  %16 = zext i16 %15 to i32
  %17 = and i32 %16, 1024
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %14
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.character, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = add nsw i32 %22, 2
  store i32 %23, ptr %21, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %19, %14
  %25 = load i16, ptr %4, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = and i32 %26, 512
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %34

29:                                               ; preds = %24
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.character, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = sub nsw i32 %32, 2
  store i32 %33, ptr %31, align 4, !tbaa !14
  br label %34

34:                                               ; preds = %29, %24
  %35 = load i16, ptr %4, align 2, !tbaa !9
  %36 = zext i16 %35 to i32
  %37 = and i32 %36, 256
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %34
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.character, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = add nsw i32 %42, 2
  store i32 %43, ptr %41, align 4, !tbaa !14
  br label %44

44:                                               ; preds = %39, %34
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.character, ptr %45, i32 0, i32 0
  %47 = load i8, ptr %46, align 4, !tbaa !15
  %48 = zext i8 %47 to i16
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.character, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !14
  %52 = trunc i32 %51 to i16
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.character, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = trunc i32 %55 to i16
  call void @oamSetXY(i16 noundef zeroext %48, i16 noundef zeroext %52, i16 noundef zeroext %56)
  ret void
}

declare void @oamSetXY(i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) #1

attributes #0 = { 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"", !7, i64 0, !13, i64 4, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{!12, !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"

; Function Attrs: nounwind uwtable
define dso_local void @updatePos(ptr nocapture noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext i16 %1 to i32
  %4 = and i32 %3, 2048
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %9, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = add nsw i32 %7, -2
  store i32 %8, ptr %6, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %5, %2
  %10 = and i32 %3, 1024
  %.not10 = icmp eq i32 %10, 0
  br i1 %.not10, label %15, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, 2
  store i32 %14, ptr %12, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %11, %9
  %16 = and i32 %3, 512
  %.not11 = icmp eq i32 %16, 0
  br i1 %.not11, label %21, label %17

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = add nsw i32 %19, -2
  store i32 %20, ptr %18, align 4, !tbaa !10
  br label %21

21:                                               ; preds = %17, %15
  %22 = and i32 %3, 256
  %.not12 = icmp eq i32 %22, 0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  br i1 %.not12, label %._crit_edge, label %23

23:                                               ; preds = %21
  %24 = add nsw i32 %.pre, 2
  store i32 %24, ptr %.phi.trans.insert, align 4, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %21, %23
  %25 = phi i32 [ %24, %23 ], [ %.pre, %21 ]
  %26 = load i8, ptr %0, align 4, !tbaa !11
  %27 = zext i8 %26 to i16
  %28 = trunc i32 %25 to i16
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = trunc i32 %30 to i16
  tail call void @oamSetXY(i16 noundef zeroext %27, i16 noundef zeroext %28, i16 noundef zeroext %31) #2
  ret void
}

declare void @oamSetXY(i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

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


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