#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 DBList {
  int dummy;
};

/* Variables and functions */
struct DBList *_dbGetList(char *);
char *dbToDBDate(char const *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *,
                           char *);
int strlen(char *);
struct DBList *dbGetListFromTo(const char *dateFrom, const char *dateTo) {
  char query[strlen("SELECT "
                    "id"
                    ", "
                    "date"
                    ", "
                    "purpose"
                    ", "
                    "expense"
                    " FROM "
                    "Expenses"
                    " WHERE "
                    "date"
                    " >= ") +
             8 +
             strlen(" AND "
                    "date"
                    " <= ") +
             8 +
             strlen(" ORDER BY "
                    "date")];
  char *dateFromFormatted, *dateToFormatted;
  dateFromFormatted = dbToDBDate(dateFrom);
  if (!dateFromFormatted)
    return 0;
  dateToFormatted = dbToDBDate(dateTo);
  if (!dateToFormatted)
    return 0;
  sprintf(query, "%s%s%s%s%s",
          "SELECT "
          "id"
          ", "
          "date"
          ", "
          "purpose"
          ", "
          "expense"
          " FROM "
          "Expenses"
          " WHERE "
          "date"
          " >= ",
          dateFromFormatted,
          " AND "
          "date"
          " <= ",
          dateToFormatted,
          " ORDER BY "
          "date");
  return _dbGetList(query);
}


x86 assembly (clang, -O0):
<dbGetListFromTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x50(%rbp)
lea    0xed9(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4c(%rbp)
lea    0xed1(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x4c(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x10(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <dbToDBDate@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11dd <dbGetListFromTo+0x9d>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1256 <dbGetListFromTo+0x116>
mov    -0x18(%rbp),%rdi
call   1030 <dbToDBDate@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1209 <dbGetListFromTo+0xc9>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1256 <dbGetListFromTo+0x116>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r9
lea    0xe40(%rip),%rsi
lea    0xddd(%rip),%rdx
lea    0xe15(%rip),%r8
lea    0xe1c(%rip),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1060 <sprintf@plt>
mov    -0x48(%rbp),%rdi
add    $0x10,%rsp
call   1050 <_dbGetList@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbGetListFromTo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xea5(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
lea    0xed5(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xed5(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r13d,%ebx
add    %ebx,%eax
add    $0x10,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
call   1030 <dbToDBDate@plt>
test   %rax,%rax
je     11ed <dbGetListFromTo+0xad>
mov    %rax,%r12
mov    %r15,%rdi
call   1030 <dbToDBDate@plt>
test   %rax,%rax
je     11ed <dbGetListFromTo+0xad>
sub    $0x8,%rsp
lea    0xe9b(%rip),%rsi
lea    0xe38(%rip),%rdx
lea    0xe70(%rip),%r8
mov    %rbx,%rdi
mov    %r12,%rcx
mov    %rax,%r9
push   %r14
call   1060 <sprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1050 <_dbGetList@plt>
jmp    11ef <dbGetListFromTo+0xaf>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.DBList = type { i32 }
@.str = [63 x i8] c"SELECT id, date, purpose, expense FROM Expenses WHERE date >= \00"
@.str.1 = [14 x i8] c" AND date <= \00"
@.str.2 = [15 x i8] c" ORDER BY date\00"
@.str.3 = [11 x i8] c"%s%s%s%s%s\00"
define %struct.DBList* @dbGetListFromTo(i8* %0, i8* %1) {
%3 = alloca %struct.DBList*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%12 = add nsw i32 %11, 8
%13 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%14 = add nsw i32 %12, %13
%15 = add nsw i32 %14, 8
%16 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%17 = add nsw i32 %15, %16
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %6
%20 = alloca i8, i64 %18
store i64 %18, i64* %7
%21 = load i8*, i8** %4
%22 = call i8* @dbToDBDate(i8* %21)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %2
store %struct.DBList* null, %struct.DBList** %3
store i32 1, i32* %10
br label %37
26: ; preds = %2
%27 = load i8*, i8** %5
%28 = call i8* @dbToDBDate(i8* %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = icmp ne i8* %29, null
br i1 %30, label %32, label %31
31: ; preds = %26
store %struct.DBList* null, %struct.DBList** %3
store i32 1, i32* %10
br label %37
32: ; preds = %26
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%36 = call %struct.DBList* @_dbGetList(i8* %20)
store %struct.DBList* %36, %struct.DBList** %3
store i32 1, i32* %10
br label %37
37: ; preds = %32, %31, %25
%38 = load i8*, i8** %6
%39 = load %struct.DBList*, %struct.DBList** %3
ret %struct.DBList* %39
}

LLVM IR (-O2):
%struct.DBList = type { i32 }
@.str = [63 x i8] c"SELECT id, date, purpose, expense FROM Expenses WHERE date >= \00"
@.str.1 = [14 x i8] c" AND date <= \00"
@.str.2 = [15 x i8] c" ORDER BY date\00"
@.str.3 = [11 x i8] c"%s%s%s%s%s\00"
define %struct.DBList* @dbGetListFromTo(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%6 = add i32 %3, 16
%7 = add i32 %6, %4
%8 = add i32 %7, %5
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = tail call i8* @dbToDBDate(i8* %0)
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = tail call i8* @dbToDBDate(i8* %1)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%18 = call %struct.DBList* @_dbGetList(i8* %10)
br label %19
19: ; preds = %13, %2, %16
%20 = phi %struct.DBList* [ %18, %16 ], [ null, %2 ], [ null, %13 ]
ret %struct.DBList* %20
}