; LLVM IR from libtcod/libtcod :: src/libtcod (zip_c)

; 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.TCOD_ColorRGB = type { i8, i8, i8 }

; 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 uwtable
declare dso_local void @TCOD_zip_put_char(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_zip_put_int(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_zip_put_color(ptr noundef, i24) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_zip_put_console(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %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 %struct.TCOD_ColorRGB, align 1
  %10 = alloca i24, align 4
  %11 = alloca %struct.TCOD_ColorRGB, align 1
  %12 = alloca i24, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @TCOD_console_get_width(ptr noundef %13)
  store i32 %14, ptr %5, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i32 @TCOD_console_get_height(ptr noundef %15)
  store i32 %16, ptr %6, align 4, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  call void @TCOD_zip_put_int(ptr noundef %17, i32 noundef %18)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  call void @TCOD_zip_put_int(ptr noundef %19, i32 noundef %20)
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %54, %2
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %57

25:                                               ; preds = %21
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %50, %25
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %53

30:                                               ; preds = %26
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = call i32 @TCOD_console_get_char(ptr noundef %32, i32 noundef %33, i32 noundef %34)
  %36 = and i32 %35, 255
  %37 = trunc i32 %36 to i8
  call void @TCOD_zip_put_char(ptr noundef %31, i8 noundef signext %37)
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = call i24 @TCOD_console_get_char_foreground(ptr noundef %39, i32 noundef %40, i32 noundef %41)
  store i24 %42, ptr %9, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 1 %9, i64 3, i1 false)
  %43 = load i24, ptr %10, align 4
  call void @TCOD_zip_put_color(ptr noundef %38, i24 %43)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = call i24 @TCOD_console_get_char_background(ptr noundef %45, i32 noundef %46, i32 noundef %47)
  store i24 %48, ptr %11, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 1 %11, i64 3, i1 false)
  %49 = load i24, ptr %12, align 4
  call void @TCOD_zip_put_color(ptr noundef %44, i24 %49)
  br label %50

50:                                               ; preds = %30
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !9
  br label %26, !llvm.loop !11

53:                                               ; preds = %26
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %8, align 4, !tbaa !9
  br label %21, !llvm.loop !13

57:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

declare i32 @TCOD_console_get_width(ptr noundef) #3

declare i32 @TCOD_console_get_height(ptr noundef) #3

declare i32 @TCOD_console_get_char(ptr noundef, i32 noundef, i32 noundef) #3

declare i24 @TCOD_console_get_char_foreground(ptr noundef, i32 noundef, i32 noundef) #3

declare i24 @TCOD_console_get_char_background(ptr noundef, i32 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !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"

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_zip_put_char(ptr noundef, i8 noundef signext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_zip_put_color(ptr noundef, i24) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_zip_put_console(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @TCOD_console_get_width(ptr noundef %1) #2
  %4 = tail call i32 @TCOD_console_get_height(ptr noundef %1) #2
  tail call void @TCOD_zip_put_int(ptr noundef %0, i32 noundef %3)
  tail call void @TCOD_zip_put_int(ptr noundef %0, i32 noundef %4)
  %5 = icmp sgt i32 %4, 0
  %6 = icmp sgt i32 %3, 0
  %or.cond = select i1 %5, i1 %6, i1 false
  br i1 %or.cond, label %.preheader.us, label %._crit_edge29

.preheader.us:                                    ; preds = %2, %._crit_edge.us
  %.02628.us = phi i32 [ %13, %._crit_edge.us ], [ 0, %2 ]
  br label %7

7:                                                ; preds = %.preheader.us, %7
  %.027.us = phi i32 [ 0, %.preheader.us ], [ %12, %7 ]
  %8 = tail call i32 @TCOD_console_get_char(ptr noundef %1, i32 noundef %.027.us, i32 noundef %.02628.us) #2
  %9 = trunc i32 %8 to i8
  tail call void @TCOD_zip_put_char(ptr noundef %0, i8 noundef signext %9)
  %10 = tail call i24 @TCOD_console_get_char_foreground(ptr noundef %1, i32 noundef %.027.us, i32 noundef %.02628.us) #2
  tail call void @TCOD_zip_put_color(ptr noundef %0, i24 %10)
  %11 = tail call i24 @TCOD_console_get_char_background(ptr noundef %1, i32 noundef %.027.us, i32 noundef %.02628.us) #2
  tail call void @TCOD_zip_put_color(ptr noundef %0, i24 %11)
  %12 = add nuw nsw i32 %.027.us, 1
  %exitcond.not = icmp eq i32 %12, %3
  br i1 %exitcond.not, label %._crit_edge.us, label %7, !llvm.loop !5

._crit_edge.us:                                   ; preds = %7
  %13 = add nuw nsw i32 %.02628.us, 1
  %exitcond31.not = icmp eq i32 %13, %4
  br i1 %exitcond31.not, label %._crit_edge29, label %.preheader.us, !llvm.loop !7

._crit_edge29:                                    ; preds = %._crit_edge.us, %2
  ret void
}

declare i32 @TCOD_console_get_width(ptr noundef) local_unnamed_addr #1

declare i32 @TCOD_console_get_height(ptr noundef) local_unnamed_addr #1

declare i32 @TCOD_console_get_char(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i24 @TCOD_console_get_char_foreground(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i24 @TCOD_console_get_char_background(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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