; LLVM IR from blat-blatnik/GPU-Life :: main (linkShaderProgram)

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

@stderr = external global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@glad_glCreateProgram = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [61 x i8], align 1
@glad_glAttachShader = external global ptr, align 8
@glad_glLinkProgram = external global ptr, align 8
@glad_glDetachShader = external global ptr, align 8
@glad_glGetProgramiv = external global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@glad_glGetProgramInfoLog = external global ptr, align 8

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @abort() #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @linkShaderProgram(ptr noundef %0, i32 noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %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 ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %11 = load ptr, ptr @glad_glCreateProgram, align 8, !tbaa !5
  %12 = call i32 %11()
  store i32 %12, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %18, label %15

15:                                               ; preds = %2
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.9) #5
  call void @abort() #6
  unreachable

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

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

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %35

24:                                               ; preds = %19
  %25 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %6, 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 %6, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %6, 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 %5, align 4, !tbaa !9
  call void %36(i32 noundef %37)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %51, %35
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %54

43:                                               ; preds = %38
  %44 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %46, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  call void %44(i32 noundef %45, i32 noundef %50)
  br label %51

51:                                               ; preds = %43
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %38, !llvm.loop !13

54:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %55 = load ptr, ptr @glad_glGetProgramiv, align 8, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !9
  call void %55(i32 noundef %56, i32 noundef 35714, ptr noundef %8)
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %77, label %59

59:                                               ; preds = %54
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %62 = load ptr, ptr @glad_glGetProgramiv, align 8, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !9
  call void %62(i32 noundef %63, i32 noundef 35716, ptr noundef %9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = call noalias ptr @malloc(i64 noundef %65) #7
  store ptr %66, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr @glad_glGetProgramInfoLog, align 8, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  call void %67(i32 noundef %68, i32 noundef %69, ptr noundef null, ptr noundef %70)
  %71 = load ptr, ptr @stderr, align 8, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str.7, ptr noundef %72) #5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %74) #5
  %75 = load ptr, ptr @stderr, align 8, !tbaa !5
  %76 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %75, ptr noundef @.str.8) #5
  call void @abort() #6
  unreachable

77:                                               ; preds = %54
  %78 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %78
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn 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 = { 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 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 #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@glad_glCreateProgram = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [61 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_glDetachShader = external local_unnamed_addr global ptr, align 8
@glad_glGetProgramiv = external local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@glad_glGetProgramInfoLog = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 1, 0) i32 @linkShaderProgram(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #5 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = load ptr, ptr @glad_glCreateProgram, align 8, !tbaa !5
  %6 = tail call i32 %5() #6
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %9, label %.preheader

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

._crit_edge.thread:                               ; preds = %.preheader
  %8 = load ptr, ptr @glad_glLinkProgram, align 8, !tbaa !5
  tail call void %8(i32 noundef %6) #6
  br label %._crit_edge28

.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 @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.9) #7
  tail call void @abort() #8
  unreachable

._crit_edge:                                      ; preds = %.lr.ph
  %12 = load ptr, ptr @glad_glLinkProgram, align 8, !tbaa !5
  tail call void %12(i32 noundef %6) #6
  br i1 %7, label %.lr.ph27.preheader, label %._crit_edge28

.lr.ph27.preheader:                               ; preds = %._crit_edge
  %wide.trip.count33 = zext nneg i32 %1 to i64
  br label %.lr.ph27

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %13 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !9
  tail call void %13(i32 noundef %6, i32 noundef %15) #6
  %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

._crit_edge28:                                    ; preds = %.lr.ph27, %._crit_edge.thread, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %16 = load ptr, ptr @glad_glGetProgramiv, align 8, !tbaa !5
  call void %16(i32 noundef %6, i32 noundef 35714, ptr noundef nonnull %3) #6
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %.not23 = icmp eq i32 %17, 0
  br i1 %.not23, label %21, label %33

.lr.ph27:                                         ; preds = %.lr.ph27.preheader, %.lr.ph27
  %indvars.iv30 = phi i64 [ 0, %.lr.ph27.preheader ], [ %indvars.iv.next31, %.lr.ph27 ]
  %18 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  %19 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv30
  %20 = load i32, ptr %19, align 4, !tbaa !9
  tail call void %18(i32 noundef %6, i32 noundef %20) #6
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count33
  br i1 %exitcond34.not, label %._crit_edge28, label %.lr.ph27, !llvm.loop !13

21:                                               ; preds = %._crit_edge28
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.10) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  %24 = load ptr, ptr @glad_glGetProgramiv, align 8, !tbaa !5
  call void %24(i32 noundef %6, i32 noundef 35716, ptr noundef nonnull %4) #6
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = call noalias ptr @malloc(i64 noundef %26) #9
  %28 = load ptr, ptr @glad_glGetProgramInfoLog, align 8, !tbaa !5
  call void %28(i32 noundef %6, i32 noundef %25, ptr noundef null, ptr noundef %27) #6
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.7, ptr noundef %27) #7
  call void @free(ptr noundef %27) #6
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.8) #7
  call void @abort() #8
  unreachable

33:                                               ; preds = %._crit_edge28
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  ret i32 %6
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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 = { noreturn 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 #4 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { cold nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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