#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 character_count(char, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fix_any_quotes(char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ output_row(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *timlib_remove_character(char *, int);
void output_insert_statements(char *table_name, char *field_names,
                              char delimiter, char replace_yn) {
  char buffer[65535 + 1];
  int max_piece = 0;
  if (*field_names) {
    max_piece = character_count(',', field_names);
  }
  while (get_line(buffer, stdin)) {
    if (!*buffer)
      continue;
    fix_any_quotes(buffer);
    if (replace_yn == 'y') {
      printf("replace into %s", table_name);
    } else {
      printf("insert into %s", table_name);
    }
    if (*field_names) {
      printf(" (%s)", timlib_remove_character(field_names, 10));
    }
    printf(" values (");
    output_row(buffer, delimiter, max_piece);
    printf(");\n");
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<output_insert_statements>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
movl   $0x0,-0x10024(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b8 <output_insert_statements+0x48>
mov    -0x10(%rbp),%rsi
mov    $0x2c,%edi
call   1090 <character_count@plt>
mov    %eax,-0x10024(%rbp)
jmp    11bd <output_insert_statements+0x4d>
lea    -0x10020(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   1040 <get_line@plt>
cmp    $0x0,%rax
je     12a3 <output_insert_statements+0x133>
cmpb   $0x0,-0x10020(%rbp)
jne    11ee <output_insert_statements+0x7e>
jmp    11bd <output_insert_statements+0x4d>
lea    -0x10020(%rbp),%rdi
call   1060 <fix_any_quotes@plt>
movsbl -0x12(%rbp),%eax
cmp    $0x79,%eax
jne    121e <output_insert_statements+0xae>
mov    -0x8(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1230 <output_insert_statements+0xc0>
mov    -0x8(%rbp),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     125c <output_insert_statements+0xec>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1080 <timlib_remove_character@plt>
mov    %rax,%rsi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x10020(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x10024(%rbp),%edx
movsbl %al,%esi
call   1030 <output_row@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    11bd <output_insert_statements+0x4d>
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_insert_statements>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10008,%rsp
mov    %ecx,%ebp
mov    %edx,%r13d
mov    %rsi,%rbx
mov    %rdi,%r14
cmpb   $0x0,(%rsi)
je     11b3 <output_insert_statements+0x33>
mov    $0x2c,%edi
mov    %rbx,%rsi
call   10a0 <character_count@plt>
mov    %eax,%r15d
jmp    11b6 <output_insert_statements+0x36>
xor    %r15d,%r15d
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1050 <get_line@plt>
test   %rax,%rax
je     127f <output_insert_statements+0xff>
cmp    $0x79,%bpl
lea    0xe25(%rip),%rax
lea    0xe2e(%rip),%r12
cmove  %rax,%r12
mov    %rsp,%rbp
movsbl %r13b,%r13d
jmp    123c <output_insert_statements+0xbc>
nop
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r15d,%edx
call   1030 <output_row@plt>
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <get_line@plt>
test   %rax,%rax
je     127f <output_insert_statements+0xff>
cmpb   $0x0,(%rsp)
je     1226 <output_insert_statements+0xa6>
mov    %rbp,%rdi
call   1070 <fix_any_quotes@plt>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmpb   $0x0,(%rbx)
je     11f0 <output_insert_statements+0x70>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1090 <timlib_remove_character@plt>
lea    0xdaf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f0 <output_insert_statements+0x70>
add    $0x10008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [16 x i8] c"replace into %s\00"
@.str.1 = [15 x i8] c"insert into %s\00"
@.str.2 = [6 x i8] c" (%s)\00"
@.str.3 = [10 x i8] c" values (\00"
@.str.4 = [4 x i8] c");\0A\00"
@stdout = global i32 0
define void @output_insert_statements(i8* %0, i8* %1, i8 signext %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca [65536 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i8 %3, i8* %8
store i32 0, i32* %10
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = call i32 @character_count(i8 signext 44, i8* %15)
store i32 %16, i32* %10
br label %17
17: ; preds = %14, %4
br label %18
18: ; preds = %48, %27, %17
%19 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i64 @get_line(i8* %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %57
23: ; preds = %18
%24 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
br label %18
28: ; preds = %23
%29 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%30 = call i32 @fix_any_quotes(i8* %29)
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 121
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i8*, i8** %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %35)
br label %40
37: ; preds = %28
%38 = load i8*, i8** %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %34
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i8*, i8** %6
%46 = call i8* @timlib_remove_character(i8* %45, i32 10)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %44, %40
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%50 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%51 = load i8, i8* %7
%52 = load i32, i32* %10
%53 = call i32 @output_row(i8* %50, i8 signext %51, i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* @stdout
%56 = call i32 @fflush(i32 %55)
br label %18
57: ; preds = %18
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [16 x i8] c"replace into %s\00"
@.str.1 = [15 x i8] c"insert into %s\00"
@.str.2 = [6 x i8] c" (%s)\00"
@.str.3 = [10 x i8] c" values (\00"
@stdout = global i32 0
@str = [3 x i8] c");\00"
define void @output_insert_statements(i8* %0, i8* %1, i8 signext %2, i8 signext %3) {
%5 = alloca [65536 x i8]
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @character_count(i8 signext 44, i8* %1)
br label %11
11: ; preds = %9, %4
%12 = phi i32 [ %10, %9 ], [ 0, %4 ]
%13 = load i32, i32* @stdin
%14 = call i64 @get_line(i8* %6, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %40, label %16
16: ; preds = %11
%17 = icmp eq i8 %3, 121
%18 = select i1 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0)
br label %19
19: ; preds = %16, %36
%20 = load i8, i8* %6
%21 = icmp eq i8 %20, 0
br i1 %21, label %36, label %22
22: ; preds = %19
%23 = call i32 @fix_any_quotes(i8* %6)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %18, i8* %0)
%25 = load i8, i8* %1
%26 = icmp eq i8 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = call i8* @timlib_remove_character(i8* %1, i32 10)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %22
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @output_row(i8* %6, i8 signext %2, i32 %12)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* @stdout
%35 = call i32 @fflush(i32 %34)
br label %36
36: ; preds = %30, %19
%37 = load i32, i32* @stdin
%38 = call i64 @get_line(i8* %6, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %19
40: ; preds = %36, %11
ret void
}