#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 */
char *do_query(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int blacklisted(sqlite3 *db, const char *device) {
  char query[1000];
  char *row;
  snprintf(query, 1000, "SELECT id FROM blacklist WHERE id='%s';", device);
  if ((row = do_query(db, query, 1))) {
    free(row);
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<blacklisted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x3e8,%esi
lea    0xea6(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    $0x1,%edx
call   1040 <do_query@plt>
mov    %rax,-0x408(%rbp)
cmp    $0x0,%rax
je     119d <blacklisted+0x6d>
mov    -0x408(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a4 <blacklisted+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blacklisted>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rsi,%rcx
mov    %rdi,%rbx
lea    0xeb8(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1050 <snprintf@plt>
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <do_query@plt>
test   %rax,%rax
je     117c <blacklisted+0x4c>
mov    %rax,%rdi
call   1030 <free@plt>
jmp    117e <blacklisted+0x4e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"SELECT id FROM blacklist WHERE id='%s';\00"
define i32 @blacklisted(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [1000 x i8]
%7 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %5
%10 = call i32 @snprintf(i8* %8, i32 1000, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32*, i32** %4
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%13 = call i8* @do_query(i32* %11, i8* %12, i32 1)
store i8* %13, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %7
%17 = call i32 @free(i8* %16)
store i32 1, i32* %3
br label %19
18: ; preds = %2
store i32 0, i32* %3
br label %19
19: ; preds = %18, %15
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [40 x i8] c"SELECT id FROM blacklist WHERE id='%s';\00"
define i32 @blacklisted(i32* %0, i8* %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 1000, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = call i8* @do_query(i32* %0, i8* %4, i32 1)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 @free(i8* %6)
br label %10
10: ; preds = %2, %8
%11 = phi i32 [ 1, %8 ], [ 0, %2 ]
ret i32 %11
}