#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 */
scalar_t__ get_line(char *, int /*<<< orphan*/ *);
char *get_table_name(char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *strdup(char *);
char *hydrology_library_get_expected_count_list_string(char *application,
                                                       char *station,
                                                       char *datatype,
                                                       char delimiter) {
  char sys_string[1024];
  char *table_name;
  char input_buffer[1024];
  FILE *input_pipe;
  char list_string[2048];
  char *ptr = list_string;
  char *select = "begin_measurement_date,begin_measurement_time,expected_count";
  table_name = get_table_name(application, "data_collection_frequency");
  sprintf(sys_string,
          "echo \"select %s					 "
          "       from %s					 "
          "	 where station = '%s'				 "
          "	   and datatype = '%s'				 "
          "	 order by %s;\"					|"
          "sql.e '%c'						 ",
          select, table_name, station, datatype, select, '^');
  input_pipe = popen(sys_string, "r");
  while (get_line(input_buffer, input_pipe)) {
    if (ptr == list_string)
      ptr += sprintf(ptr, "%s", input_buffer);
    else
      ptr += sprintf(ptr, "%c%s", delimiter, input_buffer);
  }
  *ptr = '\0';
  pclose(input_pipe);
  return strdup(list_string);
}


x86 assembly (clang, -O0):
<hydrology_library_get_expected_count_list_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
lea    -0x1040(%rbp),%rax
mov    %rax,-0x1048(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x1050(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <get_table_name@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x1050(%rbp),%rdx
mov    -0x428(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x1050(%rbp),%rax
lea    0xe7d(%rip),%rsi
mov    %rax,(%rsp)
movl   $0x5e,0x8(%rsp)
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xee3(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x838(%rbp)
lea    -0x830(%rbp),%rdi
mov    -0x838(%rbp),%rsi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     12ad <hydrology_library_get_expected_count_list_string+0x14d>
mov    -0x1048(%rbp),%rax
lea    -0x1040(%rbp),%rcx
cmp    %rcx,%rax
jne    1272 <hydrology_library_get_expected_count_list_string+0x112>
mov    -0x1048(%rbp),%rdi
lea    -0x830(%rbp),%rdx
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,%ecx
mov    -0x1048(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1048(%rbp)
jmp    12a8 <hydrology_library_get_expected_count_list_string+0x148>
mov    -0x1048(%rbp),%rdi
movsbl -0x19(%rbp),%edx
lea    -0x830(%rbp),%rcx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,%ecx
mov    -0x1048(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1048(%rbp)
jmp    1207 <hydrology_library_get_expected_count_list_string+0xa7>
mov    -0x1048(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x838(%rbp),%rdi
call   1040 <pclose@plt>
lea    -0x1040(%rbp),%rdi
call   1080 <strdup@plt>
add    $0x1060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hydrology_library_get_expected_count_list_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbp
mov    %rsi,%rbx
lea    0xeac(%rip),%rsi
call   1060 <get_table_name@plt>
lea    0xe63(%rip),%rdx
lea    0xeb3(%rip),%rsi
lea    0xc00(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rcx
mov    %rbx,%r8
mov    %rbp,%r9
xor    %eax,%eax
push   $0x5e
push   %rdx
call   1080 <sprintf@plt>
add    $0x10,%rsp
lea    0xf11(%rip),%rsi
mov    %r14,%rdi
call   1070 <popen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    %rax,%rsi
call   1030 <get_line@plt>
test   %rax,%rax
je     124d <hydrology_library_get_expected_count_list_string+0xdd>
lea    0x400(%rsp),%r15
movsbl %r12b,%r12d
mov    %rsp,%rbp
lea    0xee2(%rip),%r13
mov    %r15,%rbx
jmp    1238 <hydrology_library_get_expected_count_list_string+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
cltq
add    %rax,%rbx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <get_line@plt>
test   %rax,%rax
je     1255 <hydrology_library_get_expected_count_list_string+0xe5>
cmp    %r15,%rbx
jne    1210 <hydrology_library_get_expected_count_list_string+0xa0>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <stpcpy@plt>
sub    %r15d,%eax
jmp    1223 <hydrology_library_get_expected_count_list_string+0xb3>
lea    0x400(%rsp),%rbx
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1050 <pclose@plt>
lea    0x400(%rsp),%rdi
call   1090 <strdup@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"begin_measurement_date,begin_measurement_time,expected_count\00"
@.str.1 = [26 x i8] c"data_collection_frequency\00"
@.str.2 = [135 x i8] c"echo \22select %s\09\09\09\09\09 from %s\09\09\09\09\09 \09 where station = '%s'\09\09\09\09 \09 and datatype = '%s'\09\09\09\09 \09 order by %s;\22\09\09\09\09\09|sql.e '%c'\09\09\09\09\09\09 \00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"%c%s\00"
define i8* @hydrology_library_get_expected_count_list_string(i8* %0, i8* %1, i8* %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca [1024 x i8]
%10 = alloca i8*
%11 = alloca [1024 x i8]
%12 = alloca i32*
%13 = alloca [2048 x i8]
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8 %3, i8* %8
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
store i8* %16, i8** %14
store i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8** %15
%17 = load i8*, i8** %5
%18 = call i8* @get_table_name(i8* %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %10
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %15
%21 = load i8*, i8** %10
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = load i8*, i8** %15
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i8* %20, i8* %21, i8* %22, i8* %23, i8* %24, i32 94)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%27 = call i32* @popen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %12
br label %28
28: ; preds = %53, %4
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%30 = load i32*, i32** %12
%31 = call i64 @get_line(i8* %29, i32* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %54
33: ; preds = %28
%34 = load i8*, i8** %14
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%36 = icmp eq i8* %34, %35
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i8*, i8** %14
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %14
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %14
br label %53
44: ; preds = %33
%45 = load i8*, i8** %14
%46 = load i8, i8* %8
%47 = sext i8 %46 to i32
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %47, i8* %48)
%50 = load i8*, i8** %14
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8* %52, i8** %14
br label %53
53: ; preds = %44, %37
br label %28
54: ; preds = %28
%55 = load i8*, i8** %14
store i8 0, i8* %55
%56 = load i32*, i32** %12
%57 = call i32 @pclose(i32* %56)
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%59 = call i8* @strdup(i8* %58)
ret i8* %59
}

LLVM IR (-O2):
@.str = [61 x i8] c"begin_measurement_date,begin_measurement_time,expected_count\00"
@.str.1 = [26 x i8] c"data_collection_frequency\00"
@.str.2 = [135 x i8] c"echo \22select %s\09\09\09\09\09 from %s\09\09\09\09\09 \09 where station = '%s'\09\09\09\09 \09 and datatype = '%s'\09\09\09\09 \09 order by %s;\22\09\09\09\09\09|sql.e '%c'\09\09\09\09\09\09 \00"
@.str.3 = [2 x i8] c"r\00"
@.str.5 = [5 x i8] c"%c%s\00"
define noalias i8* @hydrology_library_get_expected_count_list_string(i8* %0, i8* %1, i8* %2, i8 signext %3) {
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [2048 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%11 = tail call i8* @get_table_name(i8* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %1, i8* %2, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 94)
%13 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = call i64 @get_line(i8* %9, i32* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %35, label %16
16: ; preds = %4
%17 = sext i8 %3 to i32
%18 = ptrtoint [2048 x i8]* %7 to i64
br label %19
19: ; preds = %16, %29
%20 = phi i8* [ %10, %16 ], [ %32, %29 ]
%21 = icmp eq i8* %20, %10
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = call i8* @stpcpy(i8* %10, i8* %9)
%24 = ptrtoint i8* %23 to i64
%25 = sub i64 %24, %18
%26 = trunc i64 %25 to i32
br label %29
27: ; preds = %19
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %17, i8* %9)
br label %29
29: ; preds = %27, %22
%30 = phi i32 [ %26, %22 ], [ %28, %27 ]
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %20, i64 %31
%33 = call i64 @get_line(i8* %9, i32* %13)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %19
35: ; preds = %29, %4
%36 = phi i8* [ %10, %4 ], [ %32, %29 ]
store i8 0, i8* %36
%37 = call i32 @pclose(i32* %13)
%38 = call i8* @strdup(i8* %10)
ret i8* %38
}