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

; 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
@maxTextureSize = external dso_local global i32, align 4
@.str.11 = external hidden unnamed_addr constant [70 x i8], align 1
@glad_glGenTextures = external global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [62 x i8], align 1
@glad_glBindTexture = external global ptr, align 8
@glad_glTexParameteri = external global ptr, align 8
@glad_glTexImage2D = 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @createTexture(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #3 {
  %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
  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
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  %14 = icmp sgt i32 %12, %13
  br i1 %14, label %19, label %15

15:                                               ; preds = %5
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  %18 = icmp sgt i32 %16, %17
  br i1 %18, label %19, label %44

19:                                               ; preds = %15, %5
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  %24 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.11, i32 noundef %21, i32 noundef %22, i32 noundef %23, i32 noundef %24) #4
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  %28 = icmp sgt i32 %26, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %19
  %30 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  br label %33

31:                                               ; preds = %19
  %32 = load i32, ptr %7, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %31, %29
  %34 = phi i32 [ %30, %29 ], [ %32, %31 ]
  store i32 %34, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  %37 = icmp sgt i32 %35, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %33
  %39 = load i32, ptr @maxTextureSize, align 4, !tbaa !9
  br label %42

40:                                               ; preds = %33
  %41 = load i32, ptr %8, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %40, %38
  %43 = phi i32 [ %39, %38 ], [ %41, %40 ]
  store i32 %43, ptr %8, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %42, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %45 = load ptr, ptr @glad_glGenTextures, align 8, !tbaa !5
  call void %45(i32 noundef 1, ptr noundef %11)
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %53, label %48

48:                                               ; preds = %44
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef @.str.12, i32 noundef %50, i32 noundef %51) #4
  call void @abort() #5
  unreachable

53:                                               ; preds = %44
  %54 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !9
  call void %54(i32 noundef 3553, i32 noundef %55)
  %56 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  call void %56(i32 noundef 3553, i32 noundef 10241, i32 noundef 9728)
  %57 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  call void %57(i32 noundef 3553, i32 noundef 10240, i32 noundef 9728)
  %58 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  call void %58(i32 noundef 3553, i32 noundef 10242, i32 noundef 10497)
  %59 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  call void %59(i32 noundef 3553, i32 noundef 10243, i32 noundef 10497)
  %60 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  call void %60(i32 noundef 3553, i32 noundef 0, i32 noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef 0, i32 noundef %64, i32 noundef 5121, ptr noundef %65)
  %66 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret i32 %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { nounwind }
attributes #5 = { noreturn 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}


; 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
@maxTextureSize = external dso_local local_unnamed_addr global i32, align 4
@.str.11 = external hidden unnamed_addr constant [70 x i8], align 1
@glad_glGenTextures = external local_unnamed_addr global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [62 x i8], align 1
@glad_glBindTexture = external local_unnamed_addr global ptr, align 8
@glad_glTexParameteri = external local_unnamed_addr global ptr, align 8
@glad_glTexImage2D = 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @createTexture(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #3 {
  %6 = alloca i32, align 4
  %7 = load i32, ptr @maxTextureSize, align 4, !tbaa !5
  %8 = icmp slt i32 %7, %1
  %9 = icmp slt i32 %7, %2
  %or.cond = or i1 %8, %9
  br i1 %or.cond, label %10, label %16

10:                                               ; preds = %5
  %11 = load ptr, ptr @stderr, align 8, !tbaa !9
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.11, i32 noundef %1, i32 noundef %2, i32 noundef %7, i32 noundef %7) #5
  %13 = load i32, ptr @maxTextureSize, align 4
  %14 = tail call i32 @llvm.smin.i32(i32 %13, i32 %1)
  %15 = tail call i32 @llvm.smin.i32(i32 %13, i32 %2)
  br label %16

16:                                               ; preds = %5, %10
  %.014 = phi i32 [ %15, %10 ], [ %2, %5 ]
  %.0 = phi i32 [ %14, %10 ], [ %1, %5 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  %17 = load ptr, ptr @glad_glGenTextures, align 8, !tbaa !9
  call void %17(i32 noundef 1, ptr noundef nonnull %6) #6
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.12, i32 noundef %.0, i32 noundef %.014) #5
  call void @abort() #7
  unreachable

22:                                               ; preds = %16
  %23 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !9
  call void %23(i32 noundef 3553, i32 noundef %18) #6
  %24 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !9
  call void %24(i32 noundef 3553, i32 noundef 10241, i32 noundef 9728) #6
  %25 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !9
  call void %25(i32 noundef 3553, i32 noundef 10240, i32 noundef 9728) #6
  %26 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !9
  call void %26(i32 noundef 3553, i32 noundef 10242, i32 noundef 10497) #6
  %27 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !9
  call void %27(i32 noundef 3553, i32 noundef 10243, i32 noundef 10497) #6
  %28 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !9
  call void %28(i32 noundef 3553, i32 noundef 0, i32 noundef %4, i32 noundef %.0, i32 noundef %.014, i32 noundef 0, i32 noundef %3, i32 noundef 5121, ptr noundef %0) #6
  %29 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  ret i32 %29
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { cold nounwind }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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