#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*/ locusLink;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *cloneString(char *);
int /*<<< orphan*/ safef(char *, int, char *, char *);
int /*<<< orphan*/ sqlNeedQuickQuery(struct sqlConnection *, char *, char *,
                                     int);
int /*<<< orphan*/ sqlSafef(char *, int, char *, int);
char *bioImageGeneName(struct sqlConnection *conn, int id) {
  char query[256], buf[256];
  sqlSafef(query, sizeof(query), "select gene from image where id=%d", id);
  sqlNeedQuickQuery(conn, query, buf, sizeof(buf));
  if (buf[0] == 0) {
    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));
      if (buf[0] == 0) {
        char locusLink[32];
        sqlSafef(query, sizeof(query),
                 "select locusLink from image where id=%d", id);
        sqlNeedQuickQuery(conn, query, locusLink, sizeof(locusLink));
        if (locusLink[0] == 0) {
          sqlSafef(query, sizeof(query),
                   "select submitId from image where id=%d", id);
          sqlNeedQuickQuery(conn, query, buf, sizeof(buf));
        } else {
          safef(buf, sizeof(buf), "NCBI Gene ID #%s", locusLink);
        }
      }
    }
  }
  return cloneString(buf);
}


x86 assembly (clang, -O0):
<bioImageGeneName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x100,%esi
lea    0xe98(%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    12d8 <bioImageGeneName+0x198>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x100,%esi
lea    0xe74(%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    12d3 <bioImageGeneName+0x193>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x100,%esi
lea    0xe52(%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    12ce <bioImageGeneName+0x18e>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x100,%esi
lea    0xe31(%rip),%rdx
call   1040 <sqlSafef@plt>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
lea    -0x230(%rbp),%rdx
mov    $0x20,%ecx
call   1030 <sqlNeedQuickQuery@plt>
movsbl -0x230(%rbp),%eax
cmp    $0x0,%eax
jne    12aa <bioImageGeneName+0x16a>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x100,%esi
lea    0xe12(%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>
jmp    12c9 <bioImageGeneName+0x189>
lea    -0x210(%rbp),%rdi
lea    -0x230(%rbp),%rcx
mov    $0x100,%esi
lea    0xdf9(%rip),%rdx
call   1060 <safef@plt>
jmp    12ce <bioImageGeneName+0x18e>
jmp    12d3 <bioImageGeneName+0x193>
jmp    12d8 <bioImageGeneName+0x198>
lea    -0x210(%rbp),%rdi
call   1050 <cloneString@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bioImageGeneName>:
push   %rbp
push   %r14
push   %rbx
sub    $0x220,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea9(%rip),%rdx
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %ebp,%ecx
call   1040 <sqlSafef@plt>
lea    0x20(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
cmpb   $0x0,0x20(%rsp)
jne    128f <bioImageGeneName+0x14f>
lea    0xe8e(%rip),%rdx
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %ebp,%ecx
call   1040 <sqlSafef@plt>
lea    0x20(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
cmpb   $0x0,0x20(%rsp)
jne    128f <bioImageGeneName+0x14f>
lea    0xe75(%rip),%rdx
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %ebp,%ecx
call   1040 <sqlSafef@plt>
lea    0x20(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
cmpb   $0x0,0x20(%rsp)
jne    128f <bioImageGeneName+0x14f>
lea    0xe5d(%rip),%rdx
lea    0x120(%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    $0x20,%ecx
call   1030 <sqlNeedQuickQuery@plt>
cmpb   $0x0,(%rsp)
je     125c <bioImageGeneName+0x11c>
lea    0xe75(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x100,%esi
call   1060 <safef@plt>
jmp    128f <bioImageGeneName+0x14f>
lea    0xe33(%rip),%rdx
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %ebp,%ecx
call   1040 <sqlSafef@plt>
lea    0x20(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%ecx
call   1030 <sqlNeedQuickQuery@plt>
lea    0x20(%rsp),%rdi
call   1050 <cloneString@plt>
add    $0x220,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sqlConnection = type { i32 }
@.str = [35 x i8] c"select gene from image where id=%d\00"
@.str.1 = [37 x i8] c"select refSeq from image where id=%d\00"
@.str.2 = [38 x i8] c"select genbank from image where id=%d\00"
@.str.3 = [40 x i8] c"select locusLink from image where id=%d\00"
@.str.4 = [39 x i8] c"select submitId from image where id=%d\00"
@.str.5 = [17 x i8] c"NCBI Gene ID #%s\00"
define i8* @bioImageGeneName(%struct.sqlConnection* %0, i32 %1) {
%3 = alloca %struct.sqlConnection*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca [32 x i8]
store %struct.sqlConnection* %0, %struct.sqlConnection** %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 @sqlSafef(i8* %8, i32 256, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load %struct.sqlConnection*, %struct.sqlConnection** %3
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%14 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %11, i8* %12, i8* %13, i32 256)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %70
19: ; preds = %2
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %4
%22 = call i32 @sqlSafef(i8* %20, i32 256, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load %struct.sqlConnection*, %struct.sqlConnection** %3
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%26 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %23, i8* %24, i8* %25, i32 256)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %69
31: ; preds = %19
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%33 = load i32, i32* %4
%34 = call i32 @sqlSafef(i8* %32, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load %struct.sqlConnection*, %struct.sqlConnection** %3
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%38 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %35, i8* %36, i8* %37, i32 256)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %68
43: ; preds = %31
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%45 = load i32, i32* %4
%46 = call i32 @sqlSafef(i8* %44, i32 256, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = load %struct.sqlConnection*, %struct.sqlConnection** %3
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%50 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %47, i8* %48, i8* %49, i32 32)
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %43
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%57 = load i32, i32* %4
%58 = call i32 @sqlSafef(i8* %56, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %57)
%59 = load %struct.sqlConnection*, %struct.sqlConnection** %3
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%62 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %59, i8* %60, i8* %61, i32 256)
br label %67
63: ; preds = %43
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%65 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%66 = call i32 @safef(i8* %64, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %63, %55
br label %68
68: ; preds = %67, %31
br label %69
69: ; preds = %68, %19
br label %70
70: ; preds = %69, %2
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%72 = call i8* @cloneString(i8* %71)
ret i8* %72
}

LLVM IR (-O2):
%struct.sqlConnection = type { i32 }
@.str = [35 x i8] c"select gene from image where id=%d\00"
@.str.1 = [37 x i8] c"select refSeq from image where id=%d\00"
@.str.2 = [38 x i8] c"select genbank from image where id=%d\00"
@.str.3 = [40 x i8] c"select locusLink from image where id=%d\00"
@.str.4 = [39 x i8] c"select submitId from image where id=%d\00"
@.str.5 = [17 x i8] c"NCBI Gene ID #%s\00"
define i8* @bioImageGeneName(%struct.sqlConnection* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = call i32 @sqlSafef(i8* %6, i32 256, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %1)
%9 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %0, i8* %6, i8* %7, i32 256)
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %2
%13 = call i32 @sqlSafef(i8* %6, i32 256, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%14 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %0, i8* %6, i8* %7, i32 256)
%15 = load i8, i8* %7
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = call i32 @sqlSafef(i8* %6, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%19 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %0, i8* %6, i8* %7, i32 256)
%20 = load i8, i8* %7
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %17
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%24 = call i32 @sqlSafef(i8* %6, i32 256, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%25 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %0, i8* %6, i8* %23, i32 32)
%26 = load i8, i8* %23
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @sqlSafef(i8* %6, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%30 = call i32 @sqlNeedQuickQuery(%struct.sqlConnection* %0, i8* %6, i8* %7, i32 256)
br label %33
31: ; preds = %22
%32 = call i32 @safef(i8* %7, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %23)
br label %33
33: ; preds = %31, %28
br label %34
34: ; preds = %12, %33, %17, %2
%35 = call i8* @cloneString(i8* %7)
ret i8* %35
}