#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 */
scalar_t__ db_active_status(int /*<<< orphan*/ *, char const *, long const);
int db_total_posts(int /*<<< orphan*/ *, char const *, long const);
int /*<<< orphan*/ db_transaction(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ free(char *);
char *sql_generate(char const *, int /*<<< orphan*/, char const *, long const);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int db_bump_parent(sqlite3 *db, const char *board_id, const long id) {
  static const char *sql = "UPDATE active_threads SET last_bump = %ld "
                           "WHERE board_id = \"%s\" AND post_id = %ld;";
  int bumped = 0;
  if (db_active_status(db, board_id, id)) {
    if (db_total_posts(db, board_id, id) <= 300) {
      char *cmd = sql_generate(sql, time(NULL), board_id, id);
      bumped = !db_transaction(db, cmd);
      free(cmd);
    }
  }
  return bumped;
}


x86 assembly (clang, -O0):
<db_bump_parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <db_active_status@plt>
cmp    $0x0,%rax
je     1208 <db_bump_parent+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <db_total_posts@plt>
cmp    $0x12c,%eax
jg     1203 <db_bump_parent+0xa3>
mov    0x2e97(%rip),%rax
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <sql_generate@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <db_transaction@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1208 <db_bump_parent+0xa8>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_bump_parent>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
call   1060 <db_active_status@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11ca <db_bump_parent+0x6a>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <db_total_posts@plt>
cmp    $0x12c,%eax
jg     11ca <db_bump_parent+0x6a>
xor    %edi,%edi
call   1080 <time@plt>
lea    0xe61(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1050 <sql_generate@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <db_transaction@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@db_bump_parent.sql = internal global i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i32 0, i32 0)
@.str = [83 x i8] c"UPDATE active_threads SET last_bump = %ld WHERE board_id = \22%s\22 AND post_id = %ld;\00"
define i32 @db_bump_parent(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%9 = load i32*, i32** %4
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = call i64 @db_active_status(i32* %9, i8* %10, i64 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %3
%15 = load i32*, i32** %4
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = call i32 @db_total_posts(i32* %15, i8* %16, i64 %17)
%19 = icmp sle i32 %18, 300
br i1 %19, label %20, label %34
20: ; preds = %14
%21 = load i8*, i8** @db_bump_parent.sql
%22 = call i32 @time(i32* null)
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i8* @sql_generate(i8* %21, i32 %22, i8* %23, i64 %24)
store i8* %25, i8** %8
%26 = load i32*, i32** %4
%27 = load i8*, i8** %8
%28 = call i32 @db_transaction(i32* %26, i8* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
%31 = zext i1 %30 to i32
store i32 %31, i32* %7
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %20, %14
br label %35
35: ; preds = %34, %3
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@.str = [83 x i8] c"UPDATE active_threads SET last_bump = %ld WHERE board_id = \22%s\22 AND post_id = %ld;\00"
define i32 @db_bump_parent(i32* %0, i8* %1, i64 %2) {
%4 = tail call i64 @db_active_status(i32* %0, i8* %1, i64 %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i32 @db_total_posts(i32* %0, i8* %1, i64 %2)
%8 = icmp slt i32 %7, 301
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = tail call i32 @time(i32* null)
%11 = tail call i8* @sql_generate(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %1, i64 %2)
%12 = tail call i32 @db_transaction(i32* %0, i8* %11)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @free(i8* %11)
br label %16
16: ; preds = %6, %9, %3
%17 = phi i32 [ %14, %9 ], [ 0, %6 ], [ 0, %3 ]
ret i32 %17
}