#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*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
char *get_where_clause(char *begin_date, char *end_date, char *station,
                       char *datatype) {
  static char where_clause[1024];
  char date_where_clause[128];
  if (strcmp(end_date, "end_date") != 0) {
    sprintf(date_where_clause, "measurement_date between '%s' and '%s'",
            begin_date, end_date);
  } else {
    sprintf(date_where_clause, "measurement_date = '%s'", begin_date);
  }
  sprintf(where_clause, "station = '%s' and datatype = '%s' and %s", station,
          datatype, date_where_clause);
  return where_clause;
}


x86 assembly (clang, -O0):
<get_where_clause>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1177 <get_where_clause+0x57>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe9e(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1190 <get_where_clause+0x70>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0xa0(%rbp),%r8
lea    0x2e9a(%rip),%rdi
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2e85(%rip),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_where_clause>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1167 <get_where_clause+0x47>
lea    0xeb4(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    117b <get_where_clause+0x5b>
lea    0xec2(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0x2ebe(%rip),%rbx
lea    0xebf(%rip),%rsi
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@get_where_clause.where_clause = internal global [1024 x i8] zeroinitializer
@.str = [9 x i8] c"end_date\00"
@.str.1 = [39 x i8] c"measurement_date between '%s' and '%s'\00"
@.str.2 = [24 x i8] c"measurement_date = '%s'\00"
@.str.3 = [42 x i8] c"station = '%s' and datatype = '%s' and %s\00"
define i8* @get_where_clause(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [128 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %6
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16)
br label %22
18: ; preds = %4
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %13
%23 = load i8*, i8** %7
%24 = load i8*, i8** %8
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%26 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_where_clause.where_clause, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8* %24, i8* %25)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_where_clause.where_clause, i64 0, i64 0)
}

LLVM IR (-O2):
@get_where_clause.where_clause = internal global [1024 x i8] zeroinitializer
@.str = [9 x i8] c"end_date\00"
@.str.1 = [39 x i8] c"measurement_date between '%s' and '%s'\00"
@.str.2 = [24 x i8] c"measurement_date = '%s'\00"
@.str.3 = [42 x i8] c"station = '%s' and datatype = '%s' and %s\00"
define i8* @get_where_clause(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %13
11: ; preds = %4
%12 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %9
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_where_clause.where_clause, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %3, i8* %6)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_where_clause.where_clause, i64 0, i64 0)
}