#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 *get_table_name(char *, char *);
char *pipe2string(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
char *hydrology_library_get_latest_measurement_date_time(
    char **latest_measurement_time, char *application_name, char *station,
    char *datatype, char *begin_date) {
  char *table_name;
  char *latest_date;
  char sys_string[1024];
  char where[512];
  table_name = get_table_name(application_name, "measurement");
  sprintf(where,
          "station = '%s' and "
          "datatype = '%s' and "
          "measurement_date < '%s'",
          station, datatype, begin_date);
  sprintf(sys_string,
          "echo \"select max( measurement_date )			 "
          "	 from %s					 "
          "	 where %s;\"					|"
          "sql							 ",
          table_name, where);
  latest_date = pipe2string(sys_string);
  if (!*latest_date)
    return (char *)0;
  sprintf(where,
          "station = '%s' and "
          "datatype = '%s' and "
          "measurement_date = '%s'",
          station, datatype, latest_date);
  sprintf(sys_string,
          "echo \"select max( measurement_time )			 "
          "	 from %s					 "
          "	 where %s;\"					|"
          "sql							 ",
          table_name, where);
  *latest_measurement_time = pipe2string(sys_string);
  return latest_date;
}


x86 assembly (clang, -O0):
<hydrology_library_get_latest_measurement_date_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1030 <get_table_name@plt>
mov    %rax,-0x38(%rbp)
lea    -0x640(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    -0x640(%rbp),%rcx
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x440(%rbp),%rdi
call   1040 <pipe2string@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11ce <hydrology_library_get_latest_measurement_date_time+0x9e>
movq   $0x0,-0x8(%rbp)
jmp    122d <hydrology_library_get_latest_measurement_date_time+0xfd>
lea    -0x640(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    -0x640(%rbp),%rcx
lea    0xed7(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x440(%rbp),%rdi
call   1040 <pipe2string@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hydrology_library_get_latest_measurement_date_time>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    %r8,%rbx
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rax
mov    %rdi,0x8(%rsp)
lea    0xea7(%rip),%rsi
mov    %rax,%rdi
call   1030 <get_table_name@plt>
mov    %rax,%r15
lea    0xea1(%rip),%rsi
xor    %ebp,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xebf(%rip),%rsi
lea    0x210(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <pipe2string@plt>
cmpb   $0x0,(%rax)
je     1205 <hydrology_library_get_latest_measurement_date_time+0xd5>
mov    %rax,%rbx
lea    0xee5(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xf05(%rip),%rsi
lea    0x210(%rsp),%rbp
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <pipe2string@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
mov    %rbx,%rbp
mov    %rbp,%rax
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"measurement\00"
@.str.1 = [63 x i8] c"station = '%s' and datatype = '%s' and measurement_date < '%s'\00"
@.str.2 = [85 x i8] c"echo \22select max( measurement_date )\09\09\09 \09 from %s\09\09\09\09\09 \09 where %s;\22\09\09\09\09\09|sql\09\09\09\09\09\09\09 \00"
@.str.3 = [63 x i8] c"station = '%s' and datatype = '%s' and measurement_date = '%s'\00"
@.str.4 = [85 x i8] c"echo \22select max( measurement_time )\09\09\09 \09 from %s\09\09\09\09\09 \09 where %s;\22\09\09\09\09\09|sql\09\09\09\09\09\09\09 \00"
define i8* @hydrology_library_get_latest_measurement_date_time(i8** %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [1024 x i8]
%15 = alloca [512 x i8]
store i8** %0, i8*** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = load i8*, i8** %8
%17 = call i8* @get_table_name(i8* %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %12
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%19 = load i8*, i8** %9
%20 = load i8*, i8** %10
%21 = load i8*, i8** %11
%22 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20, i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%24 = load i8*, i8** %12
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%26 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%28 = call i8* @pipe2string(i8* %27)
store i8* %28, i8** %13
%29 = load i8*, i8** %13
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %5
store i8* null, i8** %6
br label %47
33: ; preds = %5
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%35 = load i8*, i8** %9
%36 = load i8*, i8** %10
%37 = load i8*, i8** %13
%38 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %36, i8* %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%40 = load i8*, i8** %12
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%42 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* %40, i8* %41)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%44 = call i8* @pipe2string(i8* %43)
%45 = load i8**, i8*** %7
store i8* %44, i8** %45
%46 = load i8*, i8** %13
store i8* %46, i8** %6
br label %47
47: ; preds = %33, %32
%48 = load i8*, i8** %6
ret i8* %48
}

LLVM IR (-O2):
@.str = [12 x i8] c"measurement\00"
@.str.1 = [63 x i8] c"station = '%s' and datatype = '%s' and measurement_date < '%s'\00"
@.str.2 = [85 x i8] c"echo \22select max( measurement_date )\09\09\09 \09 from %s\09\09\09\09\09 \09 where %s;\22\09\09\09\09\09|sql\09\09\09\09\09\09\09 \00"
@.str.3 = [63 x i8] c"station = '%s' and datatype = '%s' and measurement_date = '%s'\00"
@.str.4 = [85 x i8] c"echo \22select max( measurement_time )\09\09\09 \09 from %s\09\09\09\09\09 \09 where %s;\22\09\09\09\09\09|sql\09\09\09\09\09\09\09 \00"
define i8* @hydrology_library_get_latest_measurement_date_time(i8** nocapture writeonly %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca [1024 x i8]
%7 = alloca [512 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%10 = tail call i8* @get_table_name(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3, i8* %4)
%12 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* %9)
%13 = call i8* @pipe2string(i8* %8)
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %5
%17 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %3, i8* %13)
%18 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %9)
%19 = call i8* @pipe2string(i8* %8)
store i8* %19, i8** %0
br label %20
20: ; preds = %5, %16
%21 = phi i8* [ %13, %16 ], [ null, %5 ]
ret i8* %21
}