#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__ fgets(char *, int, int /*<<< orphan*/ *);
int instr(char *, char *, int);
char *low_string(char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ search_replace(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void replace_asterisk_with_all_fields(char *sql_stmt, char *from_table,
                                      char *schema) {
  FILE *p;
  char buffer[128];
  char all_fields[1024];
  int first_time = 1;
  if (instr("(*)", sql_stmt, 1) >= 0)
    return;
  if (instr("( * )", sql_stmt, 1) >= 0)
    return;
  if (instr("(* )", sql_stmt, 1) >= 0)
    return;
  if (instr("(*)", sql_stmt, 1) >= 0)
    return;
  if (instr("*", sql_stmt, 1) == -1)
    return;
  sprintf(buffer, "column4table.sh %s %s | piece.e '|' 0", schema,
          low_string(from_table));
  p = popen(buffer, "r");
  while (fgets(buffer, 127, p)) {
    buffer[strlen(buffer) - 1] = '\0';
    if (first_time) {
      strcpy(all_fields, buffer);
      first_time = 0;
    } else {
      sprintf(all_fields + strlen(all_fields), "||'|'||%s", buffer);
    }
  }
  pclose(p);
  search_replace("*", all_fields, sql_stmt);
}


x86 assembly (clang, -O0):
<replace_asterisk_with_all_fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x4a4(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x1,%edx
call   1080 <instr@plt>
cmp    $0x0,%eax
jl     11d4 <replace_asterisk_with_all_fields+0x44>
jmp    137f <replace_asterisk_with_all_fields+0x1ef>
mov    -0x8(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x1,%edx
call   1080 <instr@plt>
cmp    $0x0,%eax
jl     11f7 <replace_asterisk_with_all_fields+0x67>
jmp    137f <replace_asterisk_with_all_fields+0x1ef>
mov    -0x8(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x1,%edx
call   1080 <instr@plt>
cmp    $0x0,%eax
jl     121a <replace_asterisk_with_all_fields+0x8a>
jmp    137f <replace_asterisk_with_all_fields+0x1ef>
mov    -0x8(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x1,%edx
call   1080 <instr@plt>
cmp    $0x0,%eax
jl     123d <replace_asterisk_with_all_fields+0xad>
jmp    137f <replace_asterisk_with_all_fields+0x1ef>
mov    -0x8(%rbp),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x1,%edx
call   1080 <instr@plt>
cmp    $0xffffffff,%eax
jne    1260 <replace_asterisk_with_all_fields+0xd0>
jmp    137f <replace_asterisk_with_all_fields+0x1ef>
lea    -0xa0(%rbp),%rax
mov    %rax,-0x4b8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x4b0(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <low_string@plt>
mov    -0x4b8(%rbp),%rdi
mov    -0x4b0(%rbp),%rdx
mov    %rax,%rcx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x20(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x7f,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     135f <replace_asterisk_with_all_fields+0x1cf>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0xa0(%rbp,%rax,1)
cmpl   $0x0,-0x4a4(%rbp)
je     131f <replace_asterisk_with_all_fields+0x18f>
lea    -0x4a0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4a4(%rbp)
jmp    135a <replace_asterisk_with_all_fields+0x1ca>
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x4c0(%rbp)
lea    -0x4a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c0(%rbp),%rdi
cltq
add    %rax,%rdi
lea    -0xa0(%rbp),%rdx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    12b8 <replace_asterisk_with_all_fields+0x128>
mov    -0x20(%rbp),%rdi
call   1060 <pclose@plt>
lea    -0x4a0(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xc95(%rip),%rdi
call   1050 <search_replace@plt>
add    $0x4c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_asterisk_with_all_fields>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x480,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <instr@plt>
test   %eax,%eax
jns    132d <replace_asterisk_with_all_fields+0x19d>
lea    0xe38(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <instr@plt>
test   %eax,%eax
jns    132d <replace_asterisk_with_all_fields+0x19d>
lea    0xe22(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <instr@plt>
test   %eax,%eax
jns    132d <replace_asterisk_with_all_fields+0x19d>
lea    0xdfc(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <instr@plt>
test   %eax,%eax
jns    132d <replace_asterisk_with_all_fields+0x19d>
lea    0xdef(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <instr@plt>
cmp    $0xffffffff,%eax
je     132d <replace_asterisk_with_all_fields+0x19d>
mov    %r14,%rdi
call   1070 <low_string@plt>
lea    0xdcc(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xdd8(%rip),%rsi
mov    %r14,%rdi
call   10a0 <popen@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x7f,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     130e <replace_asterisk_with_all_fields+0x17e>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0x80(%rsp),%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x7f,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     130e <replace_asterisk_with_all_fields+0x17e>
lea    0x80(%rsp),%r12
lea    0xd72(%rip),%r13
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x80,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %r14,%rdi
mov    $0x7f,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    12c7 <replace_asterisk_with_all_fields+0x137>
mov    %r15,%rdi
call   1060 <pclose@plt>
lea    0xcf2(%rip),%rdi
lea    0x80(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <search_replace@plt>
add    $0x480,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"(*)\00"
@.str.1 = [6 x i8] c"( * )\00"
@.str.2 = [5 x i8] c"(* )\00"
@.str.3 = [2 x i8] c"*\00"
@.str.4 = [38 x i8] c"column4table.sh %s %s | piece.e '|' 0\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [10 x i8] c"||'|'||%s\00"
define void @replace_asterisk_with_all_fields(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [128 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 1, i32* %10
%11 = load i8*, i8** %4
%12 = call i32 @instr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11, i32 1)
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
br label %75
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = call i32 @instr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 1)
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %75
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = call i32 @instr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 1)
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %75
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = call i32 @instr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26, i32 1)
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
br label %75
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = call i32 @instr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 1)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %35
34: ; preds = %30
br label %75
35: ; preds = %30
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%37 = load i8*, i8** %6
%38 = load i8*, i8** %5
%39 = call i8* @low_string(i8* %38)
%40 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %37, i8* %39)
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%42 = call i32* @popen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %42, i32** %7
br label %43
43: ; preds = %68, %35
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%45 = load i32*, i32** %7
%46 = call i64 @fgets(i8* %44, i32 127, i32* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %69
48: ; preds = %43
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %52
store i8 0, i8* %53
%54 = load i32, i32* %10
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %48
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%59 = call i32 @strcpy(i8* %57, i8* %58)
store i32 0, i32* %10
br label %68
60: ; preds = %48
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%67 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %65, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %60, %56
br label %43
69: ; preds = %43
%70 = load i32*, i32** %7
%71 = call i32 @pclose(i32* %70)
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%73 = load i8*, i8** %4
%74 = call i32 @search_replace(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %72, i8* %73)
br label %75
75: ; preds = %69, %34, %29, %24, %19, %14
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"(*)\00"
@.str.1 = [6 x i8] c"( * )\00"
@.str.2 = [5 x i8] c"(* )\00"
@.str.3 = [2 x i8] c"*\00"
@.str.4 = [38 x i8] c"column4table.sh %s %s | piece.e '|' 0\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [10 x i8] c"||'|'||%s\00"
define void @replace_asterisk_with_all_fields(i8* %0, i8* %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @instr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0, i32 1)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %50, label %10
10: ; preds = %3
%11 = tail call i32 @instr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 1)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %50, label %13
13: ; preds = %10
%14 = tail call i32 @instr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 1)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %50, label %16
16: ; preds = %13
%17 = tail call i32 @instr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0, i32 1)
%18 = icmp sgt i32 %17, -1
br i1 %18, label %50, label %19
19: ; preds = %16
%20 = tail call i32 @instr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 1)
%21 = icmp eq i32 %20, -1
br i1 %21, label %50, label %22
22: ; preds = %19
%23 = tail call i8* @low_string(i8* %1)
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %23)
%25 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = call i64 @fgets(i8* %6, i32 127, i32* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %47, label %28
28: ; preds = %22
%29 = call i32 @strlen(i8* %6)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i32 @strcpy(i8* %7, i8* %6)
%34 = call i64 @fgets(i8* %6, i32 127, i32* %25)
%35 = icmp eq i64 %34, 0
br i1 %35, label %47, label %36
36: ; preds = %28, %36
%37 = call i32 @strlen(i8* %6)
%38 = add nsw i32 %37, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 @strlen(i8* %7)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %42
%44 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %43, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%45 = call i64 @fgets(i8* %6, i32 127, i32* %25)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %36
47: ; preds = %36, %28, %22
%48 = call i32 @pclose(i32* %25)
%49 = call i32 @search_replace(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %0)
br label %50
50: ; preds = %19, %16, %13, %10, %3, %47
ret void
}