#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 */
struct sqlConnection {
  int dummy;
};
typedef int /*<<< orphan*/ query;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *cloneOrNull(char *);
int /*<<< orphan*/ sqlNeedQuickQuery(struct sqlConnection *, char *, char *,
                                     int);
int /*<<< orphan*/ sqlSafef(char *, int, char *, int);
char *bioImageAccession(struct sqlConnection *conn, int id) {
  char query[256], buf[256];
  sqlSafef(query, sizeof(query), "select refSeq from image where id=%d", id);
  sqlNeedQuickQuery(conn, query, buf, sizeof(buf));
  if (buf[0] == 0) {
    sqlSafef(query, sizeof(query), "select genbank from image where id=%d", id);
    sqlNeedQuickQuery(conn, query, buf, sizeof(buf));
  }
  return cloneOrNull(buf);
}


x86 assembly (clang, -O0):
<bioImageAccession>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x100,%esi
lea    0xea8(%rip),%rdx
call   1040 <sqlSafef@plt>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
lea    -0x210(%rbp),%rdx
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
movsbl -0x210(%rbp),%eax
cmp    $0x0,%eax
jne    11c0 <bioImageAccession+0x90>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x100,%esi
lea    0xe86(%rip),%rdx
call   1040 <sqlSafef@plt>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
lea    -0x210(%rbp),%rdx
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
lea    -0x210(%rbp),%rdi
call   1050 <cloneOrNull@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bioImageAccession>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb9(%rip),%rdx
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %ebp,%ecx
call   1040 <sqlSafef@plt>
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
cmpb   $0x0,(%rsp)
jne    11a8 <bioImageAccession+0x78>
lea    0xea7(%rip),%rdx
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %ebp,%ecx
call   1040 <sqlSafef@plt>
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
mov    %rsp,%rdi
call   1050 <cloneOrNull@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sqlConnection = type { i32 }
@.str = [37 x i8] c"select refSeq from image where id=%d\00"
@.str.1 = [38 x i8] c"select genbank from image where id=%d\00"
define i8* @bioImageAccession(%struct.sqlConnection* %0, i32 %1) {
%3 = alloca %struct.sqlConnection*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
store %struct.sqlConnection* %0, %struct.sqlConnection** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %4
%9 = call i32 @sqlSafef(i8* %7, i32 256, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load %struct.sqlConnection*, %struct.sqlConnection** %3
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %10, i8* %11, i8* %12, i32 256)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %2
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%20 = load i32, i32* %4
%21 = call i32 @sqlSafef(i8* %19, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load %struct.sqlConnection*, %struct.sqlConnection** %3
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %22, i8* %23, i8* %24, i32 256)
br label %26
26: ; preds = %18, %2
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = call i8* @cloneOrNull(i8* %27)
ret i8* %28
}

LLVM IR (-O2):
%struct.sqlConnection = type { i32 }
@.str = [37 x i8] c"select refSeq from image where id=%d\00"
@.str.1 = [38 x i8] c"select genbank from image where id=%d\00"
define i8* @bioImageAccession(%struct.sqlConnection* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @sqlSafef(i8* %5, i32 256, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %0, i8* %5, i8* %6, i32 256)
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @sqlSafef(i8* %5, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%13 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %0, i8* %5, i8* %6, i32 256)
br label %14
14: ; preds = %11, %2
%15 = call i8* @cloneOrNull(i8* %6)
ret i8* %15
}