#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 db_query {
  int dummy;
};
typedef int /*<<< orphan*/ sqlite3_stmt;

/* Variables and functions */
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int);
char *strdup(char const *);
char *db_column_copy_text(struct db_query *query, int i) {
  const char *str;
  if (query == NULL)
    return NULL;
  str = (const char *)sqlite3_column_text((sqlite3_stmt *)query, i);
  if (str != NULL)
    return strdup(str);
  return NULL;
}


x86 assembly (clang, -O0):
<db_column_copy_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <db_column_copy_text+0x27>
movq   $0x0,-0x8(%rbp)
jmp    117c <db_column_copy_text+0x5c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <sqlite3_column_text@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1174 <db_column_copy_text+0x54>
mov    -0x20(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    117c <db_column_copy_text+0x5c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_column_copy_text>:
test   %rdi,%rdi
je     113d <db_column_copy_text+0x1d>
push   %rax
call   1030 <sqlite3_column_text@plt>
test   %rax,%rax
lea    0x8(%rsp),%rsp
je     113d <db_column_copy_text+0x1d>
mov    %rax,%rdi
jmp    1040 <strdup@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.db_query = type { i32 }
define i8* @db_column_copy_text(%struct.db_query* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca %struct.db_query*
%5 = alloca i32
%6 = alloca i8*
store %struct.db_query* %0, %struct.db_query** %4
store i32 %1, i32* %5
%7 = load %struct.db_query*, %struct.db_query** %4
%8 = icmp eq %struct.db_query* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %22
10: ; preds = %2
%11 = load %struct.db_query*, %struct.db_query** %4
%12 = bitcast %struct.db_query* %11 to i32*
%13 = load i32, i32* %5
%14 = call i64 @sqlite3_column_text(i32* %12, i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i8*, i8** %6
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %3
br label %22
21: ; preds = %10
store i8* null, i8** %3
br label %22
22: ; preds = %21, %18, %9
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
%struct.db_query = type { i32 }
define noalias i8* @db_column_copy_text(%struct.db_query* %0, i32 %1) {
%3 = icmp eq %struct.db_query* %0, null
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = getelementptr %struct.db_query, %struct.db_query* %0, i64 0, i32 0
%6 = tail call i64 @sqlite3_column_text(i32* %5, i32 %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = inttoptr i64 %6 to i8*
%10 = tail call i8* @strdup(i8* %9)
br label %11
11: ; preds = %4, %2, %8
%12 = phi i8* [ %10, %8 ], [ null, %2 ], [ null, %4 ]
ret i8* %12
}