#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_dot_to_path();
int /*<<< orphan*/ add_relative_source_directory_to_path(char *);
int /*<<< orphan*/ add_src_appaserver_to_path();
int /*<<< orphan*/ add_utility_to_path();
int /*<<< orphan*/ appaserver_error_starting_argv_append_file(int, char **,
                                                              char *);
double atof(char *);
int /*<<< orphan*/ environ_set_environment(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ output_chart_data(double, double, char *);
int /*<<< orphan*/ output_transmit_data(double, double, char *, char *, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ piece(char *, char, char *, int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ timlib_parse_database_string(char **, char *);
int main(int argc, char **argv) {
  char *application_name;
  char *begin_date_string, *end_date_string;
  char *station;
  char *datatype;
  char *output_medium;
  char *database_string;
  char where_clause[1024];
  char aggregate_process[1024];
  char sys_string[1024];
  double elevation;
  char input_buffer[64];
  char measurement_date[16];
  char previous_measurement_date[16];
  char stage_string[32];
  double stage = 0.0;
  FILE *input_pipe;
  int did_any = 0;
  if (argc != 8) {
    fprintf(stderr,
            "Usage: %s application station datatype begin_date end_date "
            "elevation output_medium\n",
            argv[0]);
    exit(1);
  }
  application_name = argv[1];
  station = argv[2];
  datatype = argv[3];
  begin_date_string = argv[4];
  end_date_string = argv[5];
  elevation = atof(argv[6]);
  output_medium = argv[7];
  if (timlib_parse_database_string(&database_string, application_name)) {
    environ_set_environment("APPASERVER_DATABASE", database_string);
  }
  appaserver_error_starting_argv_append_file(argc, argv, application_name);
  add_dot_to_path();
  add_utility_to_path();
  add_src_appaserver_to_path();
  add_relative_source_directory_to_path(application_name);
  sprintf(where_clause,
          "station = '%s' and 				      "
          "datatype = '%s' and 				      "
          "measurement_date >= '%s' and measurement_date <= '%s'",
          station, datatype, begin_date_string, end_date_string);
  sprintf(aggregate_process,
          "real_time2aggregate_value.e average %d %d %d '%c' daily n %s", 0, -1,
          1, '^', end_date_string);
  sprintf(sys_string,
          "get_folder_data	application=%s		    "
          "			folder=measurement	    "
          "			select=\"%s\"		    "
          "			where=\"%s\"		   |"
          "%s						   |"
          "cat						    ",
          application_name, "measurement_date,measurement_value", where_clause,
          aggregate_process);
  input_pipe = popen(sys_string, "r");
  ;
  *previous_measurement_date = '\0';
  while (get_line(input_buffer, input_pipe)) {
    piece(measurement_date, '^', input_buffer, 0);
    piece(stage_string, '^', input_buffer, 1);
    stage = atof(stage_string);
    if (strcmp(output_medium, "chart") == 0) {
      output_chart_data(stage, elevation, measurement_date);
    } else if (strcmp(output_medium, "transmit") == 0 ||
               strcmp(output_medium, "text_file") == 0 ||
               strcmp(output_medium, "spreadsheet") == 0 ||
               strcmp(output_medium, "table") == 0 ||
               strcmp(output_medium, "stdout") == 0) {
      if (!*previous_measurement_date) {
        strcpy(previous_measurement_date, measurement_date);
      }
      output_transmit_data(stage, elevation, measurement_date,
                           previous_measurement_date, 0);
      strcpy(previous_measurement_date, measurement_date);
    }
    did_any = 1;
  }
  pclose(input_pipe);
  if ((strcmp(output_medium, "transmit") == 0 ||
       strcmp(output_medium, "text_file") == 0 ||
       strcmp(output_medium, "spreadsheet") == 0 ||
       strcmp(output_medium, "table") == 0 ||
       strcmp(output_medium, "stdout") == 0) &&
      did_any) {
    output_transmit_data(stage, elevation, measurement_date,
                         previous_measurement_date, 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd00,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xce8(%rbp)
ff
movl   $0x0,-0xcf4(%rbp)
cmpl   $0x8,-0x8(%rbp)
je     128e <main+0x5e>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd81(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0xc58(%rbp)
ff
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x48(%rbp),%rdi
call   10d0 <timlib_parse_database_string@plt>
cmp    $0x0,%rax
je     1312 <main+0xe2>
mov    -0x48(%rbp),%rsi
lea    0xd47(%rip),%rdi
call   1030 <environ_set_environment@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1120 <appaserver_error_starting_argv_append_file@plt>
mov    $0x0,%al
call   10c0 <add_dot_to_path@plt>
mov    $0x0,%al
call   1150 <add_utility_to_path@plt>
mov    $0x0,%al
call   1140 <add_src_appaserver_to_path@plt>
mov    -0x18(%rbp),%rdi
call   1070 <add_relative_source_directory_to_path@plt>
lea    -0x450(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xd0a(%rip),%rsi
mov    $0x0,%al
call   1100 <sprintf@plt>
lea    -0x850(%rbp),%rdi
mov    -0x28(%rbp),%rax
lea    0xd62(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
mov    $0xffffffff,%ecx
mov    $0x1,%r8d
mov    $0x5e,%r9d
mov    %rax,(%rsp)
mov    $0x0,%al
call   1100 <sprintf@plt>
lea    -0xc50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x450(%rbp),%r8
lea    -0x850(%rbp),%r9
lea    0xd5f(%rip),%rsi
lea    0xdd7(%rip),%rcx
mov    $0x0,%al
call   1100 <sprintf@plt>
lea    -0xc50(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   10e0 <popen@plt>
mov    %rax,-0xcf0(%rbp)
movb   $0x0,-0xcc0(%rbp)
lea    -0xca0(%rbp),%rdi
mov    -0xcf0(%rbp),%rsi
call   1060 <get_line@plt>
cmp    $0x0,%rax
je     1577 <main+0x347>
lea    -0xcb0(%rbp),%rdi
lea    -0xca0(%rbp),%rdx
mov    $0x5e,%esi
xor    %ecx,%ecx
call   1130 <piece@plt>
lea    -0xce0(%rbp),%rdi
lea    -0xca0(%rbp),%rdx
mov    $0x5e,%esi
mov    $0x1,%ecx
call   1130 <piece@plt>
lea    -0xce0(%rbp),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0xce8(%rbp)
ff
mov    -0x40(%rbp),%rdi
lea    0xd61(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1489 <main+0x259>
movsd  -0xce8(%rbp),%xmm0
ff
movsd  -0xc58(%rbp),%xmm1
ff
lea    -0xcb0(%rbp),%rdi
call   10f0 <output_chart_data@plt>
jmp    1568 <main+0x338>
mov    -0x40(%rbp),%rdi
lea    0xd2c(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     150b <main+0x2db>
mov    -0x40(%rbp),%rdi
lea    0xd1b(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     150b <main+0x2db>
mov    -0x40(%rbp),%rdi
lea    0xd0b(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     150b <main+0x2db>
mov    -0x40(%rbp),%rdi
lea    0xcfd(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     150b <main+0x2db>
mov    -0x40(%rbp),%rdi
lea    0xce9(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1563 <main+0x333>
cmpb   $0x0,-0xcc0(%rbp)
jne    152b <main+0x2fb>
lea    -0xcc0(%rbp),%rdi
lea    -0xcb0(%rbp),%rsi
call   1040 <strcpy@plt>
movsd  -0xce8(%rbp),%xmm0
ff
movsd  -0xc58(%rbp),%xmm1
ff
lea    -0xcb0(%rbp),%rdi
lea    -0xcc0(%rbp),%rsi
xor    %edx,%edx
call   1080 <output_transmit_data@plt>
lea    -0xcc0(%rbp),%rdi
lea    -0xcb0(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1568 <main+0x338>
movl   $0x1,-0xcf4(%rbp)
jmp    13e6 <main+0x1b6>
mov    -0xcf0(%rbp),%rdi
call   1090 <pclose@plt>
mov    -0x40(%rbp),%rdi
lea    0xc32(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1605 <main+0x3d5>
mov    -0x40(%rbp),%rdi
lea    0xc21(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1605 <main+0x3d5>
mov    -0x40(%rbp),%rdi
lea    0xc11(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1605 <main+0x3d5>
mov    -0x40(%rbp),%rdi
lea    0xc03(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1605 <main+0x3d5>
mov    -0x40(%rbp),%rdi
lea    0xbef(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    163a <main+0x40a>
cmpl   $0x0,-0xcf4(%rbp)
je     163a <main+0x40a>
movsd  -0xce8(%rbp),%xmm0
ff
movsd  -0xc58(%rbp),%xmm1
ff
lea    -0xcb0(%rbp),%rdi
lea    -0xcc0(%rbp),%rsi
mov    $0x1,%edx
call   1080 <output_transmit_data@plt>
xor    %eax,%eax
add    $0xd00,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xcb8,%rsp
mov    %rsi,%r14
cmp    $0x8,%edi
jne    159b <main+0x36b>
mov    0x8(%r14),%rbx
mov    0x10(%r14),%rax
mov    %rax,0x8(%rsp)
mov    0x18(%r14),%r15
mov    0x20(%r14),%r13
mov    0x28(%r14),%rbp
mov    0x30(%r14),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x38(%r14),%r12
lea    0x38(%rsp),%rdi
mov    %rbx,%rsi
call   10d0 <timlib_parse_database_string@plt>
test   %rax,%rax
je     129c <main+0x6c>
mov    0x38(%rsp),%rsi
lea    0xdbd(%rip),%rdi
call   1030 <environ_set_environment@plt>
mov    $0x8,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1120 <appaserver_error_starting_argv_append_file@plt>
xor    %eax,%eax
call   10c0 <add_dot_to_path@plt>
xor    %eax,%eax
call   1150 <add_utility_to_path@plt>
xor    %eax,%eax
call   1140 <add_src_appaserver_to_path@plt>
mov    %rbx,%rdi
call   1070 <add_relative_source_directory_to_path@plt>
lea    0xd98(%rip),%rsi
lea    0x8b0(%rsp),%r14
mov    %r14,%rdi
mov    0x8(%rsp),%rdx
mov    %r15,%rcx
mov    %r13,%r8
mov    %rbp,%r9
xor    %eax,%eax
call   1100 <sprintf@plt>
mov    %rbp,(%rsp)
lea    0xdde(%rip),%rsi
lea    0x4b0(%rsp),%r15
mov    %r15,%rdi
xor    %edx,%edx
mov    $0xffffffff,%ecx
mov    $0x1,%r8d
mov    $0x5e,%r9d
xor    %eax,%eax
call   1100 <sprintf@plt>
lea    0xdef(%rip),%rsi
lea    0xe67(%rip),%rcx
lea    0xb0(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %r14,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1100 <sprintf@plt>
lea    0xe68(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <popen@plt>
mov    %rax,%r15
movb   $0x0,0x20(%rsp)
lea    0x70(%rsp),%rdi
mov    %rax,%rsi
call   1060 <get_line@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     14e0 <main+0x2b0>
lea    0x40(%rsp),%r13
lea    0x70(%rsp),%rbx
lea    0x50(%rsp),%rbp
lea    0x20(%rsp),%r14
jmp    13e3 <main+0x1b3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x20(%rsp)
je     14d0 <main+0x2a0>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %r13,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1080 <output_transmit_data@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <get_line@plt>
test   %rax,%rax
je     14e9 <main+0x2b9>
mov    %r13,%rdi
mov    $0x5e,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1130 <piece@plt>
mov    %rbp,%rdi
mov    $0x5e,%esi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1130 <piece@plt>
mov    %rbp,%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r12,%rdi
lea    0xd98(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     14b0 <main+0x280>
mov    %r12,%rdi
lea    0xd86(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    %r12,%rdi
lea    0xd77(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    %r12,%rdi
lea    0xd69(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    %r12,%rdi
lea    0xd5d(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    %r12,%rdi
lea    0xd4b(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    13cf <main+0x19f>
jmp    13a0 <main+0x170>
nopl   (%rax)
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %r13,%rdi
call   10f0 <output_chart_data@plt>
jmp    13cf <main+0x19f>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
jmp    13ab <main+0x17b>
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1090 <pclose@plt>
lea    0xcc8(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     155f <main+0x32f>
lea    0xcbd(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     155f <main+0x32f>
lea    0xcb3(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     155f <main+0x32f>
lea    0xcab(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     155f <main+0x32f>
lea    0xc9d(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcmp@plt>
cmpq   $0x0,0x18(%rsp)
je     1587 <main+0x357>
test   %rax,%rax
je     1567 <main+0x337>
jmp    1587 <main+0x357>
cmpq   $0x0,0x18(%rsp)
je     1587 <main+0x357>
lea    0x40(%rsp),%rdi
lea    0x20(%rsp),%rsi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    $0x1,%edx
call   1080 <output_transmit_data@plt>
xor    %eax,%eax
add    $0xcb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a3e(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xa52(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [84 x i8] c"Usage: %s application station datatype begin_date end_date elevation output_medium\0A\00"
@.str.1 = [20 x i8] c"APPASERVER_DATABASE\00"
@.str.2 = [113 x i8] c"station = '%s' and \09\09\09\09 datatype = '%s' and \09\09\09\09 measurement_date >= '%s' and measurement_date <= '%s'\00"
@.str.3 = [61 x i8] c"real_time2aggregate_value.e average %d %d %d '%c' daily n %s\00"
@.str.4 = [127 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 |%s\09\09\09\09\09\09 |cat\09\09\09\09\09\09 \00"
@.str.5 = [35 x i8] c"measurement_date,measurement_value\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [6 x i8] c"chart\00"
@.str.8 = [9 x i8] c"transmit\00"
@.str.9 = [10 x i8] c"text_file\00"
@.str.10 = [12 x i8] c"spreadsheet\00"
@.str.11 = [6 x i8] c"table\00"
@.str.12 = [7 x i8] c"stdout\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [1024 x i8]
%14 = alloca [1024 x i8]
%15 = alloca [1024 x i8]
%16 = alloca double
%17 = alloca [64 x i8]
%18 = alloca [16 x i8]
%19 = alloca [16 x i8]
%20 = alloca [32 x i8]
%21 = alloca double
%22 = alloca i32*
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %21
store i32 0, i32* %23
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 8
br i1 %25, label %26, label %33
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
store i8* %36, i8** %6
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
store i8* %39, i8** %9
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
store i8* %42, i8** %10
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 4
%45 = load i8*, i8** %44
store i8* %45, i8** %7
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 5
%48 = load i8*, i8** %47
store i8* %48, i8** %8
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 6
%51 = load i8*, i8** %50
%52 = call double @atof(i8* %51)
store double %52, double* %16
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 7
%55 = load i8*, i8** %54
store i8* %55, i8** %11
%56 = load i8*, i8** %6
%57 = call i64 @timlib_parse_database_string(i8** %12, i8* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %33
%60 = load i8*, i8** %12
%61 = call i32 @environ_set_environment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %59, %33
%63 = load i32, i32* %4
%64 = load i8**, i8*** %5
%65 = load i8*, i8** %6
%66 = call i32 @appaserver_error_starting_argv_append_file(i32 %63, i8** %64, i8* %65)
%67 = call i32 (...) @add_dot_to_path()
%68 = call i32 (...) @add_utility_to_path()
%69 = call i32 (...) @add_src_appaserver_to_path()
%70 = load i8*, i8** %6
%71 = call i32 @add_relative_source_directory_to_path(i8* %70)
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%73 = load i8*, i8** %9
%74 = load i8*, i8** %10
%75 = load i8*, i8** %7
%76 = load i8*, i8** %8
%77 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %72, i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.2, i64 0, i64 0), i8* %73, i8* %74, i8* %75, i8* %76)
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%79 = load i8*, i8** %8
%80 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %78, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i8* null, i32 -1, i32 1, i32 94, i8* %79)
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%82 = load i8*, i8** %6
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%85 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str.4, i64 0, i64 0), i8* %82, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %83, i8* %84)
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%87 = call i32* @popen(i8* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %87, i32** %22
%88 = getelementptr inbounds [16 x i8], [16 x i8]* %19, i64 0, i64 0
store i8 0, i8* %88
br label %89
89: ; preds = %149, %62
%90 = getelementptr inbounds [64 x i8], [64 x i8]* %17, i64 0, i64 0
%91 = load i32*, i32** %22
%92 = call i64 @get_line(i8* %90, i32* %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %150
94: ; preds = %89
%95 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%96 = getelementptr inbounds [64 x i8], [64 x i8]* %17, i64 0, i64 0
%97 = call i32 @piece(i8* %95, i8 signext 94, i8* %96, i32 0)
%98 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%99 = getelementptr inbounds [64 x i8], [64 x i8]* %17, i64 0, i64 0
%100 = call i32 @piece(i8* %98, i8 signext 94, i8* %99, i32 1)
%101 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%102 = call double @atof(i8* %101)
store double %102, double* %21
%103 = load i8*, i8** %11
%104 = call i64 @strcmp(i8* %103, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %111
106: ; preds = %94
%107 = load double, double* %21
%108 = load double, double* %16
%109 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%110 = call i32 @output_chart_data(double %107, double %108, i8* %109)
br label %149
111: ; preds = %94
%112 = load i8*, i8** %11
%113 = call i64 @strcmp(i8* %112, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%114 = icmp eq i64 %113, 0
br i1 %114, label %131, label %115
115: ; preds = %111
%116 = load i8*, i8** %11
%117 = call i64 @strcmp(i8* %116, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%118 = icmp eq i64 %117, 0
br i1 %118, label %131, label %119
119: ; preds = %115
%120 = load i8*, i8** %11
%121 = call i64 @strcmp(i8* %120, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%122 = icmp eq i64 %121, 0
br i1 %122, label %131, label %123
123: ; preds = %119
%124 = load i8*, i8** %11
%125 = call i64 @strcmp(i8* %124, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
%126 = icmp eq i64 %125, 0
br i1 %126, label %131, label %127
127: ; preds = %123
%128 = load i8*, i8** %11
%129 = call i64 @strcmp(i8* %128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%130 = icmp eq i64 %129, 0
br i1 %130, label %131, label %148
131: ; preds = %127, %123, %119, %115, %111
%132 = getelementptr inbounds [16 x i8], [16 x i8]* %19, i64 0, i64 0
%133 = load i8, i8* %132
%134 = icmp ne i8 %133, 0
br i1 %134, label %139, label %135
135: ; preds = %131
%136 = getelementptr inbounds [16 x i8], [16 x i8]* %19, i64 0, i64 0
%137 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%138 = call i32 @strcpy(i8* %136, i8* %137)
br label %139
139: ; preds = %135, %131
%140 = load double, double* %21
%141 = load double, double* %16
%142 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%143 = getelementptr inbounds [16 x i8], [16 x i8]* %19, i64 0, i64 0
%144 = call i32 @output_transmit_data(double %140, double %141, i8* %142, i8* %143, i32 0)
%145 = getelementptr inbounds [16 x i8], [16 x i8]* %19, i64 0, i64 0
%146 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%147 = call i32 @strcpy(i8* %145, i8* %146)
br label %148
148: ; preds = %139, %127
br label %149
149: ; preds = %148, %106
store i32 1, i32* %23
br label %89
150: ; preds = %89
%151 = load i32*, i32** %22
%152 = call i32 @pclose(i32* %151)
%153 = load i8*, i8** %11
%154 = call i64 @strcmp(i8* %153, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%155 = icmp eq i64 %154, 0
br i1 %155, label %172, label %156
156: ; preds = %150
%157 = load i8*, i8** %11
%158 = call i64 @strcmp(i8* %157, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%159 = icmp eq i64 %158, 0
br i1 %159, label %172, label %160
160: ; preds = %156
%161 = load i8*, i8** %11
%162 = call i64 @strcmp(i8* %161, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%163 = icmp eq i64 %162, 0
br i1 %163, label %172, label %164
164: ; preds = %160
%165 = load i8*, i8** %11
%166 = call i64 @strcmp(i8* %165, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
%167 = icmp eq i64 %166, 0
br i1 %167, label %172, label %168
168: ; preds = %164
%169 = load i8*, i8** %11
%170 = call i64 @strcmp(i8* %169, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%171 = icmp eq i64 %170, 0
br i1 %171, label %172, label %181
172: ; preds = %168, %164, %160, %156, %150
%173 = load i32, i32* %23
%174 = icmp ne i32 %173, 0
br i1 %174, label %175, label %181
175: ; preds = %172
%176 = load double, double* %21
%177 = load double, double* %16
%178 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%179 = getelementptr inbounds [16 x i8], [16 x i8]* %19, i64 0, i64 0
%180 = call i32 @output_transmit_data(double %176, double %177, i8* %178, i8* %179, i32 1)
br label %181
181: ; preds = %175, %172, %168
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [84 x i8] c"Usage: %s application station datatype begin_date end_date elevation output_medium\0A\00"
@.str.1 = [20 x i8] c"APPASERVER_DATABASE\00"
@.str.2 = [113 x i8] c"station = '%s' and \09\09\09\09 datatype = '%s' and \09\09\09\09 measurement_date >= '%s' and measurement_date <= '%s'\00"
@.str.3 = [61 x i8] c"real_time2aggregate_value.e average %d %d %d '%c' daily n %s\00"
@.str.4 = [127 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 |%s\09\09\09\09\09\09 |cat\09\09\09\09\09\09 \00"
@.str.5 = [35 x i8] c"measurement_date,measurement_value\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [6 x i8] c"chart\00"
@.str.8 = [9 x i8] c"transmit\00"
@.str.9 = [10 x i8] c"text_file\00"
@.str.10 = [12 x i8] c"spreadsheet\00"
@.str.11 = [6 x i8] c"table\00"
@.str.12 = [7 x i8] c"stdout\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [64 x i8]
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = alloca [32 x i8]
%11 = bitcast i8** %3 to i8*
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%19 = icmp eq i32 %0, 8
br i1 %19, label %25, label %20
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8*, i8** %1, i64 4
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8*, i8** %1, i64 5
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8*, i8** %1, i64 6
%37 = load i8*, i8** %36
%38 = tail call double @atof(i8* %37)
%39 = getelementptr inbounds i8*, i8** %1, i64 7
%40 = load i8*, i8** %39
%41 = call i64 @timlib_parse_database_string(i8** %3, i8* %27)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %25
%44 = load i8*, i8** %3
%45 = call i32 @environ_set_environment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %25
%47 = call i32 @appaserver_error_starting_argv_append_file(i32 8, i8** %1, i8* %27)
%48 = call i32 (...) @add_dot_to_path()
%49 = call i32 (...) @add_utility_to_path()
%50 = call i32 (...) @add_src_appaserver_to_path()
%51 = call i32 @add_relative_source_directory_to_path(i8* %27)
%52 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([113 x i8], [113 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %31, i8* %33, i8* %35)
%53 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i8* null, i32 -1, i32 1, i32 94, i8* %35)
%54 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([127 x i8], [127 x i8]* @.str.4, i64 0, i64 0), i8* %27, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %12, i8* %13)
%55 = call i32* @popen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8 0, i8* %17
%56 = call i64 @get_line(i8* %15, i32* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %92, label %58
58: ; preds = %46, %89
%59 = call i32 @piece(i8* %16, i8 signext 94, i8* %15, i32 0)
%60 = call i32 @piece(i8* %18, i8 signext 94, i8* %15, i32 1)
%61 = call double @atof(i8* %18)
%62 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %58
%65 = call i32 @output_chart_data(double %61, double %38, i8* %16)
br label %89
66: ; preds = %58
%67 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %81, label %69
69: ; preds = %66
%70 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%71 = icmp eq i64 %70, 0
br i1 %71, label %81, label %72
72: ; preds = %69
%73 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%74 = icmp eq i64 %73, 0
br i1 %74, label %81, label %75
75: ; preds = %72
%76 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %81, label %78
78: ; preds = %75
%79 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %89
81: ; preds = %78, %75, %72, %69, %66
%82 = load i8, i8* %17
%83 = icmp eq i8 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @strcpy(i8* %17, i8* %16)
br label %86
86: ; preds = %84, %81
%87 = call i32 @output_transmit_data(double %61, double %38, i8* %16, i8* %17, i32 0)
%88 = call i32 @strcpy(i8* %17, i8* %16)
br label %89
89: ; preds = %78, %86, %64
%90 = call i64 @get_line(i8* %15, i32* %55)
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %58
92: ; preds = %89, %46
%93 = phi double [ 0.000000e+00, %46 ], [ %61, %89 ]
%94 = call i32 @pclose(i32* %55)
%95 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%96 = icmp eq i64 %95, 0
br i1 %96, label %110, label %97
97: ; preds = %92
%98 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%99 = icmp eq i64 %98, 0
br i1 %99, label %110, label %100
100: ; preds = %97
%101 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%102 = icmp eq i64 %101, 0
br i1 %102, label %110, label %103
103: ; preds = %100
%104 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
br i1 %105, label %110, label %106
106: ; preds = %103
%107 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%108 = icmp ne i64 %107, 0
%109 = or i1 %57, %108
br i1 %109, label %113, label %111
110: ; preds = %103, %100, %97, %92
br i1 %57, label %113, label %111
111: ; preds = %106, %110
%112 = call i32 @output_transmit_data(double %93, double %38, i8* %16, i8* %17, i32 1)
br label %113
113: ; preds = %111, %110, %106
ret i32 0
}