#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 */

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  int i = 3;
  char *q = NULL;
  {
    char *tmp_string_for_extend = (q);
    asprintf(&(q), "select * from tab");
    free(tmp_string_for_extend);
  };
  {
    char *tmp_string_for_extend = (q);
    asprintf(&(q), "%s where col%i is not null", q, i);
    free(tmp_string_for_extend);
  };
  printf("%s\n", q);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
lea    0xebd(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <asprintf@plt>
xor    %edi,%edi
call   1030 <free@plt>
mov    (%rsp),%rbx
lea    0xeb0(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    $0x3,%ecx
xor    %eax,%eax
call   1050 <asprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rsp),%rsi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"select * from tab\00"
@.str.1 = [27 x i8] c"%s where col%i is not null\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 3, i32* %1
store i8* null, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
%6 = call i32 (i8**, i8*, ...) @asprintf(i8** %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = call i32 @free(i8* %7)
%9 = load i8*, i8** %2
store i8* %9, i8** %4
%10 = load i8*, i8** %2
%11 = load i32, i32* %1
%12 = call i32 (i8**, i8*, ...) @asprintf(i8** %2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %11)
%13 = load i8*, i8** %4
%14 = call i32 @free(i8* %13)
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %15)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"select * from tab\00"
@.str.1 = [27 x i8] c"%s where col%i is not null\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = call i32 (i8**, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @free(i8* null)
%5 = load i8*, i8** %1
%6 = call i32 (i8**, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 3)
%7 = call i32 @free(i8* %5)
%8 = load i8*, i8** %1
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
ret i32 0
}