#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 SQLITE_OK;
int /*<<< orphan*/ db_make_sanity_check(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *read_path_from_lockfile();
int sqlite3_changes(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/, char **);
int /*<<< orphan*/ sqlite3_free(char *);
char *sqlite3_mprintf(char *, int);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
bool db_delete_entry_by_id(int id, bool *success) {
  char *path = NULL;
  sqlite3 *db;
  int rc;
  char *sql;
  char *error = NULL;
  int count;
  path = read_path_from_lockfile();
  if (!db_make_sanity_check(path)) {
    if (path != NULL)
      free(path);
    return false;
  }
  rc = sqlite3_open(path, &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    free(path);
    return false;
  }
  sql = sqlite3_mprintf("delete from entries where id=%d;", id);
  rc = sqlite3_exec(db, sql, NULL, 0, &error);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Error: %s\n", error);
    sqlite3_free(error);
    sqlite3_free(sql);
    free(path);
    return false;
  }
  count = sqlite3_changes(db);
  if (count > 0)
    *success = true;
  sqlite3_free(sql);
  sqlite3_close(db);
  free(path);
  return true;
}


x86 assembly (clang, -O0):
<db_delete_entry_by_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <read_path_from_lockfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <db_make_sanity_check@plt>
cmp    $0x0,%eax
jne    120c <db_delete_entry_by_id+0x5c>
cmpq   $0x0,-0x18(%rbp)
je     1200 <db_delete_entry_by_id+0x50>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <db_delete_entry_by_id+0x173>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <sqlite3_open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1262 <db_delete_entry_by_id+0xb2>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xdb8(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <db_delete_entry_by_id+0x173>
mov    -0x8(%rbp),%esi
lea    0xdad(%rip),%rdi
call   10d0 <sqlite3_mprintf@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x38(%rbp),%r8
call   1050 <sqlite3_exec@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d4f(%rip),%rcx
cmp    (%rcx),%eax
je     12e1 <db_delete_entry_by_id+0x131>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd85(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   10c0 <sqlite3_free@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <sqlite3_free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <db_delete_entry_by_id+0x173>
mov    -0x20(%rbp),%rdi
call   10a0 <sqlite3_changes@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jle    1301 <db_delete_entry_by_id+0x151>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x30(%rbp),%rdi
call   10c0 <sqlite3_free@plt>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_close@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_delete_entry_by_id>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
movq   $0x0,0x8(%rsp)
xor    %r14d,%r14d
xor    %eax,%eax
call   10b0 <read_path_from_lockfile@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <db_make_sanity_check@plt>
test   %eax,%eax
je     1225 <db_delete_entry_by_id+0x75>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <sqlite3_open@plt>
test   %eax,%eax
je     1233 <db_delete_entry_by_id+0x83>
mov    0x2ddf(%rip),%rax
mov    (%rax),%ebp
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xdf5(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %r14d,%r14d
jmp    12d0 <db_delete_entry_by_id+0x120>
test   %rbx,%rbx
jne    12c8 <db_delete_entry_by_id+0x118>
jmp    12d0 <db_delete_entry_by_id+0x120>
lea    0xddf(%rip),%rdi
mov    %ebp,%esi
call   10d0 <sqlite3_mprintf@plt>
mov    %rax,%r12
mov    (%rsp),%rdi
xor    %r14d,%r14d
lea    0x8(%rsp),%r8
mov    %rax,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <sqlite3_exec@plt>
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
jne    129c <db_delete_entry_by_id+0xec>
mov    (%rsp),%rdi
call   10a0 <sqlite3_changes@plt>
test   %eax,%eax
jle    127b <db_delete_entry_by_id+0xcb>
movl   $0x1,(%r15)
mov    %r12,%rdi
call   10c0 <sqlite3_free@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    $0x1,%r14d
jmp    12d0 <db_delete_entry_by_id+0x120>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xd89(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_free@plt>
mov    %r12,%rdi
call   10c0 <sqlite3_free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Can't open database: %s\0A\00"
@.str.1 = [33 x i8] c"delete from entries where id=%d;\00"
@SQLITE_OK = global i32 0
@.str.2 = [11 x i8] c"Error: %s\0A\00"
define i32 @db_delete_entry_by_id(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* null, i8** %6
store i8* null, i8** %10
%12 = call i8* (...) @read_path_from_lockfile()
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = call i32 @db_make_sanity_check(i8* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %19, %16
store i32 0, i32* %3
br label %68
23: ; preds = %2
%24 = load i8*, i8** %6
%25 = call i32 @sqlite3_open(i8* %24, i32** %7)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = load i32*, i32** %7
%31 = call i8* @sqlite3_errmsg(i32* %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
store i32 0, i32* %3
br label %68
35: ; preds = %23
%36 = load i32, i32* %4
%37 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %36)
store i8* %37, i8** %9
%38 = load i32*, i32** %7
%39 = load i8*, i8** %9
%40 = call i32 @sqlite3_exec(i32* %38, i8* %39, i32* null, i32 0, i8** %10)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = load i32, i32* @SQLITE_OK
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %54
44: ; preds = %35
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %10
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %10
%49 = call i32 @sqlite3_free(i8* %48)
%50 = load i8*, i8** %9
%51 = call i32 @sqlite3_free(i8* %50)
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
store i32 0, i32* %3
br label %68
54: ; preds = %35
%55 = load i32*, i32** %7
%56 = call i32 @sqlite3_changes(i32* %55)
store i32 %56, i32* %11
%57 = load i32, i32* %11
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = load i32*, i32** %5
store i32 1, i32* %60
br label %61
61: ; preds = %59, %54
%62 = load i8*, i8** %9
%63 = call i32 @sqlite3_free(i8* %62)
%64 = load i32*, i32** %7
%65 = call i32 @sqlite3_close(i32* %64)
%66 = load i8*, i8** %6
%67 = call i32 @free(i8* %66)
store i32 1, i32* %3
br label %68
68: ; preds = %61, %44, %28, %22
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Can't open database: %s\0A\00"
@.str.1 = [33 x i8] c"delete from entries where id=%d;\00"
@SQLITE_OK = global i32 0
@.str.2 = [11 x i8] c"Error: %s\0A\00"
define i32 @db_delete_entry_by_id(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = bitcast i32** %3 to i8*
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = tail call i8* (...) @read_path_from_lockfile()
%8 = tail call i32 @db_make_sanity_check(i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = icmp eq i8* %7, null
br i1 %11, label %47, label %12
12: ; preds = %10
%13 = tail call i32 @free(i8* %7)
br label %47
14: ; preds = %2
%15 = call i32 @sqlite3_open(i8* %7, i32** %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i32*, i32** %3
%20 = call i8* @sqlite3_errmsg(i32* %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @free(i8* %7)
br label %47
23: ; preds = %14
%24 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%25 = load i32*, i32** %3
%26 = call i32 @sqlite3_exec(i32* %25, i8* %24, i32* null, i32 0, i8** %4)
%27 = load i32, i32* @SQLITE_OK
%28 = icmp eq i32 %26, %27
br i1 %28, label %37, label %29
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %4
%34 = call i32 @sqlite3_free(i8* %33)
%35 = call i32 @sqlite3_free(i8* %24)
%36 = call i32 @free(i8* %7)
br label %47
37: ; preds = %23
%38 = load i32*, i32** %3
%39 = call i32 @sqlite3_changes(i32* %38)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 1, i32* %1
br label %42
42: ; preds = %41, %37
%43 = call i32 @sqlite3_free(i8* %24)
%44 = load i32*, i32** %3
%45 = call i32 @sqlite3_close(i32* %44)
%46 = call i32 @free(i8* %7)
br label %47
47: ; preds = %10, %12, %42, %29, %17
%48 = phi i32 [ 0, %17 ], [ 0, %29 ], [ 1, %42 ], [ 0, %12 ], [ 0, %10 ]
ret i32 %48
}