; LLVM IR from libtcod/libtcod :: src/libtcod (bresenham_c)

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

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_line_init_mt(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = load ptr, ptr %10, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %12, i32 0, i32 5
  store i32 %11, ptr %13, align 4, !tbaa !11
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = load ptr, ptr %10, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %15, i32 0, i32 6
  store i32 %14, ptr %16, align 4, !tbaa !13
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = load ptr, ptr %10, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %18, i32 0, i32 7
  store i32 %17, ptr %19, align 4, !tbaa !14
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %21, i32 0, i32 8
  store i32 %20, ptr %22, align 4, !tbaa !15
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sub nsw i32 %23, %24
  %26 = load ptr, ptr %10, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %26, i32 0, i32 3
  store i32 %25, ptr %27, align 4, !tbaa !16
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sub nsw i32 %28, %29
  %31 = load ptr, ptr %10, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %31, i32 0, i32 4
  store i32 %30, ptr %32, align 4, !tbaa !17
  %33 = load ptr, ptr %10, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %40

37:                                               ; preds = %5
  %38 = load ptr, ptr %10, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %38, i32 0, i32 0
  store i32 1, ptr %39, align 4, !tbaa !18
  br label %52

40:                                               ; preds = %5
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %46, i32 0, i32 0
  store i32 -1, ptr %47, align 4, !tbaa !18
  br label %51

48:                                               ; preds = %40
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %49, i32 0, i32 0
  store i32 0, ptr %50, align 4, !tbaa !18
  br label %51

51:                                               ; preds = %48, %45
  br label %52

52:                                               ; preds = %51, %37
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %53, i32 0, i32 4
  %55 = load i32, ptr %54, align 4, !tbaa !17
  %56 = icmp sgt i32 %55, 0
  br i1 %56, label %57, label %60

57:                                               ; preds = %52
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %58, i32 0, i32 1
  store i32 1, ptr %59, align 4, !tbaa !19
  br label %72

60:                                               ; preds = %52
  %61 = load ptr, ptr %10, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %61, i32 0, i32 4
  %63 = load i32, ptr %62, align 4, !tbaa !17
  %64 = icmp slt i32 %63, 0
  br i1 %64, label %65, label %68

65:                                               ; preds = %60
  %66 = load ptr, ptr %10, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %66, i32 0, i32 1
  store i32 -1, ptr %67, align 4, !tbaa !19
  br label %71

68:                                               ; preds = %60
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %69, i32 0, i32 1
  store i32 0, ptr %70, align 4, !tbaa !19
  br label %71

71:                                               ; preds = %68, %65
  br label %72

72:                                               ; preds = %71, %57
  %73 = load ptr, ptr %10, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 4, !tbaa !18
  %76 = load ptr, ptr %10, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %76, i32 0, i32 3
  %78 = load i32, ptr %77, align 4, !tbaa !16
  %79 = mul nsw i32 %75, %78
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !19
  %83 = load ptr, ptr %10, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %83, i32 0, i32 4
  %85 = load i32, ptr %84, align 4, !tbaa !17
  %86 = mul nsw i32 %82, %85
  %87 = icmp sgt i32 %79, %86
  br i1 %87, label %88, label %106

88:                                               ; preds = %72
  %89 = load ptr, ptr %10, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %89, i32 0, i32 0
  %91 = load i32, ptr %90, align 4, !tbaa !18
  %92 = load ptr, ptr %10, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %92, i32 0, i32 3
  %94 = load i32, ptr %93, align 4, !tbaa !16
  %95 = mul nsw i32 %91, %94
  %96 = load ptr, ptr %10, align 8, !tbaa !9
  %97 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %96, i32 0, i32 2
  store i32 %95, ptr %97, align 4, !tbaa !20
  %98 = load ptr, ptr %10, align 8, !tbaa !9
  %99 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %98, i32 0, i32 3
  %100 = load i32, ptr %99, align 4, !tbaa !16
  %101 = mul nsw i32 %100, 2
  store i32 %101, ptr %99, align 4, !tbaa !16
  %102 = load ptr, ptr %10, align 8, !tbaa !9
  %103 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %102, i32 0, i32 4
  %104 = load i32, ptr %103, align 4, !tbaa !17
  %105 = mul nsw i32 %104, 2
  store i32 %105, ptr %103, align 4, !tbaa !17
  br label %124

106:                                              ; preds = %72
  %107 = load ptr, ptr %10, align 8, !tbaa !9
  %108 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !19
  %110 = load ptr, ptr %10, align 8, !tbaa !9
  %111 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %110, i32 0, i32 4
  %112 = load i32, ptr %111, align 4, !tbaa !17
  %113 = mul nsw i32 %109, %112
  %114 = load ptr, ptr %10, align 8, !tbaa !9
  %115 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %114, i32 0, i32 2
  store i32 %113, ptr %115, align 4, !tbaa !20
  %116 = load ptr, ptr %10, align 8, !tbaa !9
  %117 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %116, i32 0, i32 3
  %118 = load i32, ptr %117, align 4, !tbaa !16
  %119 = mul nsw i32 %118, 2
  store i32 %119, ptr %117, align 4, !tbaa !16
  %120 = load ptr, ptr %10, align 8, !tbaa !9
  %121 = getelementptr inbounds %struct.TCOD_bresenham_data_t, ptr %120, i32 0, i32 4
  %122 = load i32, ptr %121, align 4, !tbaa !17
  %123 = mul nsw i32 %122, 2
  store i32 %123, ptr %121, align 4, !tbaa !17
  br label %124

124:                                              ; preds = %106, %88
  ret void
}

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 20}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !6, i64 28}
!15 = !{!12, !6, i64 32}
!16 = !{!12, !6, i64 12}
!17 = !{!12, !6, i64 16}
!18 = !{!12, !6, i64 0}
!19 = !{!12, !6, i64 4}
!20 = !{!12, !6, i64 8}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @TCOD_line_init_mt(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %4, i64 20
  store i32 %0, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 24
  store i32 %1, ptr %7, align 4, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %4, i64 28
  store i32 %2, ptr %8, align 4, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 %3, ptr %9, align 4, !tbaa !12
  %10 = sub nsw i32 %2, %0
  %11 = sub nsw i32 %3, %1
  %.lobit = ashr i32 %10, 31
  %.inv = icmp slt i32 %10, 1
  %.sink41 = select i1 %.inv, i32 %.lobit, i32 1
  store i32 %.sink41, ptr %4, align 4, !tbaa !13
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %5
  %14 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 1, ptr %14, align 4, !tbaa !14
  br label %20

15:                                               ; preds = %5
  %16 = icmp slt i32 %11, 0
  %17 = getelementptr inbounds i8, ptr %4, i64 4
  br i1 %16, label %18, label %19

18:                                               ; preds = %15
  store i32 -1, ptr %17, align 4, !tbaa !14
  br label %20

19:                                               ; preds = %15
  store i32 0, ptr %17, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %18, %19, %13
  %21 = phi i32 [ -1, %18 ], [ 0, %19 ], [ 1, %13 ]
  %22 = getelementptr inbounds i8, ptr %4, i64 16
  %23 = getelementptr inbounds i8, ptr %4, i64 12
  %24 = mul nsw i32 %.sink41, %10
  %25 = mul nsw i32 %21, %11
  %spec.select = tail call i32 @llvm.smax.i32(i32 %24, i32 %25)
  %26 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %spec.select, ptr %26, align 4
  %storemerge40 = shl nsw i32 %10, 1
  store i32 %storemerge40, ptr %23, align 4, !tbaa !15
  %storemerge = shl nsw i32 %11, 1
  store i32 %storemerge, ptr %22, align 4, !tbaa !16
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 speculatable willreturn memory(none) }

!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 20}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 24}
!11 = !{!6, !7, i64 28}
!12 = !{!6, !7, i64 32}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 12}
!16 = !{!6, !7, i64 16}


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