#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_stmt;

/* Variables and functions */
int SQLITE_DONE;
int /*<<< orphan*/ finishedStmt(int /*<<< orphan*/ *);
int /*<<< orphan*/ *getStmt(char *);
int /*<<< orphan*/ logMsg(int, char *, int);
int /*<<< orphan*/ sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int sqlite3_step(int /*<<< orphan*/ *);
int doRemoveAlert(int id) {
  int rc;
  int status;
  sqlite3_stmt *stmtDeleteAlert = getStmt("DELETE FROM alert WHERE id=?;");
  sqlite3_stmt *stmtDeleteInterval =
      getStmt("DELETE FROM interval WHERE id IN (SELECT interval_id FROM "
              "alert_interval WHERE alert_id=? UNION SELECT bound FROM alert "
              "WHERE id=?);");
  sqlite3_stmt *stmtDeleteIntervalAlert =
      getStmt("DELETE FROM alert_interval WHERE alert_id=?;");
  sqlite3_bind_int(stmtDeleteInterval, 1, id);
  sqlite3_bind_int(stmtDeleteInterval, 2, id);
  rc = sqlite3_step(stmtDeleteInterval);
  if (rc == SQLITE_DONE) {
    status = 1;
  } else {
    logMsg(4, "stmtDeleteInterval failed: %d", rc);
    status = 0;
  }
  if (status == 1) {
    sqlite3_bind_int(stmtDeleteAlert, 1, id);
    rc = sqlite3_step(stmtDeleteAlert);
    if (rc == SQLITE_DONE) {
      status = 1;
    } else {
      logMsg(4, "stmtDeleteAlert failed: %d", rc);
      status = 0;
    }
  }
  if (status == 1) {
    sqlite3_bind_int(stmtDeleteIntervalAlert, 1, id);
    rc = sqlite3_step(stmtDeleteIntervalAlert);
    if (rc == SQLITE_DONE) {
      status = 1;
    } else {
      logMsg(4, "stmtDeleteIntervalAlert failed: %d", rc);
      status = 0;
    }
  }
  finishedStmt(stmtDeleteIntervalAlert);
  finishedStmt(stmtDeleteInterval);
  finishedStmt(stmtDeleteAlert);
  return status;
}


x86 assembly (clang, -O0):
<doRemoveAlert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,-0x18(%rbp)
lea    0xeac(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,-0x20(%rbp)
lea    0xf21(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0x2,%esi
call   1030 <sqlite3_bind_int@plt>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%eax
jne    11d7 <doRemoveAlert+0x87>
movl   $0x1,-0xc(%rbp)
jmp    11f2 <doRemoveAlert+0xa2>
mov    -0x8(%rbp),%edx
mov    $0x4,%edi
lea    0xeea(%rip),%rsi
call   1040 <logMsg@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1257 <doRemoveAlert+0x107>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int@plt>
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%eax
jne    1237 <doRemoveAlert+0xe7>
movl   $0x1,-0xc(%rbp)
jmp    1252 <doRemoveAlert+0x102>
mov    -0x8(%rbp),%edx
mov    $0x4,%edi
lea    0xea8(%rip),%rsi
call   1040 <logMsg@plt>
movl   $0x0,-0xc(%rbp)
jmp    1257 <doRemoveAlert+0x107>
cmpl   $0x1,-0xc(%rbp)
jne    12bc <doRemoveAlert+0x16c>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int@plt>
mov    -0x28(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%eax
jne    129c <doRemoveAlert+0x14c>
movl   $0x1,-0xc(%rbp)
jmp    12b7 <doRemoveAlert+0x167>
mov    -0x8(%rbp),%edx
mov    $0x4,%edi
lea    0xe5e(%rip),%rsi
call   1040 <logMsg@plt>
movl   $0x0,-0xc(%rbp)
jmp    12bc <doRemoveAlert+0x16c>
mov    -0x28(%rbp),%rdi
call   1070 <finishedStmt@plt>
mov    -0x20(%rbp),%rdi
call   1070 <finishedStmt@plt>
mov    -0x18(%rbp),%rdi
call   1070 <finishedStmt@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doRemoveAlert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xe9c(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,%r14
lea    0xeab(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,%rbx
lea    0xf21(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1030 <sqlite3_bind_int@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %ebp,%edx
call   1030 <sqlite3_bind_int@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
mov    0x2e29(%rip),%r13
cmp    0x0(%r13),%eax
jne    1206 <doRemoveAlert+0xb6>
mov    $0x1,%r12d
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1030 <sqlite3_bind_int@plt>
mov    %r14,%rdi
call   1050 <sqlite3_step@plt>
cmp    0x0(%r13),%eax
jne    120f <doRemoveAlert+0xbf>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1030 <sqlite3_bind_int@plt>
mov    %r15,%rdi
call   1050 <sqlite3_step@plt>
cmp    0x0(%r13),%eax
je     1225 <doRemoveAlert+0xd5>
lea    0xf05(%rip),%rsi
jmp    1216 <doRemoveAlert+0xc6>
lea    0xec3(%rip),%rsi
jmp    1216 <doRemoveAlert+0xc6>
lea    0xed8(%rip),%rsi
mov    $0x4,%edi
mov    %eax,%edx
call   1040 <logMsg@plt>
xor    %r12d,%r12d
mov    %r15,%rdi
call   1070 <finishedStmt@plt>
mov    %rbx,%rdi
call   1070 <finishedStmt@plt>
mov    %r14,%rdi
call   1070 <finishedStmt@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"DELETE FROM alert WHERE id=?;\00"
@.str.1 = [133 x i8] c"DELETE FROM interval WHERE id IN (SELECT interval_id FROM alert_interval WHERE alert_id=? UNION SELECT bound FROM alert WHERE id=?);\00"
@.str.2 = [45 x i8] c"DELETE FROM alert_interval WHERE alert_id=?;\00"
@SQLITE_DONE = global i32 0
@.str.3 = [30 x i8] c"stmtDeleteInterval failed: %d\00"
@.str.4 = [27 x i8] c"stmtDeleteAlert failed: %d\00"
@.str.5 = [35 x i8] c"stmtDeleteIntervalAlert failed: %d\00"
define i32 @doRemoveAlert(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %2
%8 = call i32* @getStmt(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = call i32* @getStmt(i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = call i32* @getStmt(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %6
%12 = load i32, i32* %2
%13 = call i32 @sqlite3_bind_int(i32* %11, i32 1, i32 %12)
%14 = load i32*, i32** %6
%15 = load i32, i32* %2
%16 = call i32 @sqlite3_bind_int(i32* %14, i32 2, i32 %15)
%17 = load i32*, i32** %6
%18 = call i32 @sqlite3_step(i32* %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = load i32, i32* @SQLITE_DONE
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %1
store i32 1, i32* %4
br label %26
23: ; preds = %1
%24 = load i32, i32* %3
%25 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %24)
store i32 0, i32* %4
br label %26
26: ; preds = %23, %22
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %43
29: ; preds = %26
%30 = load i32*, i32** %5
%31 = load i32, i32* %2
%32 = call i32 @sqlite3_bind_int(i32* %30, i32 1, i32 %31)
%33 = load i32*, i32** %5
%34 = call i32 @sqlite3_step(i32* %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = load i32, i32* @SQLITE_DONE
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %29
store i32 1, i32* %4
br label %42
39: ; preds = %29
%40 = load i32, i32* %3
%41 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %40)
store i32 0, i32* %4
br label %42
42: ; preds = %39, %38
br label %43
43: ; preds = %42, %26
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %60
46: ; preds = %43
%47 = load i32*, i32** %7
%48 = load i32, i32* %2
%49 = call i32 @sqlite3_bind_int(i32* %47, i32 1, i32 %48)
%50 = load i32*, i32** %7
%51 = call i32 @sqlite3_step(i32* %50)
store i32 %51, i32* %3
%52 = load i32, i32* %3
%53 = load i32, i32* @SQLITE_DONE
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %46
store i32 1, i32* %4
br label %59
56: ; preds = %46
%57 = load i32, i32* %3
%58 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %57)
store i32 0, i32* %4
br label %59
59: ; preds = %56, %55
br label %60
60: ; preds = %59, %43
%61 = load i32*, i32** %7
%62 = call i32 @finishedStmt(i32* %61)
%63 = load i32*, i32** %6
%64 = call i32 @finishedStmt(i32* %63)
%65 = load i32*, i32** %5
%66 = call i32 @finishedStmt(i32* %65)
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
@.str = [30 x i8] c"DELETE FROM alert WHERE id=?;\00"
@.str.1 = [133 x i8] c"DELETE FROM interval WHERE id IN (SELECT interval_id FROM alert_interval WHERE alert_id=? UNION SELECT bound FROM alert WHERE id=?);\00"
@.str.2 = [45 x i8] c"DELETE FROM alert_interval WHERE alert_id=?;\00"
@SQLITE_DONE = global i32 0
@.str.3 = [30 x i8] c"stmtDeleteInterval failed: %d\00"
@.str.4 = [27 x i8] c"stmtDeleteAlert failed: %d\00"
@.str.5 = [35 x i8] c"stmtDeleteIntervalAlert failed: %d\00"
define i32 @doRemoveAlert(i32 %0) {
%2 = tail call i32* @getStmt(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @getStmt(i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @getStmt(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @sqlite3_bind_int(i32* %3, i32 1, i32 %0)
%6 = tail call i32 @sqlite3_bind_int(i32* %3, i32 2, i32 %0)
%7 = tail call i32 @sqlite3_step(i32* %3)
%8 = load i32, i32* @SQLITE_DONE
%9 = icmp eq i32 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 @logMsg(i32 4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %26
12: ; preds = %1
%13 = tail call i32 @sqlite3_bind_int(i32* %2, i32 1, i32 %0)
%14 = tail call i32 @sqlite3_step(i32* %2)
%15 = load i32, i32* @SQLITE_DONE
%16 = icmp eq i32 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = tail call i32 @logMsg(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %26
19: ; preds = %12
%20 = tail call i32 @sqlite3_bind_int(i32* %4, i32 1, i32 %0)
%21 = tail call i32 @sqlite3_step(i32* %4)
%22 = load i32, i32* @SQLITE_DONE
%23 = icmp eq i32 %21, %22
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = tail call i32 @logMsg(i32 4, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %26
26: ; preds = %10, %19, %17, %24
%27 = phi i32 [ 0, %24 ], [ 0, %17 ], [ 1, %19 ], [ 0, %10 ]
%28 = tail call i32 @finishedStmt(i32* %4)
%29 = tail call i32 @finishedStmt(i32* %3)
%30 = tail call i32 @finishedStmt(i32* %2)
ret i32 %27
}