; LLVM IR from achilles288/robot-monitor-graphics :: src/base/internal/shader.ll (ZN3rmg8internal6Shader20compileShaderProgramEPKcS3_)

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

@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZN3rmg8internal14glDeleteShaderE = external global ptr, align 8
@_ZN3rmg8internal15glCreateProgramE = external global ptr, align 8
@_ZN3rmg8internal14glAttachShaderE = external global ptr, align 8
@_ZN3rmg8internal13glLinkProgramE = external global ptr, align 8
@_ZN3rmg8internal14glGetProgramivE = external global ptr, align 8
@_ZN3rmg8internal19glGetProgramInfoLogE = external global ptr, align 8
@_ZN3rmg8internal14glDetachShaderE = external global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef, ptr noundef) #0 align 2

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3rmg8internal6Shader20compileShaderProgramEPKcS3_(ptr noundef %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %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 ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef 35633, ptr noundef %13)
  store i32 %14, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef 35632, ptr noundef %15)
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %22, label %19

19:                                               ; preds = %2
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %35

22:                                               ; preds = %19, %2
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  call void %26(i32 noundef %27)
  br label %28

28:                                               ; preds = %25, %22
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %28
  %32 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  call void %32(i32 noundef %33)
  br label %34

34:                                               ; preds = %31, %28
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %76

35:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %36 = load ptr, ptr @_ZN3rmg8internal15glCreateProgramE, align 8, !tbaa !5
  %37 = call noundef i32 %36()
  store i32 %37, ptr %9, align 4, !tbaa !9
  %38 = load ptr, ptr @_ZN3rmg8internal14glAttachShaderE, align 8, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  call void %38(i32 noundef %39, i32 noundef %40)
  %41 = load ptr, ptr @_ZN3rmg8internal14glAttachShaderE, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  call void %41(i32 noundef %42, i32 noundef %43)
  %44 = load ptr, ptr @_ZN3rmg8internal13glLinkProgramE, align 8, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !9
  call void %44(i32 noundef %45)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %46 = load ptr, ptr @_ZN3rmg8internal14glGetProgramivE, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !9
  call void %46(i32 noundef %47, i32 noundef 35714, ptr noundef %10)
  %48 = load ptr, ptr @_ZN3rmg8internal14glGetProgramivE, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !9
  call void %48(i32 noundef %49, i32 noundef 35716, ptr noundef %11)
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = icmp sgt i32 %50, 0
  br i1 %51, label %52, label %63

52:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = call noalias ptr @malloc(i64 noundef %55) #5
  store ptr %56, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr @_ZN3rmg8internal19glGetProgramInfoLogE, align 8, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  call void %57(i32 noundef %58, i32 noundef %59, ptr noundef null, ptr noundef %60)
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %61)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %75

63:                                               ; preds = %35
  %64 = load ptr, ptr @_ZN3rmg8internal14glDetachShaderE, align 8, !tbaa !5
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = load i32, ptr %6, align 4, !tbaa !9
  call void %64(i32 noundef %65, i32 noundef %66)
  %67 = load ptr, ptr @_ZN3rmg8internal14glDetachShaderE, align 8, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = load i32, ptr %7, align 4, !tbaa !9
  call void %67(i32 noundef %68, i32 noundef %69)
  %70 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !9
  call void %70(i32 noundef %71)
  %72 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  %73 = load i32, ptr %7, align 4, !tbaa !9
  call void %72(i32 noundef %73)
  %74 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %74, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %75

75:                                               ; preds = %63, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %76

76:                                               ; preds = %75, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %77 = load i32, ptr %3, align 4
  ret i32 %77
}

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" }
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 = { nounwind allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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}


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

@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZN3rmg8internal14glDeleteShaderE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal15glCreateProgramE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal14glAttachShaderE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal13glLinkProgramE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal14glGetProgramivE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal19glGetProgramInfoLogE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal14glDetachShaderE = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef, ptr noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3rmg8internal6Shader20compileShaderProgramEPKcS3_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef 35633, ptr noundef %0)
  %6 = tail call noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef 35632, ptr noundef %1)
  %7 = icmp eq i32 %5, 0
  %8 = icmp eq i32 %6, 0
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %9, label %15

9:                                                ; preds = %2
  br i1 %7, label %12, label %10

10:                                               ; preds = %9
  %11 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  tail call void %11(i32 noundef %5)
  br label %12

12:                                               ; preds = %10, %9
  br i1 %8, label %37, label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  tail call void %14(i32 noundef %6)
  br label %37

15:                                               ; preds = %2
  %16 = load ptr, ptr @_ZN3rmg8internal15glCreateProgramE, align 8, !tbaa !5
  %17 = tail call noundef i32 %16()
  %18 = load ptr, ptr @_ZN3rmg8internal14glAttachShaderE, align 8, !tbaa !5
  tail call void %18(i32 noundef %17, i32 noundef %5)
  %19 = load ptr, ptr @_ZN3rmg8internal14glAttachShaderE, align 8, !tbaa !5
  tail call void %19(i32 noundef %17, i32 noundef %6)
  %20 = load ptr, ptr @_ZN3rmg8internal13glLinkProgramE, align 8, !tbaa !5
  tail call void %20(i32 noundef %17)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %21 = load ptr, ptr @_ZN3rmg8internal14glGetProgramivE, align 8, !tbaa !5
  call void %21(i32 noundef %17, i32 noundef 35714, ptr noundef nonnull %3)
  %22 = load ptr, ptr @_ZN3rmg8internal14glGetProgramivE, align 8, !tbaa !5
  call void %22(i32 noundef %17, i32 noundef 35716, ptr noundef nonnull %4)
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %15
  %26 = add nuw nsw i32 %23, 1
  %27 = zext nneg i32 %26 to i64
  %28 = call noalias ptr @malloc(i64 noundef %27) #5
  %29 = load ptr, ptr @_ZN3rmg8internal19glGetProgramInfoLogE, align 8, !tbaa !5
  call void %29(i32 noundef %17, i32 noundef %23, ptr noundef null, ptr noundef %28)
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %28)
  br label %36

31:                                               ; preds = %15
  %32 = load ptr, ptr @_ZN3rmg8internal14glDetachShaderE, align 8, !tbaa !5
  call void %32(i32 noundef %17, i32 noundef %5)
  %33 = load ptr, ptr @_ZN3rmg8internal14glDetachShaderE, align 8, !tbaa !5
  call void %33(i32 noundef %17, i32 noundef %6)
  %34 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  call void %34(i32 noundef %5)
  %35 = load ptr, ptr @_ZN3rmg8internal14glDeleteShaderE, align 8, !tbaa !5
  call void %35(i32 noundef %6)
  br label %36

36:                                               ; preds = %31, %25
  %.0 = phi i32 [ 0, %25 ], [ %17, %31 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  br label %37

37:                                               ; preds = %12, %13, %36
  %.1 = phi i32 [ %.0, %36 ], [ 0, %13 ], [ 0, %12 ]
  ret i32 %.1
}

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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}


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