; LLVM IR from chkn/logdb :: src (logdb_connection)

; 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.logdb_header_t = type { [4 x i8], i16 }
%struct.logdb_connection_t = type { i16, %union.pthread_rwlock_t, i32, i32, ptr, i32 }
%union.pthread_rwlock_t = type { %struct.__pthread_rwlock_arch_t }
%struct.__pthread_rwlock_arch_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, [7 x i8], i64, i32 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @logdb_open(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.logdb_header_t, align 2
  %12 = alloca %struct.logdb_header_t, align 2
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %218

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 2, ptr %6, align 4, !tbaa !9
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = and i32 %23, 1
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %29

26:                                               ; preds = %22
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = or i32 %27, 64
  store i32 %28, ptr %6, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %26, %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i64 @strlen(ptr noundef %30) #8
  %32 = add i64 %31, 5
  store i64 %32, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %33 = load i64, ptr %7, align 8, !tbaa !11
  %34 = call noalias ptr @malloc(i64 noundef %33) #9
  store ptr %34, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %29
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %217

38:                                               ; preds = %29
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !11
  %42 = call ptr @strncpy(ptr noundef %39, ptr noundef %40, i64 noundef %41) #7
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = call ptr @strcat(ptr noundef %43, ptr noundef @.str) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = call i32 (ptr, i32, ...) @open(ptr noundef %45, i32 noundef %46, i32 noundef 384)
  store i32 %47, ptr %10, align 4, !tbaa !9
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = icmp eq i32 %48, -1
  br i1 %49, label %50, label %52

50:                                               ; preds = %38
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %51) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %216

52:                                               ; preds = %38
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = and i32 %53, 1
  %55 = icmp eq i32 %54, 1
  br i1 %55, label %56, label %72

56:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 6, ptr %11) #7
  %57 = getelementptr inbounds %struct.logdb_header_t, ptr %11, i32 0, i32 0
  %58 = getelementptr inbounds [4 x i8], ptr %57, i64 0, i64 0
  %59 = call ptr @strncpy(ptr noundef %58, ptr noundef @.str.1, i64 noundef 4) #7
  %60 = getelementptr inbounds %struct.logdb_header_t, ptr %11, i32 0, i32 1
  store i16 1, ptr %60, align 2, !tbaa !13
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = call i64 @logdb_io_write(i32 noundef %61, ptr noundef %11, i64 noundef 6)
  %63 = icmp ne i64 %62, 0
  br i1 %63, label %64, label %68

64:                                               ; preds = %56
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = call i32 @close(i32 noundef %65)
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %67) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

68:                                               ; preds = %56
  store i32 0, ptr %9, align 4
  br label %69

69:                                               ; preds = %68, %64
  call void @llvm.lifetime.end.p0(i64 6, ptr %11) #7
  %70 = load i32, ptr %9, align 4
  switch i32 %70, label %216 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %101

72:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 6, ptr %12) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = call i64 @logdb_io_read(i32 noundef %73, ptr noundef %12, i64 noundef 6)
  store i64 %74, ptr %13, align 8, !tbaa !11
  %75 = load i64, ptr %13, align 8, !tbaa !11
  %76 = icmp sgt i64 %75, 0
  br i1 %76, label %77, label %81

77:                                               ; preds = %72
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = call i32 @close(i32 noundef %78)
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %80) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %98

81:                                               ; preds = %72
  %82 = load i64, ptr %13, align 8, !tbaa !11
  %83 = icmp eq i64 %82, -1
  br i1 %83, label %93, label %84

84:                                               ; preds = %81
  %85 = getelementptr inbounds %struct.logdb_header_t, ptr %12, i32 0, i32 0
  %86 = call i32 @memcmp(ptr noundef %85, ptr noundef @.str.1, i64 noundef 4) #8
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %93, label %88

88:                                               ; preds = %84
  %89 = getelementptr inbounds %struct.logdb_header_t, ptr %12, i32 0, i32 1
  %90 = load i16, ptr %89, align 2, !tbaa !13
  %91 = zext i16 %90 to i32
  %92 = icmp ne i32 %91, 1
  br i1 %92, label %93, label %97

93:                                               ; preds = %88, %84, %81
  %94 = load i32, ptr %10, align 4, !tbaa !9
  %95 = call i32 @close(i32 noundef %94)
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %96) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %98

97:                                               ; preds = %88
  store i32 0, ptr %9, align 4
  br label %98

98:                                               ; preds = %97, %93, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 6, ptr %12) #7
  %99 = load i32, ptr %9, align 4
  switch i32 %99, label %216 [
    i32 0, label %100
  ]

100:                                              ; preds = %98
  br label %101

101:                                              ; preds = %100, %71
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  store i32 1, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  store ptr null, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  %102 = load i32, ptr %5, align 4, !tbaa !9
  %103 = and i32 %102, 2
  %104 = icmp eq i32 %103, 2
  %105 = zext i1 %104 to i32
  store i32 %105, ptr %16, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %166, %101
  %107 = load i32, ptr %10, align 4, !tbaa !9
  %108 = call i32 @flock(i32 noundef %107, i32 noundef 6) #7
  %109 = icmp eq i32 %108, 0
  br i1 %109, label %110, label %136

110:                                              ; preds = %106
  br label %111

111:                                              ; preds = %133, %110
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  %113 = load i32, ptr %10, align 4, !tbaa !9
  %114 = call ptr @logdb_log_create(ptr noundef %112, i32 noundef %113)
  store ptr %114, ptr %15, align 8, !tbaa !5
  %115 = load ptr, ptr %15, align 8, !tbaa !5
  %116 = icmp ne ptr %115, null
  br i1 %116, label %135, label %117

117:                                              ; preds = %111
  %118 = load ptr, ptr %8, align 8, !tbaa !5
  %119 = call ptr @logdb_log_open(ptr noundef %118)
  store ptr %119, ptr %15, align 8, !tbaa !5
  %120 = load ptr, ptr %15, align 8, !tbaa !5
  %121 = icmp ne ptr %120, null
  br i1 %121, label %134, label %122

122:                                              ; preds = %117
  %123 = load i32, ptr %14, align 4, !tbaa !9
  %124 = icmp ne i32 %123, 0
  br i1 %124, label %125, label %129

125:                                              ; preds = %122
  %126 = load ptr, ptr %8, align 8, !tbaa !5
  %127 = call i32 @unlink(ptr noundef %126) #7
  %128 = icmp eq i32 %127, -1
  br i1 %128, label %129, label %133

129:                                              ; preds = %125, %122
  %130 = load i32, ptr %10, align 4, !tbaa !9
  %131 = call i32 @close(i32 noundef %130)
  %132 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %132) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %215

133:                                              ; preds = %125
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %111

134:                                              ; preds = %117
  br label %135

135:                                              ; preds = %134, %111
  br label %144

136:                                              ; preds = %106
  %137 = load i32, ptr %16, align 4, !tbaa !9
  %138 = icmp ne i32 %137, 0
  br i1 %138, label %139, label %143

139:                                              ; preds = %136
  %140 = load i32, ptr %10, align 4, !tbaa !9
  %141 = call i32 @close(i32 noundef %140)
  %142 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %142) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %215

143:                                              ; preds = %136
  br label %144

144:                                              ; preds = %143, %135
  %145 = load i32, ptr %16, align 4, !tbaa !9
  %146 = icmp ne i32 %145, 0
  br i1 %146, label %155, label %147

147:                                              ; preds = %144
  %148 = load i32, ptr %10, align 4, !tbaa !9
  %149 = call i32 @flock(i32 noundef %148, i32 noundef 1) #7
  %150 = icmp ne i32 %149, 0
  br i1 %150, label %151, label %155

151:                                              ; preds = %147
  %152 = load i32, ptr %10, align 4, !tbaa !9
  %153 = call i32 @close(i32 noundef %152)
  %154 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %154) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %215

155:                                              ; preds = %147, %144
  %156 = load ptr, ptr %15, align 8, !tbaa !5
  %157 = icmp ne ptr %156, null
  br i1 %157, label %172, label %158

158:                                              ; preds = %155
  %159 = load ptr, ptr %8, align 8, !tbaa !5
  %160 = call ptr @logdb_log_open(ptr noundef %159)
  store ptr %160, ptr %15, align 8, !tbaa !5
  %161 = load ptr, ptr %15, align 8, !tbaa !5
  %162 = icmp ne ptr %161, null
  br i1 %162, label %171, label %163

163:                                              ; preds = %158
  %164 = load i32, ptr %14, align 4, !tbaa !9
  %165 = icmp ne i32 %164, 0
  br i1 %165, label %166, label %167

166:                                              ; preds = %163
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %106

167:                                              ; preds = %163
  %168 = load i32, ptr %10, align 4, !tbaa !9
  %169 = call i32 @close(i32 noundef %168)
  %170 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %170) #7
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %215

171:                                              ; preds = %158
  br label %172

172:                                              ; preds = %171, %155
  %173 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %173) #7
  %174 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 88) #10
  store ptr %174, ptr %17, align 8, !tbaa !5
  %175 = load ptr, ptr %17, align 8, !tbaa !5
  %176 = icmp ne ptr %175, null
  br i1 %176, label %178, label %177

177:                                              ; preds = %172
  br label %210

178:                                              ; preds = %172
  %179 = load ptr, ptr %17, align 8, !tbaa !5
  %180 = getelementptr inbounds %struct.logdb_connection_t, ptr %179, i32 0, i32 1
  %181 = call i32 @pthread_rwlock_init(ptr noundef %180, ptr noundef null) #7
  store i32 %181, ptr %18, align 4, !tbaa !9
  %182 = load i32, ptr %18, align 4, !tbaa !9
  %183 = icmp ne i32 %182, 0
  br i1 %183, label %184, label %186

184:                                              ; preds = %178
  %185 = load ptr, ptr %17, align 8, !tbaa !5
  call void @free(ptr noundef %185) #7
  br label %210

186:                                              ; preds = %178
  %187 = load ptr, ptr %17, align 8, !tbaa !5
  %188 = getelementptr inbounds %struct.logdb_connection_t, ptr %187, i32 0, i32 5
  %189 = call i32 @pthread_key_create(ptr noundef %188, ptr noundef @logdb_txn_destruct) #7
  store i32 %189, ptr %18, align 4, !tbaa !9
  %190 = load i32, ptr %18, align 4, !tbaa !9
  %191 = icmp ne i32 %190, 0
  br i1 %191, label %192, label %197

192:                                              ; preds = %186
  %193 = load ptr, ptr %17, align 8, !tbaa !5
  %194 = getelementptr inbounds %struct.logdb_connection_t, ptr %193, i32 0, i32 1
  %195 = call i32 @pthread_rwlock_destroy(ptr noundef %194) #7
  %196 = load ptr, ptr %17, align 8, !tbaa !5
  call void @free(ptr noundef %196) #7
  br label %210

197:                                              ; preds = %186
  %198 = load ptr, ptr %17, align 8, !tbaa !5
  %199 = getelementptr inbounds %struct.logdb_connection_t, ptr %198, i32 0, i32 0
  store i16 1, ptr %199, align 8, !tbaa !16
  %200 = load i32, ptr %5, align 4, !tbaa !9
  %201 = load ptr, ptr %17, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct.logdb_connection_t, ptr %201, i32 0, i32 2
  store i32 %200, ptr %202, align 8, !tbaa !18
  %203 = load i32, ptr %10, align 4, !tbaa !9
  %204 = load ptr, ptr %17, align 8, !tbaa !5
  %205 = getelementptr inbounds %struct.logdb_connection_t, ptr %204, i32 0, i32 3
  store i32 %203, ptr %205, align 4, !tbaa !19
  %206 = load ptr, ptr %15, align 8, !tbaa !5
  %207 = load ptr, ptr %17, align 8, !tbaa !5
  %208 = getelementptr inbounds %struct.logdb_connection_t, ptr %207, i32 0, i32 4
  store ptr %206, ptr %208, align 8, !tbaa !20
  %209 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %209, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %215

210:                                              ; preds = %192, %184, %177
  %211 = load ptr, ptr %15, align 8, !tbaa !5
  %212 = call i32 @logdb_log_close(ptr noundef %211)
  %213 = load i32, ptr %10, align 4, !tbaa !9
  %214 = call i32 @close(i32 noundef %213)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %215

215:                                              ; preds = %210, %197, %167, %151, %139, %129
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  br label %216

216:                                              ; preds = %215, %98, %69, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %217

217:                                              ; preds = %216, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %218

218:                                              ; preds = %217, %21
  %219 = load ptr, ptr %3, align 8
  ret ptr %219
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #4

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

declare i64 @logdb_io_write(i32 noundef, ptr noundef, i64 noundef) #5

declare i32 @close(i32 noundef) #5

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

declare i64 @logdb_io_read(i32 noundef, ptr noundef, i64 noundef) #5

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare i32 @flock(i32 noundef, i32 noundef) #4

declare ptr @logdb_log_create(ptr noundef, i32 noundef) #5

declare ptr @logdb_log_open(ptr noundef) #5

; Function Attrs: nounwind
declare i32 @unlink(ptr noundef) #4

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #6

; Function Attrs: nounwind
declare i32 @pthread_rwlock_init(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare i32 @pthread_key_create(ptr noundef, ptr noundef) #4

declare void @logdb_txn_destruct(ptr noundef) #5

; Function Attrs: nounwind
declare i32 @pthread_rwlock_destroy(ptr noundef) #4

declare i32 @logdb_log_close(ptr noundef) #5

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 = { nounwind willreturn memory(read) "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 allocsize(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 "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 #5 = { "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 #6 = { nounwind allocsize(0,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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { nounwind allocsize(0,1) }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !15, i64 4}
!14 = !{!"", !7, i64 0, !15, i64 4}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"", !15, i64 0, !7, i64 8, !10, i64 64, !10, i64 68, !6, i64 72, !10, i64 80}
!18 = !{!17, !10, i64 64}
!19 = !{!17, !10, i64 68}
!20 = !{!17, !6, i64 72}


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

%struct.logdb_header_t = type { [4 x i8], i16 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @logdb_open(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.logdb_header_t, align 2
  %4 = alloca %struct.logdb_header_t, align 2
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %88, label %5

5:                                                ; preds = %2
  %6 = and i32 %1, 1
  %.not90 = icmp eq i32 %6, 0
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #12
  %8 = add i64 %7, 5
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #13
  %.not91 = icmp eq ptr %9, null
  br i1 %.not91, label %88, label %10

10:                                               ; preds = %5
  %spec.select = select i1 %.not90, i32 2, i32 66
  %11 = tail call ptr @strncpy(ptr noundef nonnull %9, ptr noundef nonnull %0, i64 noundef %8) #14
  %12 = tail call ptr @strcat(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) @.str) #14
  %13 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %0, i32 noundef %spec.select, i32 noundef 384) #14
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  tail call void @free(ptr noundef nonnull %9) #14
  br label %88

16:                                               ; preds = %10
  br i1 %.not90, label %23, label %17

17:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 6, ptr nonnull %3) #14
  %18 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef 4) #14
  %19 = getelementptr inbounds i8, ptr %3, i64 4
  store i16 1, ptr %19, align 2, !tbaa !5
  %20 = call i64 @logdb_io_write(i32 noundef %13, ptr noundef nonnull %3, i64 noundef 6) #14
  %.not92 = icmp eq i64 %20, 0
  br i1 %.not92, label %.critedge, label %21

21:                                               ; preds = %17
  %22 = call i32 @close(i32 noundef %13) #14
  call void @free(ptr noundef nonnull %9) #14
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %3) #14
  br label %88

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 6, ptr nonnull %4) #14
  %24 = call i64 @logdb_io_read(i32 noundef %13, ptr noundef nonnull %4, i64 noundef 6) #14
  %25 = icmp sgt i64 %24, 0
  %26 = icmp eq i64 %24, -1
  %or.cond142 = or i1 %25, %26
  br i1 %or.cond142, label %.critedge105, label %27

27:                                               ; preds = %23
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(4) %4, ptr noundef nonnull dereferenceable(4) @.str.1, i64 4)
  %28 = icmp ne i32 %bcmp, 0
  %29 = getelementptr inbounds i8, ptr %4, i64 4
  %30 = load i16, ptr %29, align 2
  %31 = icmp ne i16 %30, 1
  %or.cond = select i1 %28, i1 true, i1 %31
  br i1 %or.cond, label %.critedge105, label %32

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %4) #14
  br label %33

.critedge:                                        ; preds = %17
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %3) #14
  br label %33

33:                                               ; preds = %32, %.critedge
  %34 = and i32 %1, 2
  %.not93 = icmp eq i32 %34, 0
  br i1 %.not93, label %.split.us, label %.split

.split.us:                                        ; preds = %33
  %35 = call i32 @flock(i32 noundef %13, i32 noundef 6) #14
  %.not151 = icmp eq i32 %35, 0
  br i1 %.not151, label %.preheader.us.preheader, label %.thread.us.thread

.preheader.us.preheader:                          ; preds = %.split.us.1, %.split.us
  %36 = call ptr @logdb_log_create(ptr noundef nonnull %9, i32 noundef %13) #14
  %.not94.us.peel = icmp eq ptr %36, null
  br i1 %.not94.us.peel, label %37, label %.thread.us

37:                                               ; preds = %.preheader.us.preheader
  %38 = call ptr @logdb_log_open(ptr noundef nonnull %9) #14
  %.not95.us.peel = icmp eq ptr %38, null
  br i1 %.not95.us.peel, label %39, label %.thread.us

39:                                               ; preds = %37
  br i1 %.not151, label %40, label %.split122.us

40:                                               ; preds = %39
  %41 = call i32 @unlink(ptr noundef nonnull %9) #14
  %42 = icmp eq i32 %41, -1
  br i1 %42, label %.split122.us, label %.preheader.us

.preheader.us:                                    ; preds = %40
  %43 = call ptr @logdb_log_create(ptr noundef nonnull %9, i32 noundef %13) #14
  %.not94.us = icmp eq ptr %43, null
  br i1 %.not94.us, label %44, label %.thread.us

44:                                               ; preds = %.preheader.us
  %45 = call ptr @logdb_log_open(ptr noundef nonnull %9) #14
  %.not95.us = icmp eq ptr %45, null
  br i1 %.not95.us, label %.split122.us, label %.thread.us

.thread.us:                                       ; preds = %.preheader.us.preheader, %37, %.preheader.us, %44
  %.176111.us = phi ptr [ %36, %.preheader.us.preheader ], [ %38, %37 ], [ %43, %.preheader.us ], [ %45, %44 ]
  %46 = call i32 @flock(i32 noundef %13, i32 noundef 1) #14
  %.not97.us = icmp eq i32 %46, 0
  br i1 %.not97.us, label %.thread112, label %.split118.us

.thread.us.thread:                                ; preds = %.split.us
  %47 = call i32 @flock(i32 noundef %13, i32 noundef 1) #14
  %.not97.us131 = icmp eq i32 %47, 0
  br i1 %.not97.us131, label %48, label %.split118.us

48:                                               ; preds = %.thread.us.thread
  %49 = call ptr @logdb_log_open(ptr noundef nonnull %9) #14
  %.not99.us = icmp eq ptr %49, null
  br i1 %.not99.us, label %.split.us.1, label %.thread112

.split.us.1:                                      ; preds = %48
  %50 = call i32 @flock(i32 noundef %13, i32 noundef 6) #14
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %.preheader.us.preheader, label %.thread.us.thread.1

.thread.us.thread.1:                              ; preds = %.split.us.1
  %52 = call i32 @flock(i32 noundef %13, i32 noundef 1) #14
  %.not97.us131.1 = icmp eq i32 %52, 0
  br i1 %.not97.us131.1, label %53, label %.split118.us

53:                                               ; preds = %.thread.us.thread.1
  %54 = call ptr @logdb_log_open(ptr noundef nonnull %9) #14
  %.not99.us.1 = icmp eq ptr %54, null
  br i1 %.not99.us.1, label %.split120.us, label %.thread112

.split120.us:                                     ; preds = %53
  %55 = call i32 @close(i32 noundef %13) #14
  call void @free(ptr noundef %9) #14
  br label %88

.split:                                           ; preds = %33
  %56 = call i32 @flock(i32 noundef %13, i32 noundef 6) #14
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %.preheader.preheader, label %68

.preheader.preheader:                             ; preds = %.split
  %58 = call ptr @logdb_log_create(ptr noundef nonnull %9, i32 noundef %13) #14
  %.not94 = icmp eq ptr %58, null
  br i1 %.not94, label %59, label %.thread112

59:                                               ; preds = %.preheader.preheader
  %60 = call ptr @logdb_log_open(ptr noundef nonnull %9) #14
  %.not95 = icmp eq ptr %60, null
  br i1 %.not95, label %61, label %.thread112

61:                                               ; preds = %59
  %62 = call i32 @unlink(ptr noundef nonnull %9) #14
  %63 = icmp eq i32 %62, -1
  br i1 %63, label %.split122.us, label %.preheader.1

.preheader.1:                                     ; preds = %61
  %64 = call ptr @logdb_log_create(ptr noundef nonnull %9, i32 noundef %13) #14
  %.not94.1 = icmp eq ptr %64, null
  br i1 %.not94.1, label %65, label %.thread112

65:                                               ; preds = %.preheader.1
  %66 = call ptr @logdb_log_open(ptr noundef nonnull %9) #14
  %.not95.1 = icmp eq ptr %66, null
  br i1 %.not95.1, label %.split122.us, label %.thread112

.split122.us:                                     ; preds = %61, %65, %44, %39, %40
  %67 = call i32 @close(i32 noundef %13) #14
  call void @free(ptr noundef %9) #14
  br label %88

68:                                               ; preds = %.split
  %69 = call i32 @close(i32 noundef %13) #14
  call void @free(ptr noundef nonnull %9) #14
  br label %88

.split118.us:                                     ; preds = %.thread.us.thread, %.thread.us.thread.1, %.thread.us
  %70 = call i32 @close(i32 noundef %13) #14
  call void @free(ptr noundef %9) #14
  br label %88

.thread112:                                       ; preds = %48, %53, %.preheader.preheader, %59, %.preheader.1, %65, %.thread.us
  %.us-phi = phi ptr [ %.176111.us, %.thread.us ], [ %60, %59 ], [ %58, %.preheader.preheader ], [ %64, %.preheader.1 ], [ %66, %65 ], [ %49, %48 ], [ %54, %53 ]
  call void @free(ptr noundef %9) #14
  %71 = call noalias dereferenceable_or_null(88) ptr @calloc(i64 noundef 1, i64 noundef 88) #15
  %.not101 = icmp eq ptr %71, null
  br i1 %.not101, label %84, label %72

72:                                               ; preds = %.thread112
  %73 = getelementptr inbounds i8, ptr %71, i64 8
  %74 = call i32 @pthread_rwlock_init(ptr noundef nonnull %73, ptr noundef null) #14
  %.not102 = icmp eq i32 %74, 0
  br i1 %.not102, label %75, label %.sink.split

75:                                               ; preds = %72
  %76 = getelementptr inbounds i8, ptr %71, i64 80
  %77 = call i32 @pthread_key_create(ptr noundef nonnull %76, ptr noundef nonnull @logdb_txn_destruct) #14
  %.not103 = icmp eq i32 %77, 0
  br i1 %.not103, label %80, label %78

78:                                               ; preds = %75
  %79 = call i32 @pthread_rwlock_destroy(ptr noundef nonnull %73) #14
  br label %.sink.split

80:                                               ; preds = %75
  store i16 1, ptr %71, align 8, !tbaa !10
  %81 = getelementptr inbounds i8, ptr %71, i64 64
  store i32 %1, ptr %81, align 8, !tbaa !14
  %82 = getelementptr inbounds i8, ptr %71, i64 68
  store i32 %13, ptr %82, align 4, !tbaa !15
  %83 = getelementptr inbounds i8, ptr %71, i64 72
  store ptr %.us-phi, ptr %83, align 8, !tbaa !16
  br label %88

.sink.split:                                      ; preds = %72, %78
  call void @free(ptr noundef nonnull %71) #14
  br label %84

84:                                               ; preds = %.sink.split, %.thread112
  %85 = call i32 @logdb_log_close(ptr noundef nonnull %.us-phi) #14
  %86 = call i32 @close(i32 noundef %13) #14
  br label %88

.critedge105:                                     ; preds = %27, %23
  %87 = call i32 @close(i32 noundef %13) #14
  call void @free(ptr noundef nonnull %9) #14
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %4) #14
  br label %88

88:                                               ; preds = %21, %5, %.split122.us, %68, %.split118.us, %.split120.us, %80, %84, %.critedge105, %15, %2
  %.5 = phi ptr [ null, %2 ], [ null, %5 ], [ null, %15 ], [ null, %21 ], [ null, %.critedge105 ], [ null, %84 ], [ %71, %80 ], [ null, %.split120.us ], [ null, %.split118.us ], [ null, %.split122.us ], [ null, %68 ]
  ret ptr %.5
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #4

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #6

declare i64 @logdb_io_write(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #7

declare i32 @close(i32 noundef) local_unnamed_addr #7

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

declare i64 @logdb_io_read(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #7

; Function Attrs: nounwind
declare i32 @flock(i32 noundef, i32 noundef) local_unnamed_addr #8

declare ptr @logdb_log_create(ptr noundef, i32 noundef) local_unnamed_addr #7

declare ptr @logdb_log_open(ptr noundef) local_unnamed_addr #7

; Function Attrs: nofree nounwind
declare noundef i32 @unlink(ptr nocapture noundef readonly) local_unnamed_addr #9

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #10

; Function Attrs: nounwind
declare i32 @pthread_rwlock_init(ptr noundef, ptr noundef) local_unnamed_addr #8

; Function Attrs: nounwind
declare i32 @pthread_key_create(ptr noundef, ptr noundef) local_unnamed_addr #8

declare void @logdb_txn_destruct(ptr noundef) #7

; Function Attrs: nounwind
declare i32 @pthread_rwlock_destroy(ptr noundef) local_unnamed_addr #8

declare i32 @logdb_log_close(ptr noundef) local_unnamed_addr #7

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #11

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #5 = { 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 #6 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #7 = { "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 #8 = { 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 #9 = { 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 #10 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #11 = { nofree nounwind willreturn memory(argmem: read) }
attributes #12 = { nounwind willreturn memory(read) }
attributes #13 = { nounwind allocsize(0) }
attributes #14 = { nounwind }
attributes #15 = { nounwind allocsize(0,1) }

!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, !9, i64 4}
!6 = !{!"", !7, i64 0, !9, i64 4}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!11, !9, i64 0}
!11 = !{!"", !9, i64 0, !7, i64 8, !12, i64 64, !12, i64 68, !13, i64 72, !12, i64 80}
!12 = !{!"int", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!11, !12, i64 64}
!15 = !{!11, !12, i64 68}
!16 = !{!11, !13, i64 72}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopInstSimplifyPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass