; LLVM IR from jovanlanik/wip :: src (wip_gl)

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

@glad_glGetError = external global ptr, align 8
@glad_glCreateProgram = external global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [32 x i8], align 1
@__func__.wip_loadProgramF = external hidden unnamed_addr constant [17 x i8], align 1
@glad_glAttachShader = external global ptr, align 8
@glad_glLinkProgram = external global ptr, align 8
@glad_glGetProgramiv = external global ptr, align 8
@glad_glGetProgramInfoLog = external global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [30 x i8], align 1
@glad_glDeleteProgram = 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

declare void @wip_log(i32 noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @wip_loadProgramF(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [8192 x i8], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load ptr, ptr @glad_glCreateProgram, align 8, !tbaa !5
  %12 = call i32 %11()
  store i32 %12, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %2
  %16 = load ptr, ptr @glad_glGetError, align 8, !tbaa !5
  %17 = call i32 %16()
  call void (i32, ptr, ...) @wip_log(i32 noundef 2, ptr noundef @.str.10, ptr noundef @__func__.wip_loadProgramF, i32 noundef %17)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %52

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %32, %18
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %35

24:                                               ; preds = %19
  %25 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  call void %25(i32 noundef %26, i32 noundef %31)
  br label %32

32:                                               ; preds = %24
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %8, align 4, !tbaa !9
  br label %19, !llvm.loop !11

35:                                               ; preds = %23
  %36 = load ptr, ptr @glad_glLinkProgram, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  call void %36(i32 noundef %37)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %38 = load ptr, ptr @glad_glGetProgramiv, align 8, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !9
  call void %38(i32 noundef %39, i32 noundef 35714, ptr noundef %9)
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %49

42:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8192, ptr %10) #3
  %43 = load ptr, ptr @glad_glGetProgramInfoLog, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = getelementptr inbounds [8192 x i8], ptr %10, i64 0, i64 0
  call void %43(i32 noundef %44, i32 noundef 8192, ptr noundef null, ptr noundef %45)
  %46 = getelementptr inbounds [8192 x i8], ptr %10, i64 0, i64 0
  call void (i32, ptr, ...) @wip_log(i32 noundef 2, ptr noundef @.str.11, ptr noundef @__func__.wip_loadProgramF, ptr noundef %46)
  %47 = load ptr, ptr @glad_glDeleteProgram, align 8, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !9
  call void %47(i32 noundef %48)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8192, ptr %10) #3
  br label %51

49:                                               ; preds = %35
  %50 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %50, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

51:                                               ; preds = %49, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %52

52:                                               ; preds = %51, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %53 = load i32, ptr %3, align 4
  ret i32 %53
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@glad_glGetError = external local_unnamed_addr global ptr, align 8
@glad_glCreateProgram = external local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [32 x i8], align 1
@__func__.wip_loadProgramF = external hidden unnamed_addr constant [17 x i8], align 1
@glad_glAttachShader = external local_unnamed_addr global ptr, align 8
@glad_glLinkProgram = external local_unnamed_addr global ptr, align 8
@glad_glGetProgramiv = external local_unnamed_addr global ptr, align 8
@glad_glGetProgramInfoLog = external local_unnamed_addr global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [30 x i8], align 1
@glad_glDeleteProgram = external local_unnamed_addr global ptr, align 8

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

declare void @wip_log(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @wip_loadProgramF(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %4 = alloca [8192 x i8], align 16
  %5 = load ptr, ptr @glad_glCreateProgram, align 8, !tbaa !5
  %6 = tail call i32 %5() #3
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %9, label %.preheader

.preheader:                                       ; preds = %2
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

9:                                                ; preds = %2
  %10 = load ptr, ptr @glad_glGetError, align 8, !tbaa !5
  %11 = tail call i32 %10() #3
  tail call void (i32, ptr, ...) @wip_log(i32 noundef 2, ptr noundef nonnull @.str.10, ptr noundef nonnull @__func__.wip_loadProgramF, i32 noundef %11) #3
  br label %23

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %12 = load ptr, ptr @glad_glLinkProgram, align 8, !tbaa !5
  tail call void %12(i32 noundef %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %13 = load ptr, ptr @glad_glGetProgramiv, align 8, !tbaa !5
  call void %13(i32 noundef %6, i32 noundef 35714, ptr noundef nonnull %3) #3
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %19, label %22

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %16 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  %17 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !9
  tail call void %16(i32 noundef %6, i32 noundef %18) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

19:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %4) #3
  %20 = load ptr, ptr @glad_glGetProgramInfoLog, align 8, !tbaa !5
  call void %20(i32 noundef %6, i32 noundef 8192, ptr noundef null, ptr noundef nonnull %4) #3
  call void (i32, ptr, ...) @wip_log(i32 noundef 2, ptr noundef nonnull @.str.11, ptr noundef nonnull @__func__.wip_loadProgramF, ptr noundef nonnull %4) #3
  %21 = load ptr, ptr @glad_glDeleteProgram, align 8, !tbaa !5
  call void %21(i32 noundef %6) #3
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %4) #3
  br label %22

22:                                               ; preds = %._crit_edge, %19
  %.012 = phi i32 [ 0, %19 ], [ %6, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %23

23:                                               ; preds = %22, %9
  %.1 = phi i32 [ 0, %9 ], [ %.012, %22 ]
  ret i32 %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass