; LLVM IR from yettabaa/cub3D :: mlx-linux (mlx_xpm)

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

%struct.s_img = type { ptr, i64, ptr, i32, i32, i32, i32, i32, i32, ptr, %struct.XShmSegmentInfo }
%struct.XShmSegmentInfo = type { i64, i32, ptr, i32 }

; Function Attrs: nounwind uwtable
declare dso_local ptr @mlx_int_get_line(ptr noundef, ptr noundef, i32 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 uwtable
declare dso_local ptr @mlx_int_parse_xpm(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @mlx_int_file_get_rid_comment(ptr noundef, i32 noundef) #0

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

18:                                               ; preds = %4
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = call i64 @lseek(i32 noundef %19, i64 noundef 0, i32 noundef 2) #4
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr %11, align 4, !tbaa !9
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %29, label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = call ptr @mmap(ptr noundef null, i64 noundef %25, i32 noundef 3, i32 noundef 2, i32 noundef %26, i64 noundef 0) #4
  store ptr %27, ptr %12, align 8, !tbaa !5
  %28 = icmp eq ptr %27, inttoptr (i64 -1 to ptr)
  br i1 %28, label %29, label %36

29:                                               ; preds = %23, %18, %4
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp sge i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = call i32 @close(i32 noundef %33)
  br label %35

35:                                               ; preds = %32, %29
  store ptr null, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %62

36:                                               ; preds = %23
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = call i32 @mlx_int_file_get_rid_comment(ptr noundef %37, i32 noundef %38)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = call ptr @mlx_int_parse_xpm(ptr noundef %40, ptr noundef %41, i32 noundef %42, ptr noundef @mlx_int_get_line)
  store ptr %43, ptr %13, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %54

45:                                               ; preds = %36
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.s_img, ptr %46, i32 0, i32 5
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %48, ptr %49, align 4, !tbaa !9
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s_img, ptr %50, i32 0, i32 6
  %52 = load i32, ptr %51, align 4, !tbaa !15
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %52, ptr %53, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %45, %36
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = call i32 @munmap(ptr noundef %55, i64 noundef %57) #4
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = call i32 @close(i32 noundef %59)
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %61, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %62

62:                                               ; preds = %54, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %63 = load ptr, ptr %5, align 8
  ret ptr %63
}

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

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) #3

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #3

declare i32 @close(i32 noundef) #2

; Function Attrs: nounwind
declare i32 @munmap(ptr noundef, i64 noundef) #3

attributes #0 = { 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 #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 "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 }

!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 = !{!12, !10, i64 32}
!12 = !{!"s_img", !6, i64 0, !13, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !6, i64 48, !14, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !13, i64 0, !10, i64 8, !6, i64 16, !10, i64 24}
!15 = !{!12, !10, i64 36}


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

; Function Attrs: nounwind uwtable
declare dso_local ptr @mlx_int_get_line(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @mlx_int_parse_xpm(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @mlx_int_file_get_rid_comment(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @mlx_xpm_file_to_image(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = tail call i32 (ptr, i32, ...) @open(ptr noundef %1, i32 noundef 0) #4
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %.thread, label %7

7:                                                ; preds = %4
  %8 = tail call i64 @lseek(i32 noundef %5, i64 noundef 0, i32 noundef 2) #4
  %9 = trunc i64 %8 to i32
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %15, label %11

11:                                               ; preds = %7
  %sext = shl i64 %8, 32
  %12 = ashr exact i64 %sext, 32
  %13 = tail call ptr @mmap(ptr noundef null, i64 noundef %12, i32 noundef 3, i32 noundef 2, i32 noundef %5, i64 noundef 0) #4
  %14 = icmp eq ptr %13, inttoptr (i64 -1 to ptr)
  br i1 %14, label %15, label %17

15:                                               ; preds = %11, %7
  %16 = icmp sgt i32 %5, -1
  br i1 %16, label %.thread.sink.split, label %.thread

17:                                               ; preds = %11
  %18 = tail call i32 @mlx_int_file_get_rid_comment(ptr noundef %13, i32 noundef %9)
  %19 = tail call ptr @mlx_int_parse_xpm(ptr noundef %0, ptr noundef %13, i32 noundef %9, ptr noundef nonnull @mlx_int_get_line)
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %25, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %19, i64 32
  %22 = load i32, ptr %21, align 8, !tbaa !5
  store i32 %22, ptr %2, align 4, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %19, i64 36
  %24 = load i32, ptr %23, align 4, !tbaa !14
  store i32 %24, ptr %3, align 4, !tbaa !13
  br label %25

25:                                               ; preds = %20, %17
  %26 = tail call i32 @munmap(ptr noundef %13, i64 noundef %12) #4
  br label %.thread.sink.split

.thread.sink.split:                               ; preds = %15, %25
  %.0.ph = phi ptr [ %19, %25 ], [ null, %15 ]
  %27 = tail call i32 @close(i32 noundef %5) #4
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %4, %15
  %.0 = phi ptr [ null, %15 ], [ null, %4 ], [ %.0.ph, %.thread.sink.split ]
  ret ptr %.0
}

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

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

declare i32 @close(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @munmap(ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { nofree "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 "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 = { "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 }

!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, !11, i64 32}
!6 = !{!"s_img", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !7, i64 48, !12, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !10, i64 0, !11, i64 8, !7, i64 16, !11, i64 24}
!13 = !{!11, !11, i64 0}
!14 = !{!6, !11, i64 36}


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