; LLVM IR from holzschu/ios_system :: curl/curl/docs/examples (certinfo)

; 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.curl_certinfo = type { i32, ptr }
%struct.curl_slist = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = call i32 @curl_global_init(i64 noundef 3)
  %8 = call ptr @curl_easy_init()
  store ptr %8, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %75

11:                                               ; preds = %0
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %12, i32 noundef 10002, ptr noundef @.str)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %14, i32 noundef 20011, ptr noundef @wrfu)
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %16, i32 noundef 64, i64 noundef 0)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %18, i32 noundef 81, i64 noundef 0)
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %20, i32 noundef 41, i64 noundef 0)
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef %22, i32 noundef 172, i64 noundef 1)
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @curl_easy_perform(ptr noundef %24)
  store i32 %25, ptr %3, align 4, !tbaa !9
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %73, label %28

28:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = call i32 (ptr, i32, ...) @curl_easy_getinfo(ptr noundef %29, i32 noundef 4194338, ptr noundef %4)
  store i32 %30, ptr %3, align 4, !tbaa !9
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %72, label %33

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %72

36:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.curl_certinfo, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %39)
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %68, %36
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.curl_certinfo, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !11
  %46 = icmp slt i32 %42, %45
  br i1 %46, label %47, label %71

47:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.curl_certinfo, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %6, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %63, %47
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %67

58:                                               ; preds = %55
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.curl_slist, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !14
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %61)
  br label %63

63:                                               ; preds = %58
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.curl_slist, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  store ptr %66, ptr %6, align 8, !tbaa !5
  br label %55, !llvm.loop !17

67:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %5, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %5, align 4, !tbaa !9
  br label %41, !llvm.loop !19

71:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %72

72:                                               ; preds = %71, %33, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %73

73:                                               ; preds = %72, %11
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  call void @curl_easy_cleanup(ptr noundef %74)
  br label %75

75:                                               ; preds = %73, %0
  call void @curl_global_cleanup()
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

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

declare i32 @curl_global_init(i64 noundef) #2

declare ptr @curl_easy_init() #2

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

; Function Attrs: nounwind uwtable
declare hidden i64 @wrfu(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

declare i32 @curl_easy_perform(ptr noundef) #2

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

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

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

declare void @curl_easy_cleanup(ptr noundef) #2

declare void @curl_global_cleanup() #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 = { 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 }

!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 0}
!12 = !{!"curl_certinfo", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !6, i64 0}
!15 = !{!"curl_slist", !6, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca ptr, align 8
  %2 = tail call i32 @curl_global_init(i64 noundef 3) #4
  %3 = tail call ptr @curl_easy_init() #4
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %36, label %4

4:                                                ; preds = %0
  %5 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 10002, ptr noundef nonnull @.str) #4
  %6 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 20011, ptr noundef nonnull @wrfu) #4
  %7 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 64, i64 noundef 0) #4
  %8 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 81, i64 noundef 0) #4
  %9 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 41, i64 noundef 0) #4
  %10 = tail call i32 (ptr, i32, ...) @curl_easy_setopt(ptr noundef nonnull %3, i32 noundef 172, i64 noundef 1) #4
  %11 = tail call i32 @curl_easy_perform(ptr noundef nonnull %3) #4
  %.not21 = icmp eq i32 %11, 0
  br i1 %.not21, label %12, label %35

12:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %13 = call i32 (ptr, i32, ...) @curl_easy_getinfo(ptr noundef nonnull %3, i32 noundef 4194338, ptr noundef nonnull %1) #4
  %14 = icmp eq i32 %13, 0
  %15 = load ptr, ptr %1, align 8
  %16 = icmp ne ptr %15, null
  %or.cond = select i1 %14, i1 %16, i1 false
  br i1 %or.cond, label %17, label %.loopexit

17:                                               ; preds = %12
  %18 = load i32, ptr %15, align 8, !tbaa !5
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %18)
  %20 = load ptr, ptr %1, align 8, !tbaa !11
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph28, label %.loopexit

.lr.ph28:                                         ; preds = %17, %._crit_edge
  %23 = phi i32 [ %31, %._crit_edge ], [ %21, %17 ]
  %24 = phi ptr [ %32, %._crit_edge ], [ %20, %17 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %17 ]
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv
  %.023 = load ptr, ptr %27, align 8, !tbaa !11
  %.not2224 = icmp eq ptr %.023, null
  br i1 %.not2224, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph28, %.lr.ph
  %.025 = phi ptr [ %.0, %.lr.ph ], [ %.023, %.lr.ph28 ]
  %28 = load ptr, ptr %.025, align 8, !tbaa !13
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %28)
  %30 = getelementptr inbounds i8, ptr %.025, i64 8
  %.0 = load ptr, ptr %30, align 8, !tbaa !11
  %.not22 = icmp eq ptr %.0, null
  br i1 %.not22, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr %1, align 8, !tbaa !11
  %.pre30 = load i32, ptr %.pre, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph28
  %31 = phi i32 [ %.pre30, %._crit_edge.loopexit ], [ %23, %.lr.ph28 ]
  %32 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %24, %.lr.ph28 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = sext i32 %31 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph28, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %._crit_edge, %17, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  br label %35

35:                                               ; preds = %.loopexit, %4
  call void @curl_easy_cleanup(ptr noundef nonnull %3) #4
  br label %36

36:                                               ; preds = %35, %0
  call void @curl_global_cleanup() #4
  ret i32 0
}

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

declare i32 @curl_global_init(i64 noundef) local_unnamed_addr #2

declare ptr @curl_easy_init() local_unnamed_addr #2

declare i32 @curl_easy_setopt(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i64 @wrfu(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

declare i32 @curl_easy_perform(ptr noundef) local_unnamed_addr #2

declare i32 @curl_easy_getinfo(ptr noundef, i32 noundef, ...) local_unnamed_addr #2

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

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

declare void @curl_easy_cleanup(ptr noundef) local_unnamed_addr #2

declare void @curl_global_cleanup() 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 = { mustprogress 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 = { 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 #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, !7, i64 0}
!6 = !{!"curl_certinfo", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"curl_slist", !10, i64 0, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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