; 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_Zip = type { ptr, i64, i32, i32, i32 }

; 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
define dso_local void @TCOD_zip_put_char(ptr noundef %0, i8 noundef signext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load i8, ptr %4, align 1, !tbaa !9
  %9 = zext i8 %8 to i64
  store i64 %9, ptr %6, align 8, !tbaa !10
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.TCOD_Zip, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !12
  switch i32 %12, label %68 [
    i32 0, label %13
    i32 1, label %19
    i32 2, label %26
    i32 3, label %33
    i32 4, label %40
    i32 5, label %47
    i32 6, label %54
    i32 7, label %61
  ]

13:                                               ; preds = %2
  %14 = load i64, ptr %6, align 8, !tbaa !10
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TCOD_Zip, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = or i64 %17, %14
  store i64 %18, ptr %16, align 8, !tbaa !15
  br label %68

19:                                               ; preds = %2
  %20 = load i64, ptr %6, align 8, !tbaa !10
  %21 = shl i64 %20, 8
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.TCOD_Zip, ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = or i64 %24, %21
  store i64 %25, ptr %23, align 8, !tbaa !15
  br label %68

26:                                               ; preds = %2
  %27 = load i64, ptr %6, align 8, !tbaa !10
  %28 = shl i64 %27, 16
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TCOD_Zip, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = or i64 %31, %28
  store i64 %32, ptr %30, align 8, !tbaa !15
  br label %68

33:                                               ; preds = %2
  %34 = load i64, ptr %6, align 8, !tbaa !10
  %35 = shl i64 %34, 24
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TCOD_Zip, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !15
  %39 = or i64 %38, %35
  store i64 %39, ptr %37, align 8, !tbaa !15
  br label %68

40:                                               ; preds = %2
  %41 = load i64, ptr %6, align 8, !tbaa !10
  %42 = shl i64 %41, 32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TCOD_Zip, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !15
  %46 = or i64 %45, %42
  store i64 %46, ptr %44, align 8, !tbaa !15
  br label %68

47:                                               ; preds = %2
  %48 = load i64, ptr %6, align 8, !tbaa !10
  %49 = shl i64 %48, 40
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TCOD_Zip, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !15
  %53 = or i64 %52, %49
  store i64 %53, ptr %51, align 8, !tbaa !15
  br label %68

54:                                               ; preds = %2
  %55 = load i64, ptr %6, align 8, !tbaa !10
  %56 = shl i64 %55, 48
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TCOD_Zip, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !15
  %60 = or i64 %59, %56
  store i64 %60, ptr %58, align 8, !tbaa !15
  br label %68

61:                                               ; preds = %2
  %62 = load i64, ptr %6, align 8, !tbaa !10
  %63 = shl i64 %62, 56
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TCOD_Zip, ptr %64, i32 0, i32 1
  %66 = load i64, ptr %65, align 8, !tbaa !15
  %67 = or i64 %66, %63
  store i64 %67, ptr %65, align 8, !tbaa !15
  br label %68

68:                                               ; preds = %61, %54, %47, %40, %33, %26, %19, %13, %2
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TCOD_Zip, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 8, !tbaa !12
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %70, align 8, !tbaa !12
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TCOD_Zip, ptr %73, i32 0, i32 3
  %75 = load i32, ptr %74, align 4, !tbaa !16
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %74, align 4, !tbaa !16
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TCOD_Zip, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 8, !tbaa !12
  %80 = sext i32 %79 to i64
  %81 = icmp eq i64 %80, 8
  br i1 %81, label %82, label %103

82:                                               ; preds = %68
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.TCOD_Zip, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !17
  %86 = icmp ne ptr %85, null
  br i1 %86, label %91, label %87

87:                                               ; preds = %82
  %88 = call ptr @TCOD_list_new()
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.TCOD_Zip, ptr %89, i32 0, i32 0
  store ptr %88, ptr %90, align 8, !tbaa !17
  br label %91

91:                                               ; preds = %87, %82
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.TCOD_Zip, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !17
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.TCOD_Zip, ptr %95, i32 0, i32 1
  %97 = load i64, ptr %96, align 8, !tbaa !15
  %98 = inttoptr i64 %97 to ptr
  call void @TCOD_list_push(ptr noundef %94, ptr noundef %98)
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.TCOD_Zip, ptr %99, i32 0, i32 2
  store i32 0, ptr %100, align 8, !tbaa !12
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.TCOD_Zip, ptr %101, i32 0, i32 1
  store i64 0, ptr %102, align 8, !tbaa !15
  br label %103

103:                                              ; preds = %91, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare ptr @TCOD_list_new() #2

declare void @TCOD_list_push(ptr noundef, ptr noundef) #2

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !14, i64 16}
!13 = !{!"TCOD_Zip", !6, i64 0, !11, i64 8, !14, i64 16, !14, i64 20, !14, i64 24}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !11, i64 8}
!16 = !{!13, !14, i64 20}
!17 = !{!13, !6, 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"

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_zip_put_char(ptr nocapture noundef %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %3 = zext i8 %1 to i64
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  switch i32 %5, label %.thread [
    i32 0, label %.thread.sink.split
    i32 1, label %6
    i32 2, label %8
    i32 3, label %10
    i32 4, label %12
    i32 5, label %14
    i32 6, label %16
    i32 7, label %25
  ]

6:                                                ; preds = %2
  %7 = shl nuw nsw i64 %3, 8
  br label %.thread.sink.split

8:                                                ; preds = %2
  %9 = shl nuw nsw i64 %3, 16
  br label %.thread.sink.split

10:                                               ; preds = %2
  %11 = shl nuw nsw i64 %3, 24
  br label %.thread.sink.split

12:                                               ; preds = %2
  %13 = shl nuw nsw i64 %3, 32
  br label %.thread.sink.split

14:                                               ; preds = %2
  %15 = shl nuw nsw i64 %3, 40
  br label %.thread.sink.split

16:                                               ; preds = %2
  %17 = shl nuw nsw i64 %3, 48
  br label %.thread.sink.split

.thread.sink.split:                               ; preds = %2, %6, %8, %10, %12, %14, %16
  %.sink29 = phi i64 [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %3, %2 ]
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !12
  %20 = or i64 %19, %.sink29
  store i64 %20, ptr %18, align 8, !tbaa !12
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %2
  %21 = add nsw i32 %5, 1
  store i32 %21, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 20
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !13
  br label %40

25:                                               ; preds = %2
  %26 = shl nuw i64 %3, 56
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load i64, ptr %27, align 8, !tbaa !12
  %29 = or i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !12
  store i32 8, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %0, i64 20
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !13
  %33 = load ptr, ptr %0, align 8, !tbaa !14
  %.not = icmp eq ptr %33, null
  br i1 %.not, label %34, label %36

34:                                               ; preds = %25
  %35 = tail call ptr @TCOD_list_new() #2
  store ptr %35, ptr %0, align 8, !tbaa !14
  %.pre = load i64, ptr %27, align 8, !tbaa !12
  br label %36

36:                                               ; preds = %34, %25
  %37 = phi i64 [ %.pre, %34 ], [ %29, %25 ]
  %38 = phi ptr [ %35, %34 ], [ %33, %25 ]
  %39 = inttoptr i64 %37 to ptr
  tail call void @TCOD_list_push(ptr noundef %38, ptr noundef %39) #2
  store i32 0, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %27, align 8, !tbaa !12
  br label %40

40:                                               ; preds = %.thread, %36
  ret void
}

declare ptr @TCOD_list_new() local_unnamed_addr #1

declare void @TCOD_list_push(ptr noundef, ptr 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 = !{!6, !11, i64 16}
!6 = !{!"TCOD_Zip", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !11, i64 24}
!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 = !{!6, !10, i64 8}
!13 = !{!6, !11, i64 20}
!14 = !{!6, !7, i64 0}


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