; LLVM IR from steps3d/graphics-book :: Code/Core/Framebuffer.ll (ZN11FrameBuffer6createEiii)

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

%class.FrameBuffer = type { i32, i32, i32, i32, [8 x ptr], i32, i32, [4 x i32] }

@__glewGenFramebuffers = external global ptr, align 8
@__glewBindFramebuffer = external global ptr, align 8
@__glewGenRenderbuffers = external global ptr, align 8
@__glewBindRenderbuffer = external global ptr, align 8
@__glewRenderbufferStorage = external global ptr, align 8
@__glewFramebufferRenderbuffer = external global ptr, align 8
@__glewCheckFramebufferStatus = external global ptr, 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 noundef zeroext i1 @_ZN11FrameBuffer6createEiii(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 1
  store i32 %14, ptr %15, align 4, !tbaa !11
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 2
  store i32 %16, ptr %17, align 8, !tbaa !13
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  store i32 %18, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = icmp sle i32 %21, 0
  br i1 %22, label %27, label %23

23:                                               ; preds = %4
  %24 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp sle i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23, %4
  store i1 false, ptr %5, align 1
  br label %122

28:                                               ; preds = %23
  %29 = load ptr, ptr @__glewGenFramebuffers, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 3
  call void %29(i32 noundef 1, ptr noundef %30)
  %31 = load ptr, ptr @__glewBindFramebuffer, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 3
  %33 = load i32, ptr %32, align 4, !tbaa !15
  call void %31(i32 noundef 36160, i32 noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  %34 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = and i32 %35, 1
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %28
  store i32 33189, ptr %10, align 4, !tbaa !9
  br label %53

39:                                               ; preds = %28
  %40 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !14
  %42 = and i32 %41, 2
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  store i32 33190, ptr %10, align 4, !tbaa !9
  br label %52

45:                                               ; preds = %39
  %46 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !14
  %48 = and i32 %47, 4
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %45
  store i32 33191, ptr %10, align 4, !tbaa !9
  br label %51

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

52:                                               ; preds = %51, %44
  br label %53

53:                                               ; preds = %52, %38
  %54 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !14
  %56 = and i32 %55, 16
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  store i32 36166, ptr %11, align 4, !tbaa !9
  br label %80

59:                                               ; preds = %53
  %60 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !14
  %62 = and i32 %61, 32
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  store i32 36167, ptr %11, align 4, !tbaa !9
  br label %79

65:                                               ; preds = %59
  %66 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !14
  %68 = and i32 %67, 64
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %65
  store i32 36168, ptr %11, align 4, !tbaa !9
  br label %78

71:                                               ; preds = %65
  %72 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !14
  %74 = and i32 %73, 128
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %71
  store i32 36169, ptr %11, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %76, %71
  br label %78

78:                                               ; preds = %77, %70
  br label %79

79:                                               ; preds = %78, %64
  br label %80

80:                                               ; preds = %79, %58
  %81 = load i32, ptr %10, align 4, !tbaa !9
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %98

83:                                               ; preds = %80
  %84 = load ptr, ptr @__glewGenRenderbuffers, align 8, !tbaa !5
  %85 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 5
  call void %84(i32 noundef 1, ptr noundef %85)
  %86 = load ptr, ptr @__glewBindRenderbuffer, align 8, !tbaa !5
  %87 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 5
  %88 = load i32, ptr %87, align 8, !tbaa !16
  call void %86(i32 noundef 36161, i32 noundef %88)
  %89 = load ptr, ptr @__glewRenderbufferStorage, align 8, !tbaa !5
  %90 = load i32, ptr %10, align 4, !tbaa !9
  %91 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 1
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 2
  %94 = load i32, ptr %93, align 8, !tbaa !13
  call void %89(i32 noundef 36161, i32 noundef %90, i32 noundef %92, i32 noundef %94)
  %95 = load ptr, ptr @__glewFramebufferRenderbuffer, align 8, !tbaa !5
  %96 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 5
  %97 = load i32, ptr %96, align 8, !tbaa !16
  call void %95(i32 noundef 36160, i32 noundef 36096, i32 noundef 36161, i32 noundef %97)
  br label %98

98:                                               ; preds = %83, %80
  %99 = load i32, ptr %11, align 4, !tbaa !9
  %100 = icmp ne i32 %99, 0
  br i1 %100, label %101, label %116

101:                                              ; preds = %98
  %102 = load ptr, ptr @__glewGenRenderbuffers, align 8, !tbaa !5
  %103 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 6
  call void %102(i32 noundef 1, ptr noundef %103)
  %104 = load ptr, ptr @__glewBindRenderbuffer, align 8, !tbaa !5
  %105 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 6
  %106 = load i32, ptr %105, align 4, !tbaa !17
  call void %104(i32 noundef 36161, i32 noundef %106)
  %107 = load ptr, ptr @__glewRenderbufferStorage, align 8, !tbaa !5
  %108 = load i32, ptr %11, align 4, !tbaa !9
  %109 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 1
  %110 = load i32, ptr %109, align 4, !tbaa !11
  %111 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 2
  %112 = load i32, ptr %111, align 8, !tbaa !13
  call void %107(i32 noundef 36161, i32 noundef %108, i32 noundef %110, i32 noundef %112)
  %113 = load ptr, ptr @__glewFramebufferRenderbuffer, align 8, !tbaa !5
  %114 = getelementptr inbounds %class.FrameBuffer, ptr %13, i32 0, i32 6
  %115 = load i32, ptr %114, align 4, !tbaa !17
  call void %113(i32 noundef 36160, i32 noundef 36128, i32 noundef 36161, i32 noundef %115)
  br label %116

116:                                              ; preds = %101, %98
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %117 = load ptr, ptr @__glewCheckFramebufferStatus, align 8, !tbaa !5
  %118 = call i32 %117(i32 noundef 36160)
  store i32 %118, ptr %12, align 4, !tbaa !9
  %119 = load ptr, ptr @__glewBindFramebuffer, align 8, !tbaa !5
  call void %119(i32 noundef 36160, i32 noundef 0)
  %120 = load i32, ptr %12, align 4, !tbaa !9
  %121 = icmp eq i32 %120, 36053
  store i1 %121, ptr %5, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %122

122:                                              ; preds = %116, %27
  %123 = load i1, ptr %5, align 1
  ret i1 %123
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS11FrameBuffer", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !10, i64 80, !10, i64 84, !7, i64 88}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 80}
!17 = !{!12, !10, i64 84}


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

@__glewGenFramebuffers = external local_unnamed_addr global ptr, align 8
@__glewBindFramebuffer = external local_unnamed_addr global ptr, align 8
@__glewGenRenderbuffers = external local_unnamed_addr global ptr, align 8
@__glewBindRenderbuffer = external local_unnamed_addr global ptr, align 8
@__glewRenderbufferStorage = external local_unnamed_addr global ptr, align 8
@__glewFramebufferRenderbuffer = external local_unnamed_addr global ptr, align 8
@__glewCheckFramebufferStatus = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN11FrameBuffer6createEiii(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %2, ptr %6, align 8, !tbaa !10
  store i32 %3, ptr %0, align 8, !tbaa !11
  %7 = icmp slt i32 %1, 1
  %8 = icmp slt i32 %2, 1
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %55, label %9

9:                                                ; preds = %4
  %10 = load ptr, ptr @__glewGenFramebuffers, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  tail call void %10(i32 noundef 1, ptr noundef nonnull %11)
  %12 = load ptr, ptr @__glewBindFramebuffer, align 8, !tbaa !12
  %13 = load i32, ptr %11, align 4, !tbaa !14
  tail call void %12(i32 noundef 36160, i32 noundef %13)
  %14 = load i32, ptr %0, align 8, !tbaa !11
  %15 = and i32 %14, 1
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %20

16:                                               ; preds = %9
  %17 = and i32 %14, 2
  %.not11 = icmp eq i32 %17, 0
  br i1 %.not11, label %18, label %20

18:                                               ; preds = %16
  %19 = and i32 %14, 4
  %.not12 = icmp eq i32 %19, 0
  %spec.select20 = select i1 %.not12, i32 0, i32 33191
  br label %20

20:                                               ; preds = %18, %16, %9
  %.not17 = phi i1 [ false, %9 ], [ false, %16 ], [ %.not12, %18 ]
  %.010 = phi i32 [ 33189, %9 ], [ 33190, %16 ], [ %spec.select20, %18 ]
  %21 = and i32 %14, 16
  %.not13 = icmp eq i32 %21, 0
  br i1 %.not13, label %22, label %28

22:                                               ; preds = %20
  %23 = and i32 %14, 32
  %.not14 = icmp eq i32 %23, 0
  br i1 %.not14, label %24, label %28

24:                                               ; preds = %22
  %25 = and i32 %14, 64
  %.not15 = icmp eq i32 %25, 0
  br i1 %.not15, label %26, label %28

26:                                               ; preds = %24
  %27 = and i32 %14, 128
  %.not16 = icmp eq i32 %27, 0
  %spec.select22 = select i1 %.not16, i32 0, i32 36169
  br label %28

28:                                               ; preds = %26, %24, %22, %20
  %.not18 = phi i1 [ false, %20 ], [ false, %22 ], [ false, %24 ], [ %.not16, %26 ]
  %.09 = phi i32 [ 36166, %20 ], [ 36167, %22 ], [ 36168, %24 ], [ %spec.select22, %26 ]
  br i1 %.not17, label %39, label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr @__glewGenRenderbuffers, align 8, !tbaa !12
  %31 = getelementptr inbounds i8, ptr %0, i64 80
  tail call void %30(i32 noundef 1, ptr noundef nonnull %31)
  %32 = load ptr, ptr @__glewBindRenderbuffer, align 8, !tbaa !12
  %33 = load i32, ptr %31, align 8, !tbaa !15
  tail call void %32(i32 noundef 36161, i32 noundef %33)
  %34 = load ptr, ptr @__glewRenderbufferStorage, align 8, !tbaa !12
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = load i32, ptr %6, align 8, !tbaa !10
  tail call void %34(i32 noundef 36161, i32 noundef %.010, i32 noundef %35, i32 noundef %36)
  %37 = load ptr, ptr @__glewFramebufferRenderbuffer, align 8, !tbaa !12
  %38 = load i32, ptr %31, align 8, !tbaa !15
  tail call void %37(i32 noundef 36160, i32 noundef 36096, i32 noundef 36161, i32 noundef %38)
  br label %39

39:                                               ; preds = %29, %28
  br i1 %.not18, label %50, label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr @__glewGenRenderbuffers, align 8, !tbaa !12
  %42 = getelementptr inbounds i8, ptr %0, i64 84
  tail call void %41(i32 noundef 1, ptr noundef nonnull %42)
  %43 = load ptr, ptr @__glewBindRenderbuffer, align 8, !tbaa !12
  %44 = load i32, ptr %42, align 4, !tbaa !16
  tail call void %43(i32 noundef 36161, i32 noundef %44)
  %45 = load ptr, ptr @__glewRenderbufferStorage, align 8, !tbaa !12
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 8, !tbaa !10
  tail call void %45(i32 noundef 36161, i32 noundef %.09, i32 noundef %46, i32 noundef %47)
  %48 = load ptr, ptr @__glewFramebufferRenderbuffer, align 8, !tbaa !12
  %49 = load i32, ptr %42, align 4, !tbaa !16
  tail call void %48(i32 noundef 36160, i32 noundef 36128, i32 noundef 36161, i32 noundef %49)
  br label %50

50:                                               ; preds = %40, %39
  %51 = load ptr, ptr @__glewCheckFramebufferStatus, align 8, !tbaa !12
  %52 = tail call i32 %51(i32 noundef 36160)
  %53 = load ptr, ptr @__glewBindFramebuffer, align 8, !tbaa !12
  tail call void %53(i32 noundef 36160, i32 noundef 0)
  %54 = icmp eq i32 %52, 36053
  br label %55

55:                                               ; preds = %4, %50
  %.0 = phi i1 [ %54, %50 ], [ false, %4 ]
  ret i1 %.0
}

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, !7, i64 4}
!6 = !{!"_ZTS11FrameBuffer", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !7, i64 80, !7, i64 84, !8, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !7, i64 12}
!15 = !{!6, !7, i64 80}
!16 = !{!6, !7, i64 84}


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