#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ LOG_DEBUG;
int SQLITE_OK;
int /*<<< orphan*/ beholddb_exec_bind_text(int /*<<< orphan*/ *, char *,
                                           char const *);
scalar_t__ sqlite3_changes(int /*<<< orphan*/ *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int beholddb_mark_worker(sqlite3 *db, const char *file, int *pchanges) {
  int changes = 0;
  syslog(LOG_DEBUG, "beholddb_mark_worker(%s)", file);
  beholddb_exec_bind_text(db,
                          "insert into files_tags ( id_file, id_tag ) "
                          "select f.id, t.id "
                          "from files f "
                          "join include t "
                          "where f.name = ?",
                          file);
  changes += sqlite3_changes(db);
  beholddb_exec_bind_text(db,
                          "delete from files_tags "
                          "where id_file = "
                          "( select id from files where name = ? ) "
                          "and id_tag in "
                          "( select id from exclude )",
                          file);
  changes += sqlite3_changes(db);
  {
    beholddb_exec_bind_text(db,
                            "insert into dirs_tags ( id_file, id_tag ) "
                            "select f.id, t.id "
                            "from files f "
                            "join dirs_include t "
                            "where f.name = ?",
                            file);
    changes += sqlite3_changes(db);
    beholddb_exec_bind_text(db,
                            "delete from dirs_tags "
                            "where id_file = "
                            "( select id from files where name = ? ) "
                            "and id_tag in "
                            "( select id from dirs_exclude )",
                            file);
    changes += sqlite3_changes(db);
  }
  if (pchanges)
    *pchanges = changes;
  syslog(LOG_DEBUG, "beholddb_mark_worker: changes=%d", changes);
  return SQLITE_OK;
}


x86 assembly (clang, -O0):
<beholddb_mark_worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xea1(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xea4(%rip),%rsi
call   1030 <beholddb_exec_bind_text@plt>
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_changes@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xee4(%rip),%rsi
call   1030 <beholddb_exec_bind_text@plt>
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_changes@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xf32(%rip),%rsi
call   1030 <beholddb_exec_bind_text@plt>
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_changes@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xf76(%rip),%rsi
call   1030 <beholddb_exec_bind_text@plt>
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_changes@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1222 <beholddb_mark_worker+0xf2>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xfb0(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beholddb_mark_worker>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e8d(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xeab(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <syslog@plt>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <beholddb_exec_bind_text@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_changes@plt>
mov    %rax,%r12
lea    0xf00(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <beholddb_exec_bind_text@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_changes@plt>
mov    %rax,%r13
add    %r12d,%r13d
lea    0xf58(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <beholddb_exec_bind_text@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_changes@plt>
mov    %rax,%r12
add    %r13d,%r12d
lea    0xfa6(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <beholddb_exec_bind_text@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_changes@plt>
add    %r12d,%eax
test   %r14,%r14
je     11e1 <beholddb_mark_worker+0xb1>
mov    %eax,(%r14)
mov    0x0(%rbp),%edi
lea    0xffa(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <syslog@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_DEBUG = global i32 0
@.str = [25 x i8] c"beholddb_mark_worker(%s)\00"
@.str.1 = [106 x i8] c"insert into files_tags ( id_file, id_tag ) select f.id, t.id from files f join include t where f.name = ?\00"
@.str.2 = [120 x i8] c"delete from files_tags where id_file = ( select id from files where name = ? ) and id_tag in ( select id from exclude )\00"
@.str.3 = [110 x i8] c"insert into dirs_tags ( id_file, id_tag ) select f.id, t.id from files f join dirs_include t where f.name = ?\00"
@.str.4 = [124 x i8] c"delete from dirs_tags where id_file = ( select id from files where name = ? ) and id_tag in ( select id from dirs_exclude )\00"
@.str.5 = [33 x i8] c"beholddb_mark_worker: changes=%d\00"
@SQLITE_OK = global i32 0
define i32 @beholddb_mark_worker(i32* %0, i8* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%8 = load i32, i32* @LOG_DEBUG
%9 = load i8*, i8** %5
%10 = call i32 (i32, i8*, ...) @syslog(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32*, i32** %4
%12 = load i8*, i8** %5
%13 = call i32 @beholddb_exec_bind_text(i32* %11, i8* getelementptr inbounds ([106 x i8], [106 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %4
%15 = call i64 @sqlite3_changes(i32* %14)
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = add nsw i64 %17, %15
%19 = trunc i64 %18 to i32
store i32 %19, i32* %7
%20 = load i32*, i32** %4
%21 = load i8*, i8** %5
%22 = call i32 @beholddb_exec_bind_text(i32* %20, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %4
%24 = call i64 @sqlite3_changes(i32* %23)
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = add nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %7
%29 = load i32*, i32** %4
%30 = load i8*, i8** %5
%31 = call i32 @beholddb_exec_bind_text(i32* %29, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %4
%33 = call i64 @sqlite3_changes(i32* %32)
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %7
%38 = load i32*, i32** %4
%39 = load i8*, i8** %5
%40 = call i32 @beholddb_exec_bind_text(i32* %38, i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %4
%42 = call i64 @sqlite3_changes(i32* %41)
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %7
%47 = load i32*, i32** %6
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %52
49: ; preds = %3
%50 = load i32, i32* %7
%51 = load i32*, i32** %6
store i32 %50, i32* %51
br label %52
52: ; preds = %49, %3
%53 = load i32, i32* @LOG_DEBUG
%54 = load i32, i32* %7
%55 = call i32 (i32, i8*, ...) @syslog(i32 %53, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %54)
%56 = load i32, i32* @SQLITE_OK
ret i32 %56
}

LLVM IR (-O2):
@LOG_DEBUG = global i32 0
@.str = [25 x i8] c"beholddb_mark_worker(%s)\00"
@.str.1 = [106 x i8] c"insert into files_tags ( id_file, id_tag ) select f.id, t.id from files f join include t where f.name = ?\00"
@.str.2 = [120 x i8] c"delete from files_tags where id_file = ( select id from files where name = ? ) and id_tag in ( select id from exclude )\00"
@.str.3 = [110 x i8] c"insert into dirs_tags ( id_file, id_tag ) select f.id, t.id from files f join dirs_include t where f.name = ?\00"
@.str.4 = [124 x i8] c"delete from dirs_tags where id_file = ( select id from files where name = ? ) and id_tag in ( select id from dirs_exclude )\00"
@.str.5 = [33 x i8] c"beholddb_mark_worker: changes=%d\00"
@SQLITE_OK = global i32 0
define i32 @beholddb_mark_worker(i32* %0, i8* %1, i32* writeonly %2) {
%4 = load i32, i32* @LOG_DEBUG
%5 = tail call i32 (i32, i8*, ...) @syslog(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = tail call i32 @beholddb_exec_bind_text(i32* %0, i8* getelementptr inbounds ([106 x i8], [106 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = tail call i64 @sqlite3_changes(i32* %0)
%8 = tail call i32 @beholddb_exec_bind_text(i32* %0, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%9 = tail call i64 @sqlite3_changes(i32* %0)
%10 = add i64 %9, %7
%11 = tail call i32 @beholddb_exec_bind_text(i32* %0, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%12 = tail call i64 @sqlite3_changes(i32* %0)
%13 = add i64 %10, %12
%14 = tail call i32 @beholddb_exec_bind_text(i32* %0, i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%15 = tail call i64 @sqlite3_changes(i32* %0)
%16 = add i64 %13, %15
%17 = trunc i64 %16 to i32
%18 = icmp eq i32* %2, null
br i1 %18, label %20, label %19
19: ; preds = %3
store i32 %17, i32* %2
br label %20
20: ; preds = %19, %3
%21 = load i32, i32* @LOG_DEBUG
%22 = tail call i32 (i32, i8*, ...) @syslog(i32 %21, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%23 = load i32, i32* @SQLITE_OK
ret i32 %23
}