#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 *);
int strlen(char *);
struct DBList *dbGetListSince(const char *date) {
  char query[strlen("SELECT "
                    "id"
                    ", "
                    "date"
                    ", "
                    "purpose"
                    ", "
                    "expense"
                    " FROM "
                    "Expenses"
                    " WHERE "
                    "date"
                    " >= ") +
             8 +
             strlen(" ORDER BY "
                    "date")];
  char *dateString;
  dateString = dbToDBDate(date);
  if (!dateString)
    return 0;
  sprintf(query, "%s%s%s",
          "SELECT "
          "id"
          ", "
          "date"
          ", "
          "purpose"
          ", "
          "expense"
          " FROM "
          "Expenses"
          " WHERE "
          "date"
          " >= ",
          dateString,
          " ORDER BY "
          "date");
  return _dbGetList(query);
}


x86 assembly (clang, -O0):
<dbGetListSince>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
lea    0xedd(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x8(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <dbToDBDate@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c3 <dbGetListSince+0x83>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11f9 <dbGetListSince+0xb9>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rcx
lea    0xe7c(%rip),%rsi
lea    0xe27(%rip),%rdx
lea    0xe5f(%rip),%r8
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <_dbGetList@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbGetListSince>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xeaf(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xee0(%rip),%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0x8,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rdi
call   1030 <dbToDBDate@plt>
test   %rax,%rax
je     11b1 <dbGetListSince+0x71>
lea    0xec0(%rip),%rsi
lea    0xe6b(%rip),%rdx
lea    0xea3(%rip),%r8
mov    %rbx,%rdi
mov    %rax,%rcx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <_dbGetList@plt>
jmp    11b3 <dbGetListSince+0x73>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
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 = [15 x i8] c" ORDER BY date\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
define %struct.DBList* @dbGetListSince(i8* %0) {
%2 = alloca %struct.DBList*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%9 = add nsw i32 %8, 8
%10 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%11 = add nsw i32 %9, %10
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = load i8*, i8** %3
%16 = call i8* @dbToDBDate(i8* %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %1
store %struct.DBList* null, %struct.DBList** %2
store i32 1, i32* %7
br label %24
20: ; preds = %1
%21 = load i8*, i8** %6
%22 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%23 = call %struct.DBList* @_dbGetList(i8* %14)
store %struct.DBList* %23, %struct.DBList** %2
store i32 1, i32* %7
br label %24
24: ; preds = %20, %19
%25 = load i8*, i8** %4
%26 = load %struct.DBList*, %struct.DBList** %2
ret %struct.DBList* %26
}

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