; LLVM IR from kajott/GIPS :: src/gl_util.ll (ZN6GLutil6Shader4initEj)

; 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.GLutil::Shader" = type <{ i32, i32, i32, [4 x i8], ptr, i8, [7 x i8] }>

@_ZN6GLutil11initializedE = external dso_local global i8, align 1
@glad_glDeleteShader = external global ptr, align 8
@glad_glCreateShader = external global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6GLutil6Shader4initEj(ptr noundef nonnull align 8 dereferenceable(25) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = load i8, ptr @_ZN6GLutil11initializedE, align 1, !tbaa !11, !range !13, !noundef !14
  %8 = trunc i8 %7 to i1
  br i1 %8, label %10, label %9

9:                                                ; preds = %2
  store i1 false, ptr %3, align 1
  br label %42

10:                                               ; preds = %2
  %11 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %20

14:                                               ; preds = %10
  %15 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !17
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %14
  store i1 true, ptr %3, align 1
  br label %42

20:                                               ; preds = %14, %10
  %21 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %20
  %25 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !15
  call void %25(i32 noundef %27)
  %28 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 2
  store i32 0, ptr %28, align 8, !tbaa !17
  %29 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 1
  store i32 0, ptr %29, align 4, !tbaa !15
  br label %30

30:                                               ; preds = %24, %20
  %31 = load ptr, ptr @glad_glCreateShader, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = call i32 %31(i32 noundef %32)
  %34 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 1
  store i32 %33, ptr %34, align 4, !tbaa !15
  %35 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %30
  store i1 false, ptr %3, align 1
  br label %42

39:                                               ; preds = %30
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = getelementptr inbounds %"class.GLutil::Shader", ptr %6, i32 0, i32 2
  store i32 %40, ptr %41, align 8, !tbaa !17
  store i1 true, ptr %3, align 1
  br label %42

42:                                               ; preds = %39, %38, %19, %9
  %43 = load i1, ptr %3, align 1
  ret i1 %43
}

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, !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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 4}
!16 = !{!"_ZTSN6GLutil6ShaderE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !12, i64 24}
!17 = !{!16, !10, 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"

@_ZN6GLutil11initializedE = external dso_local local_unnamed_addr global i8, align 1
@glad_glDeleteShader = external local_unnamed_addr global ptr, align 8
@glad_glCreateShader = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6GLutil6Shader4initEj(ptr nocapture noundef nonnull align 8 dereferenceable(25) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load i8, ptr @_ZN6GLutil11initializedE, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %5, label %18

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %.not = icmp ne i32 %7, 0
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8
  %10 = icmp eq i32 %9, %1
  %or.cond = select i1 %.not, i1 %10, i1 false
  br i1 %or.cond, label %18, label %11

11:                                               ; preds = %5
  %.not5 = icmp eq i32 %7, 0
  br i1 %.not5, label %14, label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !15
  tail call void %13(i32 noundef %7)
  store i32 0, ptr %8, align 8, !tbaa !16
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %12, %11
  %15 = load ptr, ptr @glad_glCreateShader, align 8, !tbaa !15
  %16 = tail call i32 %15(i32 noundef %1)
  store i32 %16, ptr %6, align 4, !tbaa !11
  %.not6 = icmp eq i32 %16, 0
  br i1 %.not6, label %18, label %17

17:                                               ; preds = %14
  store i32 %1, ptr %8, align 8, !tbaa !16
  br label %18

18:                                               ; preds = %14, %5, %2, %17
  %.0 = phi i1 [ true, %17 ], [ false, %2 ], [ true, %5 ], [ false, %14 ]
  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, !6, i64 0}
!6 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !13, i64 4}
!12 = !{!"_ZTSN6GLutil6ShaderE", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !6, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!12, !13, i64 8}


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