; LLVM IR from Eukky/TRender :: lib/glew/src (glewinfo)

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

@dpy = external dso_local global ptr, align 8
@vi = external dso_local global ptr, align 8
@vis = external dso_local global ptr, align 8
@ctx = external dso_local global ptr, align 8
@wnd = external dso_local global i64, align 8
@cmap = external dso_local global i64, align 8

declare void @glXDestroyContext(ptr noundef, ptr noundef) #0

declare i32 @XFree(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @glewDestroyContext() #1 {
  %1 = load ptr, ptr @dpy, align 8, !tbaa !5
  %2 = icmp ne ptr null, %1
  br i1 %2, label %3, label %9

3:                                                ; preds = %0
  %4 = load ptr, ptr @ctx, align 8, !tbaa !5
  %5 = icmp ne ptr null, %4
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = load ptr, ptr @dpy, align 8, !tbaa !5
  %8 = load ptr, ptr @ctx, align 8, !tbaa !5
  call void @glXDestroyContext(ptr noundef %7, ptr noundef %8)
  br label %9

9:                                                ; preds = %6, %3, %0
  %10 = load ptr, ptr @dpy, align 8, !tbaa !5
  %11 = icmp ne ptr null, %10
  br i1 %11, label %12, label %19

12:                                               ; preds = %9
  %13 = load i64, ptr @wnd, align 8, !tbaa !9
  %14 = icmp ne i64 0, %13
  br i1 %14, label %15, label %19

15:                                               ; preds = %12
  %16 = load ptr, ptr @dpy, align 8, !tbaa !5
  %17 = load i64, ptr @wnd, align 8, !tbaa !9
  %18 = call i32 @XDestroyWindow(ptr noundef %16, i64 noundef %17)
  br label %19

19:                                               ; preds = %15, %12, %9
  %20 = load ptr, ptr @dpy, align 8, !tbaa !5
  %21 = icmp ne ptr null, %20
  br i1 %21, label %22, label %29

22:                                               ; preds = %19
  %23 = load i64, ptr @cmap, align 8, !tbaa !9
  %24 = icmp ne i64 0, %23
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = load ptr, ptr @dpy, align 8, !tbaa !5
  %27 = load i64, ptr @cmap, align 8, !tbaa !9
  %28 = call i32 @XFreeColormap(ptr noundef %26, i64 noundef %27)
  br label %29

29:                                               ; preds = %25, %22, %19
  %30 = load ptr, ptr @vis, align 8, !tbaa !5
  %31 = icmp ne ptr null, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr @vis, align 8, !tbaa !5
  %34 = call i32 @XFree(ptr noundef %33)
  br label %42

35:                                               ; preds = %29
  %36 = load ptr, ptr @vi, align 8, !tbaa !5
  %37 = icmp ne ptr null, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load ptr, ptr @vi, align 8, !tbaa !5
  %40 = call i32 @XFree(ptr noundef %39)
  br label %41

41:                                               ; preds = %38, %35
  br label %42

42:                                               ; preds = %41, %32
  %43 = load ptr, ptr @dpy, align 8, !tbaa !5
  %44 = icmp ne ptr null, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load ptr, ptr @dpy, align 8, !tbaa !5
  %47 = call i32 @XCloseDisplay(ptr noundef %46)
  br label %48

48:                                               ; preds = %45, %42
  ret void
}

declare i32 @XDestroyWindow(ptr noundef, i64 noundef) #0

declare i32 @XFreeColormap(ptr noundef, i64 noundef) #0

declare i32 @XCloseDisplay(ptr noundef) #0

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

@dpy = external dso_local local_unnamed_addr global ptr, align 8
@vi = external dso_local local_unnamed_addr global ptr, align 8
@vis = external dso_local local_unnamed_addr global ptr, align 8
@ctx = external dso_local local_unnamed_addr global ptr, align 8
@wnd = external dso_local local_unnamed_addr global i64, align 8
@cmap = external dso_local local_unnamed_addr global i64, align 8

declare void @glXDestroyContext(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @XFree(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @glewDestroyContext() local_unnamed_addr #1 {
  %1 = load ptr, ptr @dpy, align 8, !tbaa !5
  %2 = icmp ne ptr %1, null
  %3 = load ptr, ptr @ctx, align 8
  %4 = icmp ne ptr %3, null
  %or.cond = select i1 %2, i1 %4, i1 false
  br i1 %or.cond, label %5, label %6

5:                                                ; preds = %0
  tail call void @glXDestroyContext(ptr noundef nonnull %1, ptr noundef nonnull %3) #2
  %.pre = load ptr, ptr @dpy, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %5, %0
  %7 = phi ptr [ %.pre, %5 ], [ %1, %0 ]
  %8 = icmp ne ptr %7, null
  %9 = load i64, ptr @wnd, align 8
  %10 = icmp ne i64 %9, 0
  %or.cond3 = select i1 %8, i1 %10, i1 false
  br i1 %or.cond3, label %11, label %13

11:                                               ; preds = %6
  %12 = tail call i32 @XDestroyWindow(ptr noundef nonnull %7, i64 noundef %9) #2
  %.pre16 = load ptr, ptr @dpy, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11, %6
  %14 = phi ptr [ %.pre16, %11 ], [ %7, %6 ]
  %15 = icmp ne ptr %14, null
  %16 = load i64, ptr @cmap, align 8
  %17 = icmp ne i64 %16, 0
  %or.cond5 = select i1 %15, i1 %17, i1 false
  br i1 %or.cond5, label %18, label %20

18:                                               ; preds = %13
  %19 = tail call i32 @XFreeColormap(ptr noundef nonnull %14, i64 noundef %16) #2
  br label %20

20:                                               ; preds = %18, %13
  %21 = load ptr, ptr @vis, align 8, !tbaa !5
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %22, label %.sink.split

22:                                               ; preds = %20
  %23 = load ptr, ptr @vi, align 8, !tbaa !5
  %.not14 = icmp eq ptr %23, null
  br i1 %.not14, label %25, label %.sink.split

.sink.split:                                      ; preds = %22, %20
  %.sink = phi ptr [ %21, %20 ], [ %23, %22 ]
  %24 = tail call i32 @XFree(ptr noundef nonnull %.sink) #2
  br label %25

25:                                               ; preds = %.sink.split, %22
  %26 = load ptr, ptr @dpy, align 8, !tbaa !5
  %.not15 = icmp eq ptr %26, null
  br i1 %.not15, label %29, label %27

27:                                               ; preds = %25
  %28 = tail call i32 @XCloseDisplay(ptr noundef nonnull %26) #2
  br label %29

29:                                               ; preds = %27, %25
  ret void
}

declare i32 @XDestroyWindow(ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @XFreeColormap(ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @XCloseDisplay(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 #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"}


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