#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(int /*<<< orphan*/);
int /*<<< orphan*/ sqlQuickQuery(struct sqlConnection *, char *, char *, int);
int /*<<< orphan*/ sqlSafef(char *, int, char *, char *, char *, char *, int,
                            char *, char *);
char *indirectString(struct sqlConnection *conn, int id, char *table,
                     char *valField) {
  char query[256], buf[512];
  sqlSafef(query, sizeof(query),
           "select %s.%s from image,%s "
           "where image.id=%d and image.%s = %s.id",
           table, valField, table, id, table, table);
  return cloneOrNull(sqlQuickQuery(conn, query, buf, sizeof(buf)));
}


x86 assembly (clang, -O0):
<indirectString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0xc(%rbp),%r11d
mov    -0x18(%rbp),%r10
mov    -0x18(%rbp),%rax
mov    $0x100,%esi
lea    0xe8b(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <sqlSafef@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
lea    -0x320(%rbp),%rdx
mov    $0x200,%ecx
call   1040 <sqlQuickQuery@plt>
mov    %eax,%edi
call   1050 <cloneOrNull@plt>
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indirectString>:
push   %r14
push   %rbx
sub    $0x308,%rsp
mov    %rcx,%r8
mov    %rdx,%rcx
mov    %esi,%eax
mov    %rdi,%rbx
sub    $0x8,%rsp
lea    0xeb0(%rip),%rdx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rcx,%r9
push   %rcx
push   %rcx
push   %rax
call   1030 <sqlSafef@plt>
add    $0x20,%rsp
lea    0x100(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x200,%ecx
call   1040 <sqlQuickQuery@plt>
mov    %eax,%edi
call   1050 <cloneOrNull@plt>
add    $0x308,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sqlConnection = type { i32 }
@.str = [66 x i8] c"select %s.%s from image,%s where image.id=%d and image.%s = %s.id\00"
define i8* @indirectString(%struct.sqlConnection* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca %struct.sqlConnection*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca [512 x i8]
store %struct.sqlConnection* %0, %struct.sqlConnection** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %7
%13 = load i8*, i8** %8
%14 = load i8*, i8** %7
%15 = load i32, i32* %6
%16 = load i8*, i8** %7
%17 = load i8*, i8** %7
%18 = call i32 @sqlSafef(i8* %11, i32 256, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13, i8* %14, i32 %15, i8* %16, i8* %17)
%19 = load %struct.sqlConnection*, %struct.sqlConnection** %5
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%22 = call i32 @sqlQuickQuery(%struct.sqlConnection* %19, i8* %20, i8* %21, i32 512)
%23 = call i8* @cloneOrNull(i32 %22)
ret i8* %23
}

LLVM IR (-O2):
%struct.sqlConnection = type { i32 }
@.str = [66 x i8] c"select %s.%s from image,%s where image.id=%d and image.%s = %s.id\00"
define i8* @indirectString(%struct.sqlConnection* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = alloca [512 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%9 = call i32 @sqlSafef(i8* %7, i32 256, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %3, i8* %2, i32 %1, i8* %2, i8* %2)
%10 = call i32 @sqlQuickQuery(%struct.sqlConnection* %0, i8* %7, i8* %8, i32 512)
%11 = call i8* @cloneOrNull(i32 %10)
ret i8* %11
}