#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 */
int /*<<< orphan*/ appaserver_output_error_message(char *, char *, char *);
int atoi(int /*<<< orphan*/);
char *get_table_name(char *, char *);
int /*<<< orphan*/ pipe2string(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
int measurement_validation_update_measurement(char *application_name,
                                              char *login_name, char *station,
                                              char *datatype,
                                              char *validation_date,
                                              char *begin_measurement_date,
                                              char *end_measurement_date) {
  char where[4096];
  char sys_string[4096];
  char *table_name;
  char last_validation_date_set_string[128];
  char last_person_validating_set_string[128];
  char *validation_process;
  int return_count;
  table_name = get_table_name(application_name, "measurement");
  if (!validation_date || !*validation_date) {
    strcpy(last_validation_date_set_string, "= null");
    sprintf(last_person_validating_set_string, "= '%s'", login_name);
    validation_process = "unvalidated";
  } else {
    sprintf(last_validation_date_set_string, "= '%s'", validation_date);
    sprintf(last_person_validating_set_string, "= '%s'", login_name);
    validation_process = "visual_inspection";
  }
  sprintf(where,
          "station = '%s' and				"
          "datatype = '%s' and				"
          "measurement_date between '%s' and '%s'	",
          station, datatype, begin_measurement_date, end_measurement_date);
  sprintf(sys_string, "echo \"select count(*) from %s where %s;\" | sql.e",
          table_name, where);
  return_count = atoi(pipe2string(sys_string));
  sprintf(sys_string,
          "echo \"update %s set last_validation_date %s,		 "
          "		      last_person_validating %s,	 "
          "		      last_validation_process = '%s'	 "
          "	where %s;\"				 	|"
          "sql.e 2>&1						|"
          "html_paragraph_wrapper					 ",
          table_name, last_validation_date_set_string,
          last_person_validating_set_string, validation_process, where);
  appaserver_output_error_message(application_name, sys_string, login_name);
  system(sys_string);
  return return_count;
}


x86 assembly (clang, -O0):
<measurement_validation_update_measurement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2160,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <get_table_name@plt>
mov    %rax,-0x2038(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c6 <measurement_validation_update_measurement+0x56>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1205 <measurement_validation_update_measurement+0x95>
lea    -0x20c0(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x2140(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    0xe21(%rip),%rax
mov    %rax,-0x2148(%rbp)
jmp    1245 <measurement_validation_update_measurement+0xd5>
lea    -0x20c0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x2140(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    0xde8(%rip),%rax
mov    %rax,-0x2148(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r9
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x2030(%rbp),%rdi
mov    -0x2038(%rbp),%rdx
lea    -0x1030(%rbp),%rcx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x2030(%rbp),%rdi
call   1070 <pipe2string@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,-0x214c(%rbp)
lea    -0x2030(%rbp),%rdi
mov    -0x2038(%rbp),%rdx
lea    -0x20c0(%rbp),%rcx
lea    -0x2140(%rbp),%r8
mov    -0x2148(%rbp),%r9
lea    -0x1030(%rbp),%rax
lea    0xde7(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2030(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <appaserver_output_error_message@plt>
lea    -0x2030(%rbp),%rdi
call   1040 <system@plt>
mov    -0x214c(%rbp),%eax
add    $0x2160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measurement_validation_update_measurement>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2128,%rsp
mov    %r9,%r12
mov    %r8,%rbp
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe62(%rip),%rsi
call   1060 <get_table_name@plt>
mov    %rax,%rbx
test   %rbp,%rbp
je     11d0 <measurement_validation_update_measurement+0x60>
cmpb   $0x0,0x0(%rbp)
je     11d0 <measurement_validation_update_measurement+0x60>
lea    0xe5b(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe58(%rip),%rax
jmp    11e8 <measurement_validation_update_measurement+0x78>
lea    0xe35(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xe32(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe1f(%rip),%rsi
lea    0xa0(%rsp),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe2b(%rip),%rsi
lea    0x1120(%rsp),%r13
mov    %r13,%rdi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    %r12,%r8
mov    0x2160(%rsp),%r9
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe52(%rip),%rsi
lea    0x120(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1070 <pipe2string@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    %r13,(%rsp)
lea    0xe4e(%rip),%rsi
lea    0x20(%rsp),%rcx
mov    %rbp,%rdi
mov    %rbx,%rdx
lea    0xa0(%rsp),%r8
mov    0x8(%rsp),%r9
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <appaserver_output_error_message@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
mov    %r12d,%eax
add    $0x2128,%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 = [7 x i8] c"= null\00"
@.str.2 = [7 x i8] c"= '%s'\00"
@.str.3 = [12 x i8] c"unvalidated\00"
@.str.4 = [18 x i8] c"visual_inspection\00"
@.str.5 = [85 x i8] c"station = '%s' and\09\09\09\09datatype = '%s' and\09\09\09\09measurement_date between '%s' and '%s'\09\00"
@.str.6 = [49 x i8] c"echo \22select count(*) from %s where %s;\22 | sql.e\00"
@.str.7 = [187 x i8] c"echo \22update %s set last_validation_date %s,\09\09 \09\09 last_person_validating %s,\09 \09\09 last_validation_process = '%s'\09 \09where %s;\22\09\09\09\09 \09|sql.e 2>&1\09\09\09\09\09\09|html_paragraph_wrapper\09\09\09\09\09 \00"
define i32 @measurement_validation_update_measurement(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca [4096 x i8]
%16 = alloca [4096 x i8]
%17 = alloca i8*
%18 = alloca [128 x i8]
%19 = alloca [128 x i8]
%20 = alloca i8*
%21 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%22 = load i8*, i8** %8
%23 = call i8* @get_table_name(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %23, i8** %17
%24 = load i8*, i8** %12
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %7
%27 = load i8*, i8** %12
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %26, %7
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %19, i64 0, i64 0
%34 = load i8*, i8** %9
%35 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %20
br label %43
36: ; preds = %26
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%38 = load i8*, i8** %12
%39 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %19, i64 0, i64 0
%41 = load i8*, i8** %9
%42 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %41)
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8** %20
br label %43
43: ; preds = %36, %30
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%45 = load i8*, i8** %10
%46 = load i8*, i8** %11
%47 = load i8*, i8** %13
%48 = load i8*, i8** %14
%49 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.5, i64 0, i64 0), i8* %45, i8* %46, i8* %47, i8* %48)
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%51 = load i8*, i8** %17
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%53 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %51, i8* %52)
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%55 = call i32 @pipe2string(i8* %54)
%56 = call i32 @atoi(i32 %55)
store i32 %56, i32* %21
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%58 = load i8*, i8** %17
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %19, i64 0, i64 0
%61 = load i8*, i8** %20
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%63 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([187 x i8], [187 x i8]* @.str.7, i64 0, i64 0), i8* %58, i8* %59, i8* %60, i8* %61, i8* %62)
%64 = load i8*, i8** %8
%65 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%66 = load i8*, i8** %9
%67 = call i32 @appaserver_output_error_message(i8* %64, i8* %65, i8* %66)
%68 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%69 = call i32 @system(i8* %68)
%70 = load i32, i32* %21
ret i32 %70
}

LLVM IR (-O2):
@.str = [12 x i8] c"measurement\00"
@.str.1 = [7 x i8] c"= null\00"
@.str.2 = [7 x i8] c"= '%s'\00"
@.str.3 = [12 x i8] c"unvalidated\00"
@.str.4 = [18 x i8] c"visual_inspection\00"
@.str.5 = [85 x i8] c"station = '%s' and\09\09\09\09datatype = '%s' and\09\09\09\09measurement_date between '%s' and '%s'\09\00"
@.str.6 = [49 x i8] c"echo \22select count(*) from %s where %s;\22 | sql.e\00"
@.str.7 = [187 x i8] c"echo \22update %s set last_validation_date %s,\09\09 \09\09 last_person_validating %s,\09 \09\09 last_validation_process = '%s'\09 \09where %s;\22\09\09\09\09 \09|sql.e 2>&1\09\09\09\09\09\09|html_paragraph_wrapper\09\09\09\09\09 \00"
define i32 @measurement_validation_update_measurement(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca [4096 x i8]
%9 = alloca [4096 x i8]
%10 = alloca [128 x i8]
%11 = alloca [128 x i8]
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%16 = tail call i8* @get_table_name(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %4, null
br i1 %17, label %21, label %18
18: ; preds = %7
%19 = load i8, i8* %4
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18, %7
%22 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %25
23: ; preds = %18
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %25
25: ; preds = %23, %21
%26 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), %23 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %21 ]
%27 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %3, i8* %5, i8* %6)
%29 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %16, i8* %12)
%30 = call i32 @pipe2string(i8* %13)
%31 = call i32 @atoi(i32 %30)
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([187 x i8], [187 x i8]* @.str.7, i64 0, i64 0), i8* %16, i8* %14, i8* %15, i8* %26, i8* %12)
%33 = call i32 @appaserver_output_error_message(i8* %0, i8* %13, i8* %1)
%34 = call i32 @system(i8* %13)
ret i32 %31
}