#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 */
double atof(int /*<<< orphan*/);
char *hydrology_library_get_latest_measurement_date_time(char **, char *,
                                                         char *, char *,
                                                         char *);
int /*<<< orphan*/ pipe2string(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
double hydrology_library_get_latest_before_measurement_value(
    char *application_name, char *station, char *datatype, char *begin_date) {
  char *latest_date;
  char *latest_time;
  char sys_string[1024];
  char where[512];
  latest_date = hydrology_library_get_latest_measurement_date_time(
      &latest_time, application_name, station, datatype, begin_date);
  if (!latest_date || !*latest_date)
    return 0.0;
  sprintf(where,
          "station = '%s' and "
          "datatype = '%s' and "
          "measurement_date = '%s' and "
          "measurement_time = '%s'",
          station, datatype, latest_date, latest_time);
  sprintf(sys_string,
          "get_folder_data	application=%s			"
          "			select=measurement_value	"
          "			folder=measurement		"
          "			where=\"%s\"			",
          application_name, where);
  return atof(pipe2string(sys_string));
}


x86 assembly (clang, -O0):
<hydrology_library_get_latest_before_measurement_value>:
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    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    -0x38(%rbp),%rdi
call   1040 <hydrology_library_get_latest_measurement_date_time@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1190 <hydrology_library_get_latest_before_measurement_value+0x50>
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119d <hydrology_library_get_latest_before_measurement_value+0x5d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11fa <hydrology_library_get_latest_before_measurement_value+0xba>
lea    -0x640(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%r9
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x640(%rbp),%rcx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x440(%rbp),%rdi
call   1050 <pipe2string@plt>
mov    %eax,%edi
call   1030 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hydrology_library_get_latest_before_measurement_value>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    %rcx,%r8
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <hydrology_library_get_latest_measurement_date_time@plt>
xorps  %xmm0,%xmm0
test   %rax,%rax
je     11cc <hydrology_library_get_latest_before_measurement_value+0x8c>
cmpb   $0x0,(%rax)
je     11cc <hydrology_library_get_latest_before_measurement_value+0x8c>
mov    0x8(%rsp),%r9
lea    0xe7a(%rip),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0xeb6(%rip),%rsi
lea    0x210(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <pipe2string@plt>
mov    %eax,%edi
call   1030 <atof@plt>
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [91 x i8] c"station = '%s' and datatype = '%s' and measurement_date = '%s' and measurement_time = '%s'\00"
@.str.1 = [101 x i8] c"get_folder_data\09application=%s\09\09\09\09\09\09select=measurement_value\09\09\09\09folder=measurement\09\09\09\09\09where=\22%s\22\09\09\09\00"
define double @hydrology_library_get_latest_before_measurement_value(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca [512 x i8]
%8 = bitcast i8** %5 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%11 = call i8* @hydrology_library_get_latest_measurement_date_time(i8** %5, i8* %0, i8* %1, i8* %2, i8* %3)
%12 = icmp eq i8* %11, null
br i1 %12, label %22, label %13
13: ; preds = %4
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i8* %11, i8* %17)
%19 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([101 x i8], [101 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %10)
%20 = call i32 @pipe2string(i8* %9)
%21 = call double @atof(i32 %20)
br label %22
22: ; preds = %4, %13, %16
%23 = phi double [ %21, %16 ], [ 0.000000e+00, %13 ], [ 0.000000e+00, %4 ]
ret double %23
}