#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*/ appaserver_output_error_message(char *, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
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 *, char *, char *);
int /*<<< orphan*/ stderr;
int insert_mysql(char *application_name, int rows_to_insert, char *folder_name,
                 char *attribute_comma_string,
                 char *carrot_delimited_row_filename) {
  FILE *p;
  char *table_name;
  char buffer[1024];
  table_name = get_table_name(application_name, folder_name);
  sprintf(buffer,
          "cat %s			|"
          "unescape_single_quotes.e	|"
          "insert_statement %s %s '^'	|"
          "sed 's/\\\\\\$/$/g'		|"
          "tee_appaserver_error.sh	|"
          "sql 2>&1			 ",
          carrot_delimited_row_filename, table_name, attribute_comma_string);
  p = popen(buffer, "r");
  while (get_line(buffer, p)) {
    appaserver_output_error_message(application_name, buffer, (char *)0);
    fprintf(stderr, "%s\n", buffer);
    rows_to_insert--;
  }
  pclose(p);
  return rows_to_insert;
}


x86 assembly (clang, -O0):
<insert_mysql>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <get_table_name@plt>
mov    %rax,-0x38(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe47(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x440(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     122d <insert_mysql+0xbd>
mov    -0x8(%rbp),%rdi
lea    -0x440(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <appaserver_output_error_message@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    -0x440(%rbp),%rdx
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11d5 <insert_mysql+0x65>
mov    -0x30(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0xc(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_mysql>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %r8,%r15
mov    %rcx,%r12
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rdx,%rsi
call   1070 <get_table_name@plt>
lea    0xe65(%rip),%rsi
mov    %rsp,%r13
mov    %r13,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
mov    %r12,%r8
call   1090 <sprintf@plt>
lea    0xec3(%rip),%rsi
mov    %r13,%rdi
call   1080 <popen@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %rax,%rsi
call   1030 <get_line@plt>
test   %rax,%rax
je     121e <insert_mysql+0xae>
mov    %rsp,%r12
mov    0x2e05(%rip),%rbp
lea    0xe99(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1060 <appaserver_output_error_message@plt>
mov    0x0(%rbp),%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
add    $0xffffffff,%ebx
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <get_line@plt>
test   %rax,%rax
jne    11f0 <insert_mysql+0x80>
mov    %r15,%rdi
call   1040 <pclose@plt>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [121 x i8] c"cat %s\09\09\09|unescape_single_quotes.e\09|insert_statement %s %s '^'\09|sed 's/\\\\\\$/$/g'\09\09|tee_appaserver_error.sh\09|sql 2>&1\09\09\09 \00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @insert_mysql(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca [1024 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%14 = load i8*, i8** %6
%15 = load i8*, i8** %8
%16 = call i8* @get_table_name(i8* %14, i8* %15)
store i8* %16, i8** %12
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%18 = load i8*, i8** %10
%19 = load i8*, i8** %12
%20 = load i8*, i8** %9
%21 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19, i8* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%23 = call i32* @popen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %11
br label %24
24: ; preds = %29, %5
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%26 = load i32*, i32** %11
%27 = call i64 @get_line(i8* %25, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%32 = call i32 @appaserver_output_error_message(i8* %30, i8* %31, i8* null)
%33 = load i32, i32* @stderr
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %7
%37 = add nsw i32 %36, -1
store i32 %37, i32* %7
br label %24
38: ; preds = %24
%39 = load i32*, i32** %11
%40 = call i32 @pclose(i32* %39)
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
@.str = [121 x i8] c"cat %s\09\09\09|unescape_single_quotes.e\09|insert_statement %s %s '^'\09|sed 's/\\\\\\$/$/g'\09\09|tee_appaserver_error.sh\09|sql 2>&1\09\09\09 \00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @insert_mysql(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = tail call i8* @get_table_name(i8* %0, i8* %2)
%9 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %8, i8* %3)
%10 = call i32* @popen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i64 @get_line(i8* %7, i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %5, %13
%14 = phi i32 [ %18, %13 ], [ %1, %5 ]
%15 = call i32 @appaserver_output_error_message(i8* %0, i8* %7, i8* null)
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%18 = add nsw i32 %14, -1
%19 = call i64 @get_line(i8* %7, i32* %10)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %13
21: ; preds = %13, %5
%22 = phi i32 [ %1, %5 ], [ %18, %13 ]
%23 = call i32 @pclose(i32* %10)
ret i32 %22
}