#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 */
char *pipe2string(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
char *timlib_get_in_clause(char *);
char *hydrology_library_get_period_of_record_begin_date(char *application_name,
                                                        char *station,
                                                        char *datatype) {
  char sys_string[1024];
  char where_clause[1024];
  char *select;
  if (datatype && *datatype && strcmp(datatype, "datatype") != 0) {
    sprintf(where_clause, "station in (%s) and datatype in (%s)",
            timlib_get_in_clause(station), timlib_get_in_clause(datatype));
  } else {
    sprintf(where_clause, "station in (%s)", timlib_get_in_clause(station));
  }
  select = "min(measurement_date)";
  sprintf(sys_string,
          "get_folder_data	application=%s		"
          "			folder=measurement	"
          "			select=\"%s\"		"
          "			where=\"%s\"		"
          "			order=none		",
          application_name, select, where_clause);
  return pipe2string(sys_string);
}


x86 assembly (clang, -O0):
<hydrology_library_get_period_of_record_begin_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d7 <hydrology_library_get_period_of_record_begin_date+0x97>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <hydrology_library_get_period_of_record_begin_date+0x97>
mov    -0x18(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11d7 <hydrology_library_get_period_of_record_begin_date+0x97>
lea    -0x820(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <timlib_get_in_clause@plt>
mov    %rax,-0x830(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <timlib_get_in_clause@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rdx
mov    %rax,%rcx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1206 <hydrology_library_get_period_of_record_begin_date+0xc6>
lea    -0x820(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <timlib_get_in_clause@plt>
mov    -0x840(%rbp),%rdi
mov    %rax,%rdx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    0xe31(%rip),%rax
mov    %rax,-0x828(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x828(%rbp),%rcx
lea    -0x820(%rbp),%r8
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1050 <pipe2string@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hydrology_library_get_period_of_record_begin_date>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
test   %rdx,%rdx
je     119f <hydrology_library_get_period_of_record_begin_date+0x5f>
mov    %rdx,%rbx
cmpb   $0x0,(%rdx)
je     119f <hydrology_library_get_period_of_record_begin_date+0x5f>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     119f <hydrology_library_get_period_of_record_begin_date+0x5f>
mov    %r15,%rdi
call   1030 <timlib_get_in_clause@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <timlib_get_in_clause@plt>
lea    0xe7c(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    11bb <hydrology_library_get_period_of_record_begin_date+0x7b>
mov    %r15,%rdi
call   1030 <timlib_get_in_clause@plt>
lea    0xe80(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0xe92(%rip),%rsi
lea    0xe75(%rip),%rcx
lea    0x400(%rsp),%rbx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <pipe2string@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"datatype\00"
@.str.1 = [37 x i8] c"station in (%s) and datatype in (%s)\00"
@.str.2 = [16 x i8] c"station in (%s)\00"
@.str.3 = [22 x i8] c"min(measurement_date)\00"
@.str.4 = [101 x i8] c"get_folder_data\09application=%s\09\09\09\09\09folder=measurement\09\09\09\09select=\22%s\22\09\09\09\09\09where=\22%s\22\09\09\09\09\09order=none\09\09\00"
define i8* @hydrology_library_get_period_of_record_begin_date(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %28
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i8*, i8** %6
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = load i8*, i8** %5
%24 = call i8* @timlib_get_in_clause(i8* %23)
%25 = load i8*, i8** %6
%26 = call i8* @timlib_get_in_clause(i8* %25)
%27 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %26)
br label %33
28: ; preds = %17, %12, %3
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = load i8*, i8** %5
%31 = call i8* @timlib_get_in_clause(i8* %30)
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %21
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8** %9
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = load i8*, i8** %4
%36 = load i8*, i8** %9
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.4, i64 0, i64 0), i8* %35, i8* %36, i8* %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = call i8* @pipe2string(i8* %39)
ret i8* %40
}

LLVM IR (-O2):
@.str = [9 x i8] c"datatype\00"
@.str.1 = [37 x i8] c"station in (%s) and datatype in (%s)\00"
@.str.2 = [16 x i8] c"station in (%s)\00"
@.str.3 = [22 x i8] c"min(measurement_date)\00"
@.str.4 = [101 x i8] c"get_folder_data\09application=%s\09\09\09\09\09folder=measurement\09\09\09\09select=\22%s\22\09\09\09\09\09where=\22%s\22\09\09\09\09\09order=none\09\09\00"
define i8* @hydrology_library_get_period_of_record_begin_date(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %19, label %9
9: ; preds = %3
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = tail call i8* @timlib_get_in_clause(i8* %1)
%17 = tail call i8* @timlib_get_in_clause(i8* %2)
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
br label %22
19: ; preds = %12, %9, %3
%20 = tail call i8* @timlib_get_in_clause(i8* %1)
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %15
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([101 x i8], [101 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%24 = call i8* @pipe2string(i8* %6)
ret i8* %24
}