; LLVM IR from 0intro/wmii :: lib/libstuff/x11/drawing (border)

; 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.Rectangle = type { %struct.Point, %struct.Point }
%struct.Point = type { i32, i32 }
%struct.Window = type { i32, i64, ptr, ptr, ptr, i64, ptr, %struct.Rectangle, i32, ptr, ptr, ptr, ptr, ptr, ptr, %struct.Ewmh, i64, ptr, ptr, i8, i32, i32 }
%struct.Ewmh = type { i64, i64, i64 }

@display = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @border(ptr noundef %0, i64 %1, i64 %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca %struct.Rectangle, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca %struct.Rectangle, align 4
  %11 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  store i64 %1, ptr %11, align 4
  %12 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  store i64 %2, ptr %12, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  store ptr %4, ptr %9, align 8, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %5
  br label %76

16:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = sdiv i32 %17, 2
  %19 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %20 = load i64, ptr %19, align 4
  %21 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %22 = load i64, ptr %21, align 4
  %23 = call { i64, i64 } @insetrect(i64 %20, i64 %22, i32 noundef %18)
  %24 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %25 = extractvalue { i64, i64 } %23, 0
  store i64 %25, ptr %24, align 4
  %26 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %27 = extractvalue { i64, i64 } %23, 1
  store i64 %27, ptr %26, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %10, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = srem i32 %28, 2
  %30 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %31 = getelementptr inbounds %struct.Point, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = sub nsw i32 %32, %29
  store i32 %33, ptr %31, align 4, !tbaa !12
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = srem i32 %34, 2
  %36 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %37 = getelementptr inbounds %struct.Point, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = sub nsw i32 %38, %35
  store i32 %39, ptr %37, align 4, !tbaa !15
  %40 = load ptr, ptr @display, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Window, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = call i32 @XSetLineAttributes(ptr noundef %40, ptr noundef %43, i32 noundef %44, i32 noundef 0, i32 noundef 1, i32 noundef 0)
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  call void @setgccol(ptr noundef %46, ptr noundef %47)
  %48 = load ptr, ptr @display, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Window, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !21
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Window, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 0
  %56 = getelementptr inbounds %struct.Point, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !22
  %58 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 0
  %59 = getelementptr inbounds %struct.Point, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !23
  %61 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %62 = getelementptr inbounds %struct.Point, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !12
  %64 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 0
  %65 = getelementptr inbounds %struct.Point, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 4, !tbaa !22
  %67 = sub nsw i32 %63, %66
  %68 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %69 = getelementptr inbounds %struct.Point, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !15
  %71 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 0
  %72 = getelementptr inbounds %struct.Point, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !23
  %74 = sub nsw i32 %70, %73
  %75 = call i32 @XDrawRectangle(ptr noundef %48, i64 noundef %51, ptr noundef %54, i32 noundef %57, i32 noundef %60, i32 noundef %67, i32 noundef %74)
  br label %76

76:                                               ; preds = %16, %15
  ret void
}

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

declare { i64, i64 } @insetrect(i64, i64, i32 noundef) #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) #3

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

declare i32 @XSetLineAttributes(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare void @setgccol(ptr noundef, ptr noundef) #2

declare i32 @XDrawRectangle(ptr noundef, i64 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9}
!12 = !{!13, !10, i64 8}
!13 = !{!"Rectangle", !14, i64 0, !14, i64 8}
!14 = !{!"Point", !10, i64 0, !10, i64 4}
!15 = !{!13, !10, i64 12}
!16 = !{!17, !6, i64 24}
!17 = !{!"Window", !10, i64 0, !18, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !18, i64 40, !6, i64 48, !13, i64 56, !10, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !19, i64 128, !18, i64 152, !6, i64 160, !6, i64 168, !20, i64 176, !10, i64 180, !10, i64 184}
!18 = !{!"long", !7, i64 0}
!19 = !{!"Ewmh", !18, i64 0, !18, i64 8, !18, i64 16}
!20 = !{!"_Bool", !7, i64 0}
!21 = !{!17, !18, i64 8}
!22 = !{!13, !10, i64 0}
!23 = !{!13, !10, i64 4}


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

@display = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @border(ptr noundef %0, i64 %1, i64 %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %3, 0
  br i1 %6, label %26, label %7

7:                                                ; preds = %5
  %8 = sdiv i32 %3, 2
  %9 = tail call { i64, i64 } @insetrect(i64 %1, i64 %2, i32 noundef %8) #2
  %10 = extractvalue { i64, i64 } %9, 0
  %11 = extractvalue { i64, i64 } %9, 1
  %.sroa.09.0.extract.trunc12 = trunc i64 %10 to i32
  %.sroa.5.0.extract.shift13 = lshr i64 %10, 32
  %.sroa.5.0.extract.trunc14 = trunc nuw i64 %.sroa.5.0.extract.shift13 to i32
  %.sroa.7.8.extract.trunc18 = trunc i64 %11 to i32
  %.sroa.13.8.extract.shift19 = lshr i64 %11, 32
  %.sroa.13.8.extract.trunc20 = trunc nuw i64 %.sroa.13.8.extract.shift19 to i32
  %12 = srem i32 %3, 2
  %13 = load ptr, ptr @display, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = tail call i32 @XSetLineAttributes(ptr noundef %13, ptr noundef %15, i32 noundef %3, i32 noundef 0, i32 noundef 1, i32 noundef 0) #2
  tail call void @setgccol(ptr noundef %0, ptr noundef %4) #2
  %17 = load ptr, ptr @display, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = load ptr, ptr %14, align 8, !tbaa !9
  %21 = add i32 %12, %.sroa.09.0.extract.trunc12
  %22 = sub i32 %.sroa.7.8.extract.trunc18, %21
  %23 = add i32 %12, %.sroa.5.0.extract.trunc14
  %24 = sub i32 %.sroa.13.8.extract.trunc20, %23
  %25 = tail call i32 @XDrawRectangle(ptr noundef %17, i64 noundef %19, ptr noundef %20, i32 noundef %.sroa.09.0.extract.trunc12, i32 noundef %.sroa.5.0.extract.trunc14, i32 noundef %22, i32 noundef %24) #2
  br label %26

26:                                               ; preds = %5, %7
  ret void
}

declare { i64, i64 } @insetrect(i64, i64, i32 noundef) local_unnamed_addr #1

declare i32 @XSetLineAttributes(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @setgccol(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @XDrawRectangle(ptr noundef, i64 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"Window", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !13, i64 56, !11, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !15, i64 128, !12, i64 152, !6, i64 160, !6, i64 168, !16, i64 176, !11, i64 180, !11, i64 184}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"Rectangle", !14, i64 0, !14, i64 8}
!14 = !{!"Point", !11, i64 0, !11, i64 4}
!15 = !{!"Ewmh", !12, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!10, !12, i64 8}


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